LSSington.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 LSSington: Singleton<LSSington>, ISingletonAwake
  13. {
  14. private readonly TypeSystems typeSystems = new(LSQueneUpdateIndex.Max);
  15. public void Awake()
  16. {
  17. foreach (Type type in EventSystem.Instance.GetTypes(typeof (LSSystemAttribute)))
  18. {
  19. object obj = Activator.CreateInstance(type);
  20. if (obj is not ISystemType iSystemType)
  21. {
  22. continue;
  23. }
  24. TypeSystems.OneTypeSystems oneTypeSystems = this.typeSystems.GetOrCreateOneTypeSystems(iSystemType.Type());
  25. oneTypeSystems.Map.Add(iSystemType.SystemType(), obj);
  26. int index = iSystemType.GetInstanceQueueIndex();
  27. if (index > InstanceQueueIndex.None && index < InstanceQueueIndex.Max)
  28. {
  29. oneTypeSystems.QueueFlag[index] = true;
  30. }
  31. }
  32. }
  33. public TypeSystems.OneTypeSystems GetOneTypeSystems(Type type)
  34. {
  35. return this.typeSystems.GetOneTypeSystems(type);
  36. }
  37. public void Rollback(Entity entity)
  38. {
  39. if (entity is not IRollback)
  40. {
  41. return;
  42. }
  43. List<object> iRollbackSystems = this.typeSystems.GetSystems(entity.GetType(), typeof (IRollbackSystem));
  44. if (iRollbackSystems == null)
  45. {
  46. return;
  47. }
  48. foreach (IRollbackSystem iRollbackSystem in iRollbackSystems)
  49. {
  50. if (iRollbackSystem == null)
  51. {
  52. continue;
  53. }
  54. try
  55. {
  56. iRollbackSystem.Run(entity);
  57. }
  58. catch (Exception e)
  59. {
  60. Log.Error(e);
  61. }
  62. }
  63. }
  64. public void LSUpdate(LSEntity entity)
  65. {
  66. if (entity is not ILSUpdate)
  67. {
  68. return;
  69. }
  70. List<object> iLSUpdateSystems = typeSystems.GetSystems(entity.GetType(), typeof (ILSUpdateSystem));
  71. if (iLSUpdateSystems == null)
  72. {
  73. return;
  74. }
  75. foreach (ILSUpdateSystem iLSUpdateSystem in iLSUpdateSystems)
  76. {
  77. try
  78. {
  79. iLSUpdateSystem.Run(entity);
  80. }
  81. catch (Exception e)
  82. {
  83. Log.Error(e);
  84. }
  85. }
  86. }
  87. }
  88. }