using DragonLi.Core; using Mirror; using System.Collections; using System.Collections.Generic; using UnityEngine; /// /// Base class of all Objects /// public abstract class Entity : NetworkBehaviour { /// /// Some default value of rain entity /// public class Default { /// /// Transform of this entity /// public const string kControllerKey = "controller"; } /// /// Should all entity update? /// public static bool ShouldUpdate = true; /// /// Data of this Rain entity /// [SerializeField] [HideInInspector] public DataContainer Data; /// /// Will this entity update self? /// [SerializeField] [HideInInspector] protected bool updateSelf = true; private Animator animator; private Collider colliderComponent; private Rigidbody rigidbodyComponent; /// /// Animator of this entity /// public Animator AnimatorComponent { get { if (animator == null) { animator = GetComponentInChildren(); } return animator; } } /// /// Collider of this component /// public Collider ColliderComponent { get { if (colliderComponent == null) { colliderComponent = GetComponentInChildren(); } return colliderComponent; } } /// /// Rigidbody of this entity /// public Rigidbody RigidbodyComponent { get { if (rigidbodyComponent == null) { rigidbodyComponent = GetComponentInChildren(); } return rigidbodyComponent; } } public virtual void Awake() { InitData(); OnAwake(); } internal virtual void Update() { if (ShouldUpdate && updateSelf) { OnUpdate(); } } public virtual void OnEnable() { OnEntityEnable(); } /// /// This will be called when Awake() was called. /// protected virtual void OnAwake() { } /// /// This will be called when entity is Enable /// protected virtual void OnEntityEnable() { } /// /// This will be called every frame /// protected virtual void OnUpdate() { } /// /// This will be called when DeliverMessage has been called by others /// protected virtual void OnReceiveMessage(string msg, object info) { } public virtual void InitData() { } /// /// Convert this to target type /// /// target type /// public T As() where T : Entity { return this as T; } /// /// Deliver message into this entity. /// /// public void DeliverMessage(string msg, object info) { OnReceiveMessage(msg, info); } }