using System.Threading; using System; using System.ComponentModel.Design; using Microsoft.Extensions.DependencyInjection; #if NET5_0_OR_GREATER using Microsoft.Extensions.DependencyInjection; #endif namespace BITKit.Entities { /// /// 基本实体 /// public interface IEntity { int Id { get; } CancellationToken CancellationToken { get; } IServiceProvider ServiceProvider { get; } IServiceCollection ServiceCollection { get; } object[] GetServices(); void Inject(object obj); } /// /// 基本实体服务 /// 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(int id); /// /// 尝试通过Id获取Entity /// /// /// /// bool TryGetEntity(int id, out IEntity entity); /// /// 通过Id获取或添加Entity /// IEntity GetOrAdd(int id,Func factory); /// /// 查询Entity,例如 /// /// var rotationEntities=EntitiesService.Query<RotationComponent> IEntity[] Query(); /// /// 查询1个组件 /// /// /// T[] QueryComponents(); /// /// 查询2个组件 /// /// /// /// ValueTuple[] QueryComponents(); /// /// 查询3个组件 /// /// /// /// /// ValueTuple[] QueryComponents(); /// /// 查询4个组件 /// /// /// /// /// /// ValueTuple[] QueryComponents(); /// /// 查询5个组件 /// /// /// /// /// /// /// ValueTuple[] QueryComponents(); /// /// 查询6个组件 /// /// /// /// /// /// /// /// ValueTuple[] QueryComponents(); /// /// 查询7个组件 /// /// /// /// /// /// /// /// /// ValueTuple[] QueryComponents(); /// /// 查询8个组件 /// /// /// /// /// /// /// /// /// 剩余实例 /// ValueTuple[] QueryComponents() where TRest : struct; } }