using System.Collections.Generic; using DragonLi.Core; using Mirror; 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"; } /// /// Data of this Rain entity /// [SerializeField] [HideInInspector] public DataContainer Data; private Animator animatorComponent; /// /// Animator of this entity /// public Animator AnimatorComponent { get { if (animatorComponent == null) { animatorComponent = GetComponentInChildren(); } return animatorComponent; } } private Collider colliderComponent; /// /// Collider of this component /// public Collider ColliderComponent { get { if (colliderComponent == null) { colliderComponent = GetComponentInChildren(); } return colliderComponent; } } private Rigidbody rigidbodyComponent; /// /// Rigidbody of this entity /// public Rigidbody RigidbodyComponent { get { if (rigidbodyComponent == null) { rigidbodyComponent = GetComponentInChildren(); } return rigidbodyComponent; } } public virtual void Awake() { InitData(); OnAwake(); } public virtual void Update() { OnUpdate(); } public virtual void OnEnable() { OnEntityEnable(); } /// /// This will be called when Awake() was called. /// public virtual void OnAwake() { } /// /// This will be called when entity is Enable /// public virtual void OnEntityEnable() { } /// /// This will be called every frame /// public virtual void OnUpdate() { } /// /// This will be called when DeliverMessage has been called by others /// public 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); } }