BITKit/Src/Unity/Scripts/Entity/Core/EntityComponent.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2023-08-11 23:57:37 +08:00
using System;
2023-06-29 14:57:11 +08:00
#if UNITY_EDITOR
using UnityEditor;
#endif
2023-06-05 19:57:17 +08:00
using UnityEngine;
2023-06-29 14:57:11 +08:00
2023-06-05 19:57:17 +08:00
namespace BITKit.Entities
{
2023-08-11 23:57:37 +08:00
public interface IEntityComponent:BITKit.Core.Entites.IEntityComponent
2023-06-05 19:57:17 +08:00
{
IEntity entity { get; }
2023-08-11 23:57:37 +08:00
void Initialize(IEntity _entity);
2023-06-05 19:57:17 +08:00
void OnUpdate(float deltaTime);
void OnFixedUpdate(float deltaTime);
void OnLateUpdate(float deltaTime);
void OnDestroyComponent();
}
2023-08-23 01:59:26 +08:00
public abstract class EntityComponent : MonoBehaviour, IEntityComponent
2023-06-05 19:57:17 +08:00
{
2023-08-23 01:59:26 +08:00
public IEntity entity { get; private set; }
2023-06-05 19:57:17 +08:00
private IEntity mEntity;
2023-08-23 01:59:26 +08:00
public virtual void Initialize(IEntity _entity) { entity = _entity; }
2023-06-05 19:57:17 +08:00
public virtual void OnAwake() { }
public virtual void OnStart() { }
public virtual void OnUpdate(float deltaTime) { }
public virtual void OnFixedUpdate(float deltaTime) { }
public virtual void OnLateUpdate(float deltaTime) { }
public virtual void OnDestroyComponent() { }
2023-08-11 23:57:37 +08:00
public virtual Type BaseType => GetType();
public Core.Entites.IEntity Entity { get; set; }
2023-06-05 19:57:17 +08:00
}
#if UNITY_EDITOR
2023-06-29 14:57:11 +08:00
[CanEditMultipleObjects]
[CustomEditor(typeof(EntityComponent), true)]
2023-06-05 19:57:17 +08:00
public class EntityComponentInspector : BITInspector<EntityComponent>
{
}
#endif
}