SRMonoBehaviour.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Diagnostics;
  3. using UnityEngine;
  4. namespace SRF
  5. {
  6. public abstract class SRMonoBehaviour : MonoBehaviour
  7. {
  8. public Transform CachedTransform
  9. {
  10. [DebuggerNonUserCode]
  11. [DebuggerStepThrough]
  12. get
  13. {
  14. if (this._transform == null)
  15. {
  16. this._transform = base.transform;
  17. }
  18. return this._transform;
  19. }
  20. }
  21. public Collider CachedCollider
  22. {
  23. [DebuggerStepThrough]
  24. [DebuggerNonUserCode]
  25. get
  26. {
  27. if (this._collider == null)
  28. {
  29. this._collider = base.GetComponent<Collider>();
  30. }
  31. return this._collider;
  32. }
  33. }
  34. public Collider2D CachedCollider2D
  35. {
  36. [DebuggerStepThrough]
  37. [DebuggerNonUserCode]
  38. get
  39. {
  40. if (this._collider2D == null)
  41. {
  42. this._collider2D = base.GetComponent<Collider2D>();
  43. }
  44. return this._collider2D;
  45. }
  46. }
  47. public Rigidbody CachedRigidBody
  48. {
  49. [DebuggerStepThrough]
  50. [DebuggerNonUserCode]
  51. get
  52. {
  53. if (this._rigidBody == null)
  54. {
  55. this._rigidBody = base.GetComponent<Rigidbody>();
  56. }
  57. return this._rigidBody;
  58. }
  59. }
  60. public Rigidbody2D CachedRigidBody2D
  61. {
  62. [DebuggerStepThrough]
  63. [DebuggerNonUserCode]
  64. get
  65. {
  66. if (this._rigidbody2D == null)
  67. {
  68. this._rigidbody2D = base.GetComponent<Rigidbody2D>();
  69. }
  70. return this._rigidbody2D;
  71. }
  72. }
  73. public GameObject CachedGameObject
  74. {
  75. [DebuggerStepThrough]
  76. [DebuggerNonUserCode]
  77. get
  78. {
  79. if (this._gameObject == null)
  80. {
  81. this._gameObject = base.gameObject;
  82. }
  83. return this._gameObject;
  84. }
  85. }
  86. public new Transform transform
  87. {
  88. get
  89. {
  90. return this.CachedTransform;
  91. }
  92. }
  93. [DebuggerNonUserCode]
  94. [DebuggerStepThrough]
  95. protected void AssertNotNull(object value, string fieldName = null)
  96. {
  97. SRDebugUtil.AssertNotNull(value, fieldName, this);
  98. }
  99. [DebuggerNonUserCode]
  100. [DebuggerStepThrough]
  101. protected void Assert(bool condition, string message = null)
  102. {
  103. SRDebugUtil.Assert(condition, message, this);
  104. }
  105. [Conditional("UNITY_EDITOR")]
  106. [DebuggerNonUserCode]
  107. [DebuggerStepThrough]
  108. protected void EditorAssertNotNull(object value, string fieldName = null)
  109. {
  110. this.AssertNotNull(value, fieldName);
  111. }
  112. [Conditional("UNITY_EDITOR")]
  113. [DebuggerNonUserCode]
  114. [DebuggerStepThrough]
  115. protected void EditorAssert(bool condition, string message = null)
  116. {
  117. this.Assert(condition, message);
  118. }
  119. private Collider _collider;
  120. private Transform _transform;
  121. private Rigidbody _rigidBody;
  122. private GameObject _gameObject;
  123. private Rigidbody2D _rigidbody2D;
  124. private Collider2D _collider2D;
  125. }
  126. }