LSEntitySystemSington.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. namespace ET
  4. {
  5. [UniqueId(-1, 1)]
  6. public static class LSQueneUpdateIndex
  7. {
  8. public const int None = -1;
  9. public const int LSUpdate = 0;
  10. public const int Max = 1;
  11. }
  12. public class LSEntitySystemSington: Singleton<LSEntitySystemSington>, ISingletonAwake, ISingletonLoad
  13. {
  14. private TypeSystems typeSystems;
  15. public void Awake()
  16. {
  17. this.Load();
  18. }
  19. public void Load()
  20. {
  21. this.typeSystems = new(LSQueneUpdateIndex.Max);
  22. foreach (Type type in EventSystem.Instance.GetTypes(typeof (LSEntitySystemAttribute)))
  23. {
  24. object obj = Activator.CreateInstance(type);
  25. if (obj is not ISystemType iSystemType)
  26. {
  27. continue;
  28. }
  29. TypeSystems.OneTypeSystems oneTypeSystems = this.typeSystems.GetOrCreateOneTypeSystems(iSystemType.Type());
  30. oneTypeSystems.Map.Add(iSystemType.SystemType(), obj);
  31. int index = iSystemType.GetInstanceQueueIndex();
  32. if (index > InstanceQueueIndex.None && index < InstanceQueueIndex.Max)
  33. {
  34. oneTypeSystems.QueueFlag[index] = true;
  35. }
  36. }
  37. }
  38. public TypeSystems.OneTypeSystems GetOneTypeSystems(Type type)
  39. {
  40. return this.typeSystems.GetOneTypeSystems(type);
  41. }
  42. public void LSRollback(Entity entity)
  43. {
  44. if (entity is not ILSRollback)
  45. {
  46. return;
  47. }
  48. List<object> iLSRollbackSystems = this.typeSystems.GetSystems(entity.GetType(), typeof (ILSRollbackSystem));
  49. if (iLSRollbackSystems == null)
  50. {
  51. return;
  52. }
  53. foreach (ILSRollbackSystem iLSRollbackSystem in iLSRollbackSystems)
  54. {
  55. if (iLSRollbackSystem == null)
  56. {
  57. continue;
  58. }
  59. try
  60. {
  61. iLSRollbackSystem.Run(entity);
  62. }
  63. catch (Exception e)
  64. {
  65. Log.Error(e);
  66. }
  67. }
  68. }
  69. public void LSUpdate(LSEntity entity)
  70. {
  71. if (entity is not ILSUpdate)
  72. {
  73. return;
  74. }
  75. List<object> iLSUpdateSystems = typeSystems.GetSystems(entity.GetType(), typeof (ILSUpdateSystem));
  76. if (iLSUpdateSystems == null)
  77. {
  78. return;
  79. }
  80. foreach (ILSUpdateSystem iLSUpdateSystem in iLSUpdateSystems)
  81. {
  82. try
  83. {
  84. iLSUpdateSystem.Run(entity);
  85. }
  86. catch (Exception e)
  87. {
  88. Log.Error(e);
  89. }
  90. }
  91. }
  92. }
  93. }