using System.Threading; using System; using System.ComponentModel.Design; #if NET5_0_OR_GREATER using Microsoft.Extensions.DependencyInjection; #endif namespace BITKit.Entities { /// /// 基本实体 /// public interface IEntity { ulong Id { get; } CancellationToken CancellationToken { get; } bool TryGetComponent(out T component); IEntityComponent[] Components { get; } bool RegisterComponent(T component); IServiceProvider ServiceProvider { get; } #if NET5_0_OR_GREATER IServiceCollection ServiceCollection { get; } #endif void Inject(object obj); } /// /// 基本实体组件 /// public interface IEntityComponent { IEntity Entity { get; set; } #if NET5_0_OR_GREATER void BuildService(IServiceCollection serviceCollection); #endif } public interface IEntityBehavior:IEntityComponent { void Initialize(IEntity _entity); void OnAwake(); void OnStart(); void OnUpdate(float deltaTime); void OnFixedUpdate(float deltaTime); void OnLateUpdate(float deltaTime); void OnDestroyComponent(); } /// /// 基本实体服务 /// public interface IEntitiesService { /// /// 当添加Entity时 /// public event Action OnAdd; /// /// 当移除Entity时 /// public event Action OnRemove; /// /// 所有Entity /// IEntity[] Entities { get; } /// /// 注册Entity /// /// /// bool Register(IEntity entity); /// /// 注销Entity /// /// /// bool UnRegister(IEntity entity); CancellationToken CancellationToken { get; } /// /// 通过Id获取Entity /// /// /// IEntity Get(ulong id); /// /// 查询Entity,例如 /// /// var rotationEntities=EntitiesService.Query<RotationComponent> IEntity[] Query(); /// /// 查询1个组件 /// /// /// T[] QueryComponents(); /// /// 查询2个组件 /// /// /// /// ValueTuple[] QueryComponents(); /// /// 查询3个组件 /// /// /// /// /// ValueTuple[] QueryComponents(); } }