Entity.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //------------------------------------------------------------
  2. // Game Framework
  3. // Copyright © 2013-2021 Jiang Yin. All rights reserved.
  4. // Homepage: https://gameframework.cn/
  5. // Feedback: mailto:ellan@gameframework.cn
  6. //------------------------------------------------------------
  7. using GameFramework;
  8. using UnityEngine;
  9. using UnityGameFramework.Runtime;
  10. namespace MetaClient
  11. {
  12. public abstract class Entity : EntityLogic
  13. {
  14. [SerializeField]
  15. private EntityData m_EntityData = null;
  16. public int Id
  17. {
  18. get
  19. {
  20. return Entity.Id;
  21. }
  22. }
  23. public Animation CachedAnimation
  24. {
  25. get;
  26. private set;
  27. }
  28. #if UNITY_2017_3_OR_NEWER
  29. protected override void OnInit(object userData)
  30. #else
  31. protected internal override void OnInit(object userData)
  32. #endif
  33. {
  34. base.OnInit(userData);
  35. CachedAnimation = GetComponent<Animation>();
  36. }
  37. #if UNITY_2017_3_OR_NEWER
  38. protected override void OnRecycle()
  39. #else
  40. protected internal override void OnRecycle()
  41. #endif
  42. {
  43. base.OnRecycle();
  44. }
  45. #if UNITY_2017_3_OR_NEWER
  46. protected override void OnShow(object userData)
  47. #else
  48. protected internal override void OnShow(object userData)
  49. #endif
  50. {
  51. base.OnShow(userData);
  52. m_EntityData = userData as EntityData;
  53. if (m_EntityData == null)
  54. {
  55. Log.Error("Entity data is invalid.");
  56. return;
  57. }
  58. Name = Utility.Text.Format("[Entity {0}]", Id);
  59. CachedTransform.localPosition = m_EntityData.Position;
  60. CachedTransform.localRotation = m_EntityData.Rotation;
  61. CachedTransform.localScale = Vector3.one;
  62. }
  63. #if UNITY_2017_3_OR_NEWER
  64. protected override void OnHide(bool isShutdown, object userData)
  65. #else
  66. protected internal override void OnHide(bool isShutdown, object userData)
  67. #endif
  68. {
  69. base.OnHide(isShutdown, userData);
  70. }
  71. #if UNITY_2017_3_OR_NEWER
  72. protected override void OnAttached(EntityLogic childEntity, Transform parentTransform, object userData)
  73. #else
  74. protected internal override void OnAttached(EntityLogic childEntity, Transform parentTransform, object userData)
  75. #endif
  76. {
  77. base.OnAttached(childEntity, parentTransform, userData);
  78. }
  79. #if UNITY_2017_3_OR_NEWER
  80. protected override void OnDetached(EntityLogic childEntity, object userData)
  81. #else
  82. protected internal override void OnDetached(EntityLogic childEntity, object userData)
  83. #endif
  84. {
  85. base.OnDetached(childEntity, userData);
  86. }
  87. #if UNITY_2017_3_OR_NEWER
  88. protected override void OnAttachTo(EntityLogic parentEntity, Transform parentTransform, object userData)
  89. #else
  90. protected internal override void OnAttachTo(EntityLogic parentEntity, Transform parentTransform, object userData)
  91. #endif
  92. {
  93. base.OnAttachTo(parentEntity, parentTransform, userData);
  94. }
  95. #if UNITY_2017_3_OR_NEWER
  96. protected override void OnDetachFrom(EntityLogic parentEntity, object userData)
  97. #else
  98. protected internal override void OnDetachFrom(EntityLogic parentEntity, object userData)
  99. #endif
  100. {
  101. base.OnDetachFrom(parentEntity, userData);
  102. }
  103. #if UNITY_2017_3_OR_NEWER
  104. protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  105. #else
  106. protected internal override void OnUpdate(float elapseSeconds, float realElapseSeconds)
  107. #endif
  108. {
  109. base.OnUpdate(elapseSeconds, realElapseSeconds);
  110. }
  111. }
  112. }