IGetComponentSystem.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. namespace ET
  3. {
  4. // GetComponentSystem有巨大作用,比如每次保存Unit的数据不需要所有组件都保存,只需要保存Unit变化过的组件
  5. // 是否变化可以通过判断该组件是否GetComponent,Get了就记录该组件
  6. // 这样可以只保存Unit变化过的组件
  7. // 再比如传送也可以做此类优化
  8. public interface IGetComponent
  9. {
  10. }
  11. public interface IGetComponentSystem: ISystemType
  12. {
  13. void Run(Entity o, Entity component);
  14. }
  15. [ObjectSystem]
  16. public abstract class GetComponentSystem<T> : IGetComponentSystem where T: Entity, IGetComponent
  17. {
  18. void IGetComponentSystem.Run(Entity o, Entity component)
  19. {
  20. this.GetComponent((T)o, component);
  21. }
  22. Type ISystemType.SystemType()
  23. {
  24. return typeof(IGetComponentSystem);
  25. }
  26. InstanceQueueIndex ISystemType.GetInstanceQueueIndex()
  27. {
  28. return InstanceQueueIndex.None;
  29. }
  30. Type ISystemType.Type()
  31. {
  32. return typeof(T);
  33. }
  34. protected abstract void GetComponent(T self, Entity component);
  35. }
  36. }