using System.Threading; using System; namespace BITKit.Core.Entites { /// /// 基本实体 /// public interface IEntity { ulong Id { get; } #if NET5_0_OR_GREATER bool TryGetComponent(out T component) where T : IEntityComponent; IEntityComponent[] Components { get; } bool RegisterComponent(T component) where T : IEntityComponent; #else #endif } /// /// 基本实体组件 /// public interface IEntityComponent:IAwake,IStart { Type BaseType { get; } IEntity Entity { get; set; } } /// /// 基本实体服务 /// 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() where T : IEntityComponent; /// /// 查询1个组件 /// /// /// T[] QueryComponents() where T : IEntityComponent; /// /// 查询2个组件 /// /// /// /// ValueTuple[] QueryComponents()where T : IEntityComponent where T1 : IEntityComponent; /// /// 查询3个组件 /// /// /// /// /// ValueTuple[] QueryComponents() where T : IEntityComponent where T1 : IEntityComponent where T2 : IEntityComponent; } }