Jelajahi Sumber

做了两个大改动
1.EventSystem把ObjectSystem的部分拆成了单独的单间,叫做EntitySystemSingleton,主要是大家可以单独扩展各种System出来,例如这次的帧同步System,叫做LSEntitySingleton
2.Entity的System分析器也禁止访问Entity类成员了,这样可以把Entity的System放到System静态类中,后期可以用source generator生成这个System类,只需要写一个静态方法,例如Awake,加上标签就能生成AwakeSystem,这样会简化很多

tanghai 2 tahun lalu
induk
melakukan
9835c174d4
95 mengubah file dengan 1398 tambahan dan 1071 penghapusan
  1. 1 32
      Share/Analyzer/Analyzer/EntityFiledAccessAnalyzer.cs
  2. 1 1
      Share/Analyzer/Config/Definition.cs
  3. 24 24
      Unity/Assets/Scripts/Core/Module/Entity/Entity.cs
  4. 14 0
      Unity/Assets/Scripts/Core/Module/EventSystem/EntitySystemAttribute.cs
  5. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/EntitySystemAttribute.cs.meta
  6. 426 0
      Unity/Assets/Scripts/Core/Module/EventSystem/EntitySystemSingleton.cs
  7. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/EntitySystemSingleton.cs.meta
  8. 4 480
      Unity/Assets/Scripts/Core/Module/EventSystem/EventSystem.cs
  9. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/IAddComponentSystem.cs
  10. 5 5
      Unity/Assets/Scripts/Core/Module/EventSystem/IAwakeSystem.cs
  11. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/IDeserializeSystem.cs
  12. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/IDestroySystem.cs
  13. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/IGetComponentSystem.cs
  14. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/ILateUpdateSystem.cs
  15. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/ILoadSystem.cs
  16. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/IUpdateSystem.cs
  17. 0 9
      Unity/Assets/Scripts/Core/Module/EventSystem/ObjectSystemAttribute.cs
  18. 66 0
      Unity/Assets/Scripts/Core/Module/EventSystem/TypeSystems.cs
  19. 1 1
      Unity/Assets/Scripts/Core/Module/EventSystem/TypeSystems.cs.meta
  20. 2 2
      Unity/Assets/Scripts/Core/Module/Network/KChannel.cs
  21. 25 1
      Unity/Assets/Scripts/Core/Module/Network/MessageSerializeHelper.cs
  22. 2 2
      Unity/Assets/Scripts/Core/Module/Network/TChannel.cs
  23. 2 2
      Unity/Assets/Scripts/Core/Module/Network/WChannel.cs
  24. 0 34
      Unity/Assets/Scripts/Core/Serialize/SerializeHelper.cs
  25. 41 15
      Unity/Assets/Scripts/Core/Singleton/Game.cs
  26. 7 0
      Unity/Assets/Scripts/Core/Singleton/ISingletonLoad.cs
  27. 1 1
      Unity/Assets/Scripts/Core/Singleton/ISingletonLoad.cs.meta
  28. 2 2
      Unity/Assets/Scripts/Hotfix/Client/Demo/Ping/PingComponentSystem.cs
  29. 7 2
      Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterAddressComponentSystem.cs
  30. 1 1
      Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterCheckComponentSystem.cs
  31. 1 1
      Unity/Assets/Scripts/Hotfix/Client/LockStep/LSReplayUpdaterSystem.cs
  32. 16 6
      Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs
  33. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/PlayerSystem.cs
  34. 1 1
      Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Robot/RobotCaseSystem.cs
  35. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/RoomServerComponentSystem.cs
  36. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs
  37. 1 1
      Unity/Assets/Scripts/Hotfix/Server/LockStep/Room/LSServerUpdaterSystem.cs
  38. 28 14
      Unity/Assets/Scripts/Hotfix/Server/Module/AOI/AOIEntitySystem.cs
  39. 10 5
      Unity/Assets/Scripts/Hotfix/Server/Module/AOI/CellSystem.cs
  40. 11 6
      Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageDispatcherComponentSystem.cs
  41. 19 9
      Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageSenderComponentSystem.cs
  42. 29 13
      Unity/Assets/Scripts/Hotfix/Server/Module/Actor/MailBoxComponentSystem.cs
  43. 27 14
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs
  44. 21 9
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderSystem.cs
  45. 39 16
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationOneTypeSystem.cs
  46. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs
  47. 7 2
      Unity/Assets/Scripts/Hotfix/Server/Module/DB/DBComponentSystem.cs
  48. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Module/DB/DBManagerComponentSystem.cs
  49. 32 22
      Unity/Assets/Scripts/Hotfix/Server/Module/Http/HttpComponentSystem.cs
  50. 50 35
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentSystem.cs
  51. 17 7
      Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs
  52. 2 2
      Unity/Assets/Scripts/Hotfix/Server/Module/RobotCase/RobotCaseComponentSystem.cs
  53. 48 33
      Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs
  54. 29 19
      Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterNodeSystem.cs
  55. 1 1
      Unity/Assets/Scripts/Hotfix/Share/LockStep/LSHelper.cs
  56. 1 1
      Unity/Assets/Scripts/Hotfix/Share/LockStep/LSInputComponentSystem.cs
  57. 18 8
      Unity/Assets/Scripts/Hotfix/Share/Module/AI/AIComponentSystem.cs
  58. 17 7
      Unity/Assets/Scripts/Hotfix/Share/Module/AI/AIDispatcherComponentSystem.cs
  59. 2 2
      Unity/Assets/Scripts/Hotfix/Share/Module/Console/ConsoleComponentSystem.cs
  60. 17 7
      Unity/Assets/Scripts/Hotfix/Share/Module/Message/MessageDispatcherComponentSystem.cs
  61. 35 18
      Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionAcceptTimeoutComponentSystem.cs
  62. 36 25
      Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionIdleCheckerComponentSystem.cs
  63. 22 12
      Unity/Assets/Scripts/Hotfix/Share/Module/Move/MoveComponentSystem.cs
  64. 20 10
      Unity/Assets/Scripts/Hotfix/Share/Module/Recast/PathfindingComponentSystem.cs
  65. 2 2
      Unity/Assets/Scripts/Hotfix/Share/Module/Scene/ClientSceneManagerComponentSystem.cs
  66. 2 2
      Unity/Assets/Scripts/Hotfix/Share/Module/Scene/ServerSceneManagerComponentSystem.cs
  67. 0 16
      Unity/Assets/Scripts/Hotfix/Share/Module/Unit/UnitComponentSystem.cs
  68. 1 1
      Unity/Assets/Scripts/Hotfix/Share/Module/Unit/UnitSystem.cs
  69. 3 3
      Unity/Assets/Scripts/HotfixView/Client/Demo/Opera/OperaComponentSystem.cs
  70. 1 1
      Unity/Assets/Scripts/HotfixView/Client/Demo/UI/UILobby/UILobbyComponentSystem.cs
  71. 1 1
      Unity/Assets/Scripts/HotfixView/Client/Demo/UI/UILogin/UILoginComponentSystem.cs
  72. 3 3
      Unity/Assets/Scripts/HotfixView/Client/Demo/Unit/AnimatorComponentSystem.cs
  73. 1 1
      Unity/Assets/Scripts/HotfixView/Client/Demo/Unit/GameObjectComponentSystem.cs
  74. 2 2
      Unity/Assets/Scripts/HotfixView/Client/LockStep/Camera/LSCameraComponentSystem.cs
  75. 3 3
      Unity/Assets/Scripts/HotfixView/Client/LockStep/LSAnimatorComponentSystem.cs
  76. 1 1
      Unity/Assets/Scripts/HotfixView/Client/LockStep/UI/UILSLobby/UILSLobbyComponentSystem.cs
  77. 1 1
      Unity/Assets/Scripts/HotfixView/Client/LockStep/UI/UILSLogin/UILoginComponentSystem.cs
  78. 1 1
      Unity/Assets/Scripts/HotfixView/Client/Module/UI/UIEventComponentSystem.cs
  79. 4 1
      Unity/Assets/Scripts/Model/Share/Entry.cs
  80. 1 1
      Unity/Assets/Scripts/Model/Share/LockStep/ILSUpdateSystem.cs
  81. 1 1
      Unity/Assets/Scripts/Model/Share/LockStep/IRollbackSystem.cs
  82. 1 1
      Unity/Assets/Scripts/Model/Share/LockStep/LSEntity.cs
  83. 1 1
      Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemAttribute.cs
  84. 11 0
      Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemAttribute.cs.meta
  85. 9 3
      Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemSington.cs
  86. 11 0
      Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemSington.cs.meta
  87. 1 1
      Unity/Assets/Scripts/Model/Share/LockStep/LSUpdater.cs
  88. 25 9
      Unity/Assets/Scripts/Model/Share/Module/Console/ModeContex.cs
  89. 54 47
      Unity/Assets/Scripts/Model/Share/Module/Message/OpcodeTypeComponent.cs
  90. 27 17
      Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs
  91. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Numeric/NumericWatcherComponent.cs
  92. 17 7
      Unity/Assets/Scripts/Model/Share/Module/ObjectWait/ObjectWait.cs
  93. 4 4
      Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesComponent.cs
  94. 1 1
      Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesLoaderComponent.cs
  95. 2 2
      Unity/Assets/Scripts/ModelView/Client/Module/UI/UI.cs

+ 1 - 32
Share/Analyzer/Analyzer/EntityFiledAccessAnalyzer.cs

@@ -94,11 +94,7 @@ namespace ET.Analyzer
                 return;
             }
             
-            //判断是否在实体类生命周期System中
-            if (this.CheckIsEntityLifecycleSystem(accessFieldClassSymbol, filedSymbol.ContainingType))
-            {
-                return;
-            }
+            //判断是否在实体类生命周期System中, 这里做了修改,周期System也不允许
 
             //判断是否在实体类的友元类中
             if (this.CheckIsEntityFriendOf(accessFieldClassSymbol, filedSymbol.ContainingType))
@@ -113,33 +109,6 @@ namespace ET.Analyzer
             context.ReportDiagnostic(diagnostic);
         }
 
-        private bool CheckIsEntityLifecycleSystem(INamedTypeSymbol accessFieldClassSymbol, INamedTypeSymbol entityTypeSymbol)
-        {
-            if (accessFieldClassSymbol.BaseType == null || !accessFieldClassSymbol.BaseType.IsGenericType)
-            {
-                return false;
-            }
-
-            // 判断是否含有 ObjectSystem Attribute 且继承了接口 ISystemType
-            if (accessFieldClassSymbol.BaseType.HasAttribute(Definition.ObjectSystemAttribute) && accessFieldClassSymbol.HasInterface(Definition.ISystemType))
-            {
-                // 获取 accessFieldClassSymbol 父类的实体类型参数
-                ITypeSymbol? entityTypeArgumentSymbol = accessFieldClassSymbol.BaseType.TypeArguments.FirstOrDefault();
-                if (entityTypeArgumentSymbol == null)
-                {
-                    return false;
-                }
-
-                // 判断 accessFieldClassSymbol 父类的实体类型参数是否为 entityTypeSymbol
-                if (entityTypeArgumentSymbol.ToString() == entityTypeSymbol.ToString())
-                {
-                    return true;
-                }
-            }
-
-            return false;
-        }
-
         private bool CheckIsEntityFriendOf(INamedTypeSymbol accessFieldTypeSymbol, INamedTypeSymbol entityTypeSymbol)
         {
             var attributes = accessFieldTypeSymbol.GetAttributes();

+ 1 - 1
Share/Analyzer/Config/Definition.cs

@@ -16,7 +16,7 @@
         
         public const string BaseAttribute = "ET.BaseAttribute";
         
-        public const string ObjectSystemAttribute = "ET.ObjectSystemAttribute";
+        public const string ObjectSystemAttribute = "ET.SystemAttribute";
 
         public const string EnableMethodAttribute = "ET.EnableMethodAttribute";
         

+ 24 - 24
Unity/Assets/Scripts/Core/Module/Entity/Entity.cs

@@ -96,7 +96,7 @@ namespace ET
 
         protected virtual void RegisterSystem()
         {
-            EventSystem.Instance.RegisterSystem(this);
+            EntitySystemSingleton.Instance.RegisterSystem(this);
         }
 
         protected virtual string ViewName
@@ -349,7 +349,7 @@ namespace ET
                 if (!this.IsCreated)
                 {
                     this.IsCreated = true;
-                    EventSystem.Instance.Deserialize(this);
+                    EntitySystemSingleton.Instance.Deserialize(this);
                 }
             }
         }
@@ -486,7 +486,7 @@ namespace ET
             // 触发Destroy事件
             if (this is IDestroy)
             {
-                EventSystem.Instance.Destroy(this);
+                EntitySystemSingleton.Instance.Destroy(this);
             }
 
             this.domain = null;
@@ -646,7 +646,7 @@ namespace ET
             // 如果有IGetComponent接口,则触发GetComponentSystem
             if (this is IGetComponent)
             {
-                EventSystem.Instance.GetComponent(this, component);
+                EntitySystemSingleton.Instance.GetComponent(this, component);
             }
 
             return (K) component;
@@ -668,7 +668,7 @@ namespace ET
             // 如果有IGetComponent接口,则触发GetComponentSystem
             if (this is IGetComponent)
             {
-                EventSystem.Instance.GetComponent(this, component);
+                EntitySystemSingleton.Instance.GetComponent(this, component);
             }
 
             return component;
@@ -705,7 +705,7 @@ namespace ET
 
             if (this is IAddComponent)
             {
-                EventSystem.Instance.AddComponent(this, component);
+                EntitySystemSingleton.Instance.AddComponent(this, component);
             }
 
             return component;
@@ -721,11 +721,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = this.Id;
             component.ComponentParent = this;
-            EventSystem.Instance.Awake(component);
+            EntitySystemSingleton.Instance.Awake(component);
 
             if (this is IAddComponent)
             {
-                EventSystem.Instance.AddComponent(this, component);
+                EntitySystemSingleton.Instance.AddComponent(this, component);
             }
 
             return component;
@@ -742,11 +742,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = id;
             component.ComponentParent = this;
-            EventSystem.Instance.Awake(component);
+            EntitySystemSingleton.Instance.Awake(component);
 
             if (this is IAddComponent)
             {
-                EventSystem.Instance.AddComponent(this, component);
+                EntitySystemSingleton.Instance.AddComponent(this, component);
             }
 
             return component as K;
@@ -763,11 +763,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = id;
             component.ComponentParent = this;
-            EventSystem.Instance.Awake(component, p1);
+            EntitySystemSingleton.Instance.Awake(component, p1);
 
             if (this is IAddComponent)
             {
-                EventSystem.Instance.AddComponent(this, component);
+                EntitySystemSingleton.Instance.AddComponent(this, component);
             }
 
             return component as K;
@@ -784,11 +784,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = id;
             component.ComponentParent = this;
-            EventSystem.Instance.Awake(component, p1, p2);
+            EntitySystemSingleton.Instance.Awake(component, p1, p2);
 
             if (this is IAddComponent)
             {
-                EventSystem.Instance.AddComponent(this, component);
+                EntitySystemSingleton.Instance.AddComponent(this, component);
             }
 
             return component as K;
@@ -805,11 +805,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = id;
             component.ComponentParent = this;
-            EventSystem.Instance.Awake(component, p1, p2, p3);
+            EntitySystemSingleton.Instance.Awake(component, p1, p2, p3);
 
             if (this is IAddComponent)
             {
-                EventSystem.Instance.AddComponent(this, component);
+                EntitySystemSingleton.Instance.AddComponent(this, component);
             }
 
             return component as K;
@@ -848,7 +848,7 @@ namespace ET
             component.Id = IdGenerater.Instance.GenerateId();
             component.Parent = this;
 
-            EventSystem.Instance.Awake(component);
+            EntitySystemSingleton.Instance.Awake(component);
             return component;
         }
 
@@ -859,7 +859,7 @@ namespace ET
             component.Id = IdGenerater.Instance.GenerateId();
             component.Parent = this;
 
-            EventSystem.Instance.Awake(component, a);
+            EntitySystemSingleton.Instance.Awake(component, a);
             return component;
         }
 
@@ -870,7 +870,7 @@ namespace ET
             component.Id = IdGenerater.Instance.GenerateId();
             component.Parent = this;
 
-            EventSystem.Instance.Awake(component, a, b);
+            EntitySystemSingleton.Instance.Awake(component, a, b);
             return component;
         }
 
@@ -881,7 +881,7 @@ namespace ET
             component.Id = IdGenerater.Instance.GenerateId();
             component.Parent = this;
 
-            EventSystem.Instance.Awake(component, a, b, c);
+            EntitySystemSingleton.Instance.Awake(component, a, b, c);
             return component;
         }
 
@@ -891,7 +891,7 @@ namespace ET
             T component = Entity.Create(type, isFromPool) as T;
             component.Id = id;
             component.Parent = this;
-            EventSystem.Instance.Awake(component);
+            EntitySystemSingleton.Instance.Awake(component);
             return component;
         }
 
@@ -902,7 +902,7 @@ namespace ET
             component.Id = id;
             component.Parent = this;
 
-            EventSystem.Instance.Awake(component, a);
+            EntitySystemSingleton.Instance.Awake(component, a);
             return component;
         }
 
@@ -913,7 +913,7 @@ namespace ET
             component.Id = id;
             component.Parent = this;
 
-            EventSystem.Instance.Awake(component, a, b);
+            EntitySystemSingleton.Instance.Awake(component, a, b);
             return component;
         }
 
@@ -924,7 +924,7 @@ namespace ET
             component.Id = id;
             component.Parent = this;
 
-            EventSystem.Instance.Awake(component, a, b, c);
+            EntitySystemSingleton.Instance.Awake(component, a, b, c);
             return component;
         }
 

+ 14 - 0
Unity/Assets/Scripts/Core/Module/EventSystem/EntitySystemAttribute.cs

@@ -0,0 +1,14 @@
+using System;
+
+namespace ET
+{
+	[AttributeUsage(AttributeTargets.Class)]
+	public class SystemAttribute: BaseAttribute
+	{
+	}
+	
+	[AttributeUsage(AttributeTargets.Class)]
+	public class EntitySystemAttribute: SystemAttribute
+	{
+	}
+}

+ 1 - 1
Unity/Assets/Scripts/Model/Share/LockStep/LSSington.cs.meta → Unity/Assets/Scripts/Core/Module/EventSystem/EntitySystemAttribute.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 5ce95fa13386040b9bfad6be674fc69a
+guid: fb281f49dbef64b43a444b5a62c8e353
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 426 - 0
Unity/Assets/Scripts/Core/Module/EventSystem/EntitySystemSingleton.cs

@@ -0,0 +1,426 @@
+using System;
+using System.Collections.Generic;
+
+namespace ET
+{
+    public class EntitySystemSingleton: Singleton<EntitySystemSingleton>, ISingletonAwake, ISingletonUpdate, ISingletonLateUpdate, ISingletonLoad
+    {
+        private TypeSystems typeSystems;
+
+        private readonly Queue<EntityRef<Entity>>[] queues = new Queue<EntityRef<Entity>>[InstanceQueueIndex.Max];
+        
+        public void Awake()
+        {
+            for (int i = 0; i < this.queues.Length; i++)
+            {
+                this.queues[i] = new Queue<EntityRef<Entity>>();
+            }
+            this.Load();
+        }
+
+        public void Load()
+        {
+            this.typeSystems = new TypeSystems(InstanceQueueIndex.Max);
+
+            foreach (Type type in EventSystem.Instance.GetTypes(typeof (EntitySystemAttribute)))
+            {
+                object obj = Activator.CreateInstance(type);
+
+                if (obj is ISystemType iSystemType)
+                {
+                    TypeSystems.OneTypeSystems oneTypeSystems = this.typeSystems.GetOrCreateOneTypeSystems(iSystemType.Type());
+                    oneTypeSystems.Map.Add(iSystemType.SystemType(), obj);
+                    int index = iSystemType.GetInstanceQueueIndex();
+                    if (index > InstanceQueueIndex.None && index < InstanceQueueIndex.Max)
+                    {
+                        oneTypeSystems.QueueFlag[index] = true;
+                    }
+                }
+            }
+            
+            
+            Queue<EntityRef<Entity>> queue = this.queues[InstanceQueueIndex.Load];
+            int count = queue.Count;
+            while (count-- > 0)
+            {
+                Entity component = queue.Dequeue();
+                if (component == null)
+                {
+                    continue;
+                }
+
+                if (component.IsDisposed)
+                {
+                    continue;
+                }
+
+                if (component is not ILoad)
+                {
+                    continue;
+                }
+
+                List<object> iLoadSystems = this.typeSystems.GetSystems(component.GetType(), typeof (ILoadSystem));
+                if (iLoadSystems == null)
+                {
+                    continue;
+                }
+
+                queue.Enqueue(component);
+
+                foreach (ILoadSystem iLoadSystem in iLoadSystems)
+                {
+                    try
+                    {
+                        iLoadSystem.Run(component);
+                    }
+                    catch (Exception e)
+                    {
+                        Log.Error(e);
+                    }
+                }
+            }
+        }
+        
+        public virtual void RegisterSystem(Entity component)
+        {
+            Type type = component.GetType();
+
+            TypeSystems.OneTypeSystems oneTypeSystems = this.typeSystems.GetOneTypeSystems(type);
+            if (oneTypeSystems == null)
+            {
+                return;
+            }
+            for (int i = 0; i < oneTypeSystems.QueueFlag.Length; ++i)
+            {
+                if (!oneTypeSystems.QueueFlag[i])
+                {
+                    continue;
+                }
+                this.queues[i].Enqueue(component);
+            }
+        }
+        
+        public void Deserialize(Entity component)
+        {
+            if (component is not IDeserialize)
+            {
+                return;
+            }
+            
+            List<object> iDeserializeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IDeserializeSystem));
+            if (iDeserializeSystems == null)
+            {
+                return;
+            }
+
+            foreach (IDeserializeSystem deserializeSystem in iDeserializeSystems)
+            {
+                if (deserializeSystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    deserializeSystem.Run(component);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+        
+        // GetComponentSystem
+        public void GetComponent(Entity entity, Entity component)
+        {
+            List<object> iGetSystem = this.typeSystems.GetSystems(entity.GetType(), typeof (IGetComponentSystem));
+            if (iGetSystem == null)
+            {
+                return;
+            }
+
+            foreach (IGetComponentSystem getSystem in iGetSystem)
+            {
+                if (getSystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    getSystem.Run(entity, component);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+        
+        // AddComponentSystem
+        public void AddComponent(Entity entity, Entity component)
+        {
+            List<object> iAddSystem = this.typeSystems.GetSystems(entity.GetType(), typeof (IAddComponentSystem));
+            if (iAddSystem == null)
+            {
+                return;
+            }
+
+            foreach (IAddComponentSystem addComponentSystem in iAddSystem)
+            {
+                if (addComponentSystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    addComponentSystem.Run(entity, component);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+
+        public void Awake(Entity component)
+        {
+            List<object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem));
+            if (iAwakeSystems == null)
+            {
+                return;
+            }
+
+            foreach (IAwakeSystem aAwakeSystem in iAwakeSystems)
+            {
+                if (aAwakeSystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    aAwakeSystem.Run(component);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+
+        public void Awake<P1>(Entity component, P1 p1)
+        {
+            if (component is not IAwake<P1>)
+            {
+                return;
+            }
+            
+            List<object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem<P1>));
+            if (iAwakeSystems == null)
+            {
+                return;
+            }
+
+            foreach (IAwakeSystem<P1> aAwakeSystem in iAwakeSystems)
+            {
+                if (aAwakeSystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    aAwakeSystem.Run(component, p1);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+
+        public void Awake<P1, P2>(Entity component, P1 p1, P2 p2)
+        {
+            if (component is not IAwake<P1, P2>)
+            {
+                return;
+            }
+            
+            List<object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem<P1, P2>));
+            if (iAwakeSystems == null)
+            {
+                return;
+            }
+
+            foreach (IAwakeSystem<P1, P2> aAwakeSystem in iAwakeSystems)
+            {
+                if (aAwakeSystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    aAwakeSystem.Run(component, p1, p2);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+
+        public void Awake<P1, P2, P3>(Entity component, P1 p1, P2 p2, P3 p3)
+        {
+            if (component is not IAwake<P1, P2, P3>)
+            {
+                return;
+            }
+            
+            List<object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem<P1, P2, P3>));
+            if (iAwakeSystems == null)
+            {
+                return;
+            }
+
+            foreach (IAwakeSystem<P1, P2, P3> aAwakeSystem in iAwakeSystems)
+            {
+                if (aAwakeSystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    aAwakeSystem.Run(component, p1, p2, p3);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+
+        public void Destroy(Entity component)
+        {
+            if (component is not IDestroy)
+            {
+                return;
+            }
+            
+            List<object> iDestroySystems = this.typeSystems.GetSystems(component.GetType(), typeof (IDestroySystem));
+            if (iDestroySystems == null)
+            {
+                return;
+            }
+
+            foreach (IDestroySystem iDestroySystem in iDestroySystems)
+            {
+                if (iDestroySystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    iDestroySystem.Run(component);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+
+        public void Update()
+        {
+            Queue<EntityRef<Entity>> queue = this.queues[InstanceQueueIndex.Update];
+            int count = queue.Count;
+            while (count-- > 0)
+            {
+                Entity component = queue.Dequeue();
+                if (component == null)
+                {
+                    continue;
+                }
+
+                if (component.IsDisposed)
+                {
+                    continue;
+                }
+                
+                if (component is not IUpdate)
+                {
+                    continue;
+                }
+
+                List<object> iUpdateSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IUpdateSystem));
+                if (iUpdateSystems == null)
+                {
+                    continue;
+                }
+
+                queue.Enqueue(component);
+
+                foreach (IUpdateSystem iUpdateSystem in iUpdateSystems)
+                {
+                    try
+                    {
+                        iUpdateSystem.Run(component);
+                    }
+                    catch (Exception e)
+                    {
+                        Log.Error(e);
+                    }
+                }
+            }
+        }
+
+        public void LateUpdate()
+        {
+            Queue<EntityRef<Entity>> queue = this.queues[InstanceQueueIndex.LateUpdate];
+            int count = queue.Count;
+            while (count-- > 0)
+            {
+                Entity component = queue.Dequeue();
+                if (component == null)
+                {
+                    continue;
+                }
+
+                if (component.IsDisposed)
+                {
+                    continue;
+                }
+                
+                if (component is not ILateUpdate)
+                {
+                    continue;
+                }
+
+                List<object> iLateUpdateSystems = this.typeSystems.GetSystems(component.GetType(), typeof (ILateUpdateSystem));
+                if (iLateUpdateSystems == null)
+                {
+                    continue;
+                }
+
+                queue.Enqueue(component);
+
+                foreach (ILateUpdateSystem iLateUpdateSystem in iLateUpdateSystems)
+                {
+                    try
+                    {
+                        iLateUpdateSystem.Run(component);
+                    }
+                    catch (Exception e)
+                    {
+                        Log.Error(e);
+                    }
+                }
+            }
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Core/Module/EventSystem/ObjectSystemAttribute.cs.meta → Unity/Assets/Scripts/Core/Module/EventSystem/EntitySystemSingleton.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 1f36f2acb200b244bac466b10dfe0411
+guid: 66db4b290cd6347f487400fcdddb9740
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 4 - 480
Unity/Assets/Scripts/Core/Module/EventSystem/EventSystem.cs

@@ -5,68 +5,7 @@ using System.Text;
 
 namespace ET
 {
-    public class TypeSystems
-    {
-        public class OneTypeSystems
-        {
-            public OneTypeSystems(int count)
-            {
-                this.QueueFlag = new bool[count];
-            }
-            
-            public readonly UnOrderMultiMap<Type, object> Map = new();
-            // 这里不用hash,数量比较少,直接for循环速度更快
-            public readonly bool[] QueueFlag;
-        }
-
-        private readonly int count;
-
-        public TypeSystems(int count)
-        {
-            this.count = count;
-        }
-        
-        private readonly Dictionary<Type, OneTypeSystems> typeSystemsMap = new();
-
-        public OneTypeSystems GetOrCreateOneTypeSystems(Type type)
-        {
-            OneTypeSystems systems = null;
-            this.typeSystemsMap.TryGetValue(type, out systems);
-            if (systems != null)
-            {
-                return systems;
-            }
-
-            systems = new OneTypeSystems(this.count);
-            this.typeSystemsMap.Add(type, systems);
-            return systems;
-        }
-
-        public OneTypeSystems GetOneTypeSystems(Type type)
-        {
-            OneTypeSystems systems = null;
-            this.typeSystemsMap.TryGetValue(type, out systems);
-            return systems;
-        }
-
-        public List<object> GetSystems(Type type, Type systemType)
-        {
-            OneTypeSystems oneTypeSystems = null;
-            if (!this.typeSystemsMap.TryGetValue(type, out oneTypeSystems))
-            {
-                return null;
-            }
-
-            if (!oneTypeSystems.Map.TryGetValue(systemType, out List<object> systems))
-            {
-                return null;
-            }
-
-            return systems;
-        }
-    }
-    
-    public class EventSystem: Singleton<EventSystem>, ISingletonUpdate, ISingletonLateUpdate
+    public class EventSystem: Singleton<EventSystem>
     {
         private class EventInfo
         {
@@ -88,19 +27,7 @@ namespace ET
         private readonly Dictionary<Type, List<EventInfo>> allEvents = new();
         
         private Dictionary<Type, Dictionary<int, object>> allInvokes = new(); 
-
-        private TypeSystems typeSystems;
-
-        private readonly Queue<EntityRef<Entity>>[] queues = new Queue<EntityRef<Entity>>[InstanceQueueIndex.Max];
-
-        public EventSystem()
-        {
-            for (int i = 0; i < this.queues.Length; i++)
-            {
-                this.queues[i] = new Queue<EntityRef<Entity>>();
-            }
-        }
-
+        
         public void Add(Dictionary<string, Type> addTypes)
         {
             this.allTypes.Clear();
@@ -124,24 +51,6 @@ namespace ET
                 }
             }
 
-            this.typeSystems = new TypeSystems(InstanceQueueIndex.Max);
-
-            foreach (Type type in this.GetTypes(typeof (ObjectSystemAttribute)))
-            {
-                object obj = Activator.CreateInstance(type);
-
-                if (obj is ISystemType iSystemType)
-                {
-                    TypeSystems.OneTypeSystems oneTypeSystems = this.typeSystems.GetOrCreateOneTypeSystems(iSystemType.Type());
-                    oneTypeSystems.Map.Add(iSystemType.SystemType(), obj);
-                    int index = iSystemType.GetInstanceQueueIndex();
-                    if (index > InstanceQueueIndex.None && index < InstanceQueueIndex.Max)
-                    {
-                        oneTypeSystems.QueueFlag[index] = true;
-                    }
-                }
-            }
-
             this.allEvents.Clear();
             foreach (Type type in types[typeof (EventAttribute)])
             {
@@ -197,9 +106,10 @@ namespace ET
                     {
                         throw new Exception($"action type duplicate: {iInvoke.Type.Name} {invokeAttribute.Type}", e);
                     }
-                    
                 }
             }
+            
+            Game.Load();
         }
 
         public HashSet<Type> GetTypes(Type systemAttributeType)
@@ -222,392 +132,6 @@ namespace ET
             return this.allTypes[typeName];
         }
 
-        public virtual void RegisterSystem(Entity component)
-        {
-            Type type = component.GetType();
-
-            TypeSystems.OneTypeSystems oneTypeSystems = this.typeSystems.GetOneTypeSystems(type);
-            if (oneTypeSystems == null)
-            {
-                return;
-            }
-            for (int i = 0; i < oneTypeSystems.QueueFlag.Length; ++i)
-            {
-                if (!oneTypeSystems.QueueFlag[i])
-                {
-                    continue;
-                }
-                this.queues[i].Enqueue(component);
-            }
-        }
-
-        public void Deserialize(Entity component)
-        {
-            if (component is not IDeserialize)
-            {
-                return;
-            }
-            
-            List<object> iDeserializeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IDeserializeSystem));
-            if (iDeserializeSystems == null)
-            {
-                return;
-            }
-
-            foreach (IDeserializeSystem deserializeSystem in iDeserializeSystems)
-            {
-                if (deserializeSystem == null)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    deserializeSystem.Run(component);
-                }
-                catch (Exception e)
-                {
-                    Log.Error(e);
-                }
-            }
-        }
-        
-        // GetComponentSystem
-        public void GetComponent(Entity entity, Entity component)
-        {
-            List<object> iGetSystem = this.typeSystems.GetSystems(entity.GetType(), typeof (IGetComponentSystem));
-            if (iGetSystem == null)
-            {
-                return;
-            }
-
-            foreach (IGetComponentSystem getSystem in iGetSystem)
-            {
-                if (getSystem == null)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    getSystem.Run(entity, component);
-                }
-                catch (Exception e)
-                {
-                    Log.Error(e);
-                }
-            }
-        }
-        
-        // AddComponentSystem
-        public void AddComponent(Entity entity, Entity component)
-        {
-            List<object> iAddSystem = this.typeSystems.GetSystems(entity.GetType(), typeof (IAddComponentSystem));
-            if (iAddSystem == null)
-            {
-                return;
-            }
-
-            foreach (IAddComponentSystem addComponentSystem in iAddSystem)
-            {
-                if (addComponentSystem == null)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    addComponentSystem.Run(entity, component);
-                }
-                catch (Exception e)
-                {
-                    Log.Error(e);
-                }
-            }
-        }
-
-        public void Awake(Entity component)
-        {
-            List<object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem));
-            if (iAwakeSystems == null)
-            {
-                return;
-            }
-
-            foreach (IAwakeSystem aAwakeSystem in iAwakeSystems)
-            {
-                if (aAwakeSystem == null)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    aAwakeSystem.Run(component);
-                }
-                catch (Exception e)
-                {
-                    Log.Error(e);
-                }
-            }
-        }
-
-        public void Awake<P1>(Entity component, P1 p1)
-        {
-            if (component is not IAwake<P1>)
-            {
-                return;
-            }
-            
-            List<object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem<P1>));
-            if (iAwakeSystems == null)
-            {
-                return;
-            }
-
-            foreach (IAwakeSystem<P1> aAwakeSystem in iAwakeSystems)
-            {
-                if (aAwakeSystem == null)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    aAwakeSystem.Run(component, p1);
-                }
-                catch (Exception e)
-                {
-                    Log.Error(e);
-                }
-            }
-        }
-
-        public void Awake<P1, P2>(Entity component, P1 p1, P2 p2)
-        {
-            if (component is not IAwake<P1, P2>)
-            {
-                return;
-            }
-            
-            List<object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem<P1, P2>));
-            if (iAwakeSystems == null)
-            {
-                return;
-            }
-
-            foreach (IAwakeSystem<P1, P2> aAwakeSystem in iAwakeSystems)
-            {
-                if (aAwakeSystem == null)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    aAwakeSystem.Run(component, p1, p2);
-                }
-                catch (Exception e)
-                {
-                    Log.Error(e);
-                }
-            }
-        }
-
-        public void Awake<P1, P2, P3>(Entity component, P1 p1, P2 p2, P3 p3)
-        {
-            if (component is not IAwake<P1, P2, P3>)
-            {
-                return;
-            }
-            
-            List<object> iAwakeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IAwakeSystem<P1, P2, P3>));
-            if (iAwakeSystems == null)
-            {
-                return;
-            }
-
-            foreach (IAwakeSystem<P1, P2, P3> aAwakeSystem in iAwakeSystems)
-            {
-                if (aAwakeSystem == null)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    aAwakeSystem.Run(component, p1, p2, p3);
-                }
-                catch (Exception e)
-                {
-                    Log.Error(e);
-                }
-            }
-        }
-
-        public void Load()
-        {
-            Queue<EntityRef<Entity>> queue = this.queues[InstanceQueueIndex.Load];
-            int count = queue.Count;
-            while (count-- > 0)
-            {
-                Entity component = queue.Dequeue();
-                if (component == null)
-                {
-                    continue;
-                }
-
-                if (component.IsDisposed)
-                {
-                    continue;
-                }
-
-                if (component is not ILoad)
-                {
-                    continue;
-                }
-
-                List<object> iLoadSystems = this.typeSystems.GetSystems(component.GetType(), typeof (ILoadSystem));
-                if (iLoadSystems == null)
-                {
-                    continue;
-                }
-
-                queue.Enqueue(component);
-
-                foreach (ILoadSystem iLoadSystem in iLoadSystems)
-                {
-                    try
-                    {
-                        iLoadSystem.Run(component);
-                    }
-                    catch (Exception e)
-                    {
-                        Log.Error(e);
-                    }
-                }
-            }
-        }
-
-        public void Destroy(Entity component)
-        {
-            if (component is not IDestroy)
-            {
-                return;
-            }
-            
-            List<object> iDestroySystems = this.typeSystems.GetSystems(component.GetType(), typeof (IDestroySystem));
-            if (iDestroySystems == null)
-            {
-                return;
-            }
-
-            foreach (IDestroySystem iDestroySystem in iDestroySystems)
-            {
-                if (iDestroySystem == null)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    iDestroySystem.Run(component);
-                }
-                catch (Exception e)
-                {
-                    Log.Error(e);
-                }
-            }
-        }
-
-        public void Update()
-        {
-            Queue<EntityRef<Entity>> queue = this.queues[InstanceQueueIndex.Update];
-            int count = queue.Count;
-            while (count-- > 0)
-            {
-                Entity component = queue.Dequeue();
-                if (component == null)
-                {
-                    continue;
-                }
-
-                if (component.IsDisposed)
-                {
-                    continue;
-                }
-                
-                if (component is not IUpdate)
-                {
-                    continue;
-                }
-
-                List<object> iUpdateSystems = this.typeSystems.GetSystems(component.GetType(), typeof (IUpdateSystem));
-                if (iUpdateSystems == null)
-                {
-                    continue;
-                }
-
-                queue.Enqueue(component);
-
-                foreach (IUpdateSystem iUpdateSystem in iUpdateSystems)
-                {
-                    try
-                    {
-                        iUpdateSystem.Run(component);
-                    }
-                    catch (Exception e)
-                    {
-                        Log.Error(e);
-                    }
-                }
-            }
-        }
-
-        public void LateUpdate()
-        {
-            Queue<EntityRef<Entity>> queue = this.queues[InstanceQueueIndex.LateUpdate];
-            int count = queue.Count;
-            while (count-- > 0)
-            {
-                Entity component = queue.Dequeue();
-                if (component == null)
-                {
-                    continue;
-                }
-
-                if (component.IsDisposed)
-                {
-                    continue;
-                }
-                
-                if (component is not ILateUpdate)
-                {
-                    continue;
-                }
-
-                List<object> iLateUpdateSystems = this.typeSystems.GetSystems(component.GetType(), typeof (ILateUpdateSystem));
-                if (iLateUpdateSystems == null)
-                {
-                    continue;
-                }
-
-                queue.Enqueue(component);
-
-                foreach (ILateUpdateSystem iLateUpdateSystem in iLateUpdateSystems)
-                {
-                    try
-                    {
-                        iLateUpdateSystem.Run(component);
-                    }
-                    catch (Exception e)
-                    {
-                        Log.Error(e);
-                    }
-                }
-            }
-        }
-
         public async ETTask PublishAsync<S, T>(S scene, T a) where S: class, IScene where T : struct
         {
             List<EventInfo> iEvents;

+ 1 - 1
Unity/Assets/Scripts/Core/Module/EventSystem/IAddComponentSystem.cs

@@ -11,7 +11,7 @@ namespace ET
 		void Run(Entity o, Entity component);
 	}
 
-	[ObjectSystem]
+	[EntitySystem]
 	public abstract class AddComponentSystem<T> : IAddComponentSystem where T: Entity, IAddComponent
 	{
 		void IAddComponentSystem.Run(Entity o, Entity component)

+ 5 - 5
Unity/Assets/Scripts/Core/Module/EventSystem/IAwakeSystem.cs

@@ -47,7 +47,7 @@ namespace ET
         void Run(Entity o, A a, B b, C c, D d);
     }
 
-    [ObjectSystem]
+    [EntitySystem]
     public abstract class AwakeSystem<T> : IAwakeSystem where T: Entity, IAwake
     {
         Type ISystemType.Type()
@@ -73,7 +73,7 @@ namespace ET
         protected abstract void Awake(T self);
     }
     
-    [ObjectSystem]
+    [EntitySystem]
     public abstract class AwakeSystem<T, A> : IAwakeSystem<A> where T: Entity, IAwake<A>
     {
         Type ISystemType.Type()
@@ -99,7 +99,7 @@ namespace ET
         protected abstract void Awake(T self, A a);
     }
 
-    [ObjectSystem]
+    [EntitySystem]
     public abstract class AwakeSystem<T, A, B> : IAwakeSystem<A, B> where T: Entity, IAwake<A, B>
     {
         Type ISystemType.Type()
@@ -125,7 +125,7 @@ namespace ET
         protected abstract void Awake(T self, A a, B b);
     }
 
-    [ObjectSystem]
+    [EntitySystem]
     public abstract class AwakeSystem<T, A, B, C> : IAwakeSystem<A, B, C> where T: Entity, IAwake<A, B, C>
     {
         Type ISystemType.Type()
@@ -151,7 +151,7 @@ namespace ET
         protected abstract void Awake(T self, A a, B b, C c);
     }
     
-    [ObjectSystem]
+    [EntitySystem]
     public abstract class AwakeSystem<T, A, B, C, D> : IAwakeSystem<A, B, C, D> where T: Entity, IAwake<A, B, C, D>
     {
         Type ISystemType.Type()

+ 1 - 1
Unity/Assets/Scripts/Core/Module/EventSystem/IDeserializeSystem.cs

@@ -15,7 +15,7 @@ namespace ET
 	/// 反序列化后执行的System
 	/// </summary>
 	/// <typeparam name="T"></typeparam>
-	[ObjectSystem]
+	[EntitySystem]
 	public abstract class DeserializeSystem<T> : IDeserializeSystem where T: Entity, IDeserialize
 	{
 		void IDeserializeSystem.Run(Entity o)

+ 1 - 1
Unity/Assets/Scripts/Core/Module/EventSystem/IDestroySystem.cs

@@ -11,7 +11,7 @@ namespace ET
 		void Run(Entity o);
 	}
 
-	[ObjectSystem]
+	[EntitySystem]
 	public abstract class DestroySystem<T> : IDestroySystem where T: Entity, IDestroy
 	{
 		void IDestroySystem.Run(Entity o)

+ 1 - 1
Unity/Assets/Scripts/Core/Module/EventSystem/IGetComponentSystem.cs

@@ -15,7 +15,7 @@ namespace ET
 		void Run(Entity o, Entity component);
 	}
 
-	[ObjectSystem]
+	[EntitySystem]
 	public abstract class GetComponentSystem<T> : IGetComponentSystem where T: Entity, IGetComponent
 	{
 		void IGetComponentSystem.Run(Entity o, Entity component)

+ 1 - 1
Unity/Assets/Scripts/Core/Module/EventSystem/ILateUpdateSystem.cs

@@ -11,7 +11,7 @@ namespace ET
 		void Run(Entity o);
 	}
 
-	[ObjectSystem]
+	[EntitySystem]
 	public abstract class LateUpdateSystem<T> : ILateUpdateSystem where T: Entity, ILateUpdate
 	{
 		void ILateUpdateSystem.Run(Entity o)

+ 1 - 1
Unity/Assets/Scripts/Core/Module/EventSystem/ILoadSystem.cs

@@ -11,7 +11,7 @@ namespace ET
 		void Run(Entity o);
 	}
 
-	[ObjectSystem]
+	[EntitySystem]
 	public abstract class LoadSystem<T> : ILoadSystem where T: Entity, ILoad
 	{
 		void ILoadSystem.Run(Entity o)

+ 1 - 1
Unity/Assets/Scripts/Core/Module/EventSystem/IUpdateSystem.cs

@@ -11,7 +11,7 @@ namespace ET
 		void Run(Entity o);
 	}
 
-	[ObjectSystem]
+	[EntitySystem]
 	public abstract class UpdateSystem<T> : IUpdateSystem where T: Entity, IUpdate
 	{
 		void IUpdateSystem.Run(Entity o)

+ 0 - 9
Unity/Assets/Scripts/Core/Module/EventSystem/ObjectSystemAttribute.cs

@@ -1,9 +0,0 @@
-using System;
-
-namespace ET
-{
-	[AttributeUsage(AttributeTargets.Class)]
-	public class ObjectSystemAttribute: BaseAttribute
-	{
-	}
-}

+ 66 - 0
Unity/Assets/Scripts/Core/Module/EventSystem/TypeSystems.cs

@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+
+namespace ET
+{
+    public class TypeSystems
+    {
+        public class OneTypeSystems
+        {
+            public OneTypeSystems(int count)
+            {
+                this.QueueFlag = new bool[count];
+            }
+            
+            public readonly UnOrderMultiMap<Type, object> Map = new();
+            // 这里不用hash,数量比较少,直接for循环速度更快
+            public readonly bool[] QueueFlag;
+        }
+
+        private readonly int count;
+
+        public TypeSystems(int count)
+        {
+            this.count = count;
+        }
+        
+        private readonly Dictionary<Type, OneTypeSystems> typeSystemsMap = new();
+
+        public OneTypeSystems GetOrCreateOneTypeSystems(Type type)
+        {
+            OneTypeSystems systems = null;
+            this.typeSystemsMap.TryGetValue(type, out systems);
+            if (systems != null)
+            {
+                return systems;
+            }
+
+            systems = new OneTypeSystems(this.count);
+            this.typeSystemsMap.Add(type, systems);
+            return systems;
+        }
+
+        public OneTypeSystems GetOneTypeSystems(Type type)
+        {
+            OneTypeSystems systems = null;
+            this.typeSystemsMap.TryGetValue(type, out systems);
+            return systems;
+        }
+
+        public List<object> GetSystems(Type type, Type systemType)
+        {
+            OneTypeSystems oneTypeSystems = null;
+            if (!this.typeSystemsMap.TryGetValue(type, out oneTypeSystems))
+            {
+                return null;
+            }
+
+            if (!oneTypeSystems.Map.TryGetValue(systemType, out List<object> systems))
+            {
+                return null;
+            }
+
+            return systems;
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Model/Share/LockStep/LSSystemAttribute.cs.meta → Unity/Assets/Scripts/Core/Module/EventSystem/TypeSystems.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 56d67c3eee436459aa79c9a4008dfdd8
+guid: e0eda11a6dcbc4874882857077fa35a2
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 2 - 2
Unity/Assets/Scripts/Core/Module/Network/KChannel.cs

@@ -500,7 +500,7 @@ namespace ET
 					{
 						ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.KcpOpcodeIndex);
 						Type type = NetServices.Instance.GetType(opcode);
-						message = SerializeHelper.Deserialize(type, memoryStream);
+						message = MessageSerializeHelper.Deserialize(type, memoryStream);
 						break;
 					}
 					case ServiceType.Inner:
@@ -508,7 +508,7 @@ namespace ET
 						actorId = BitConverter.ToInt64(memoryStream.GetBuffer(), Packet.ActorIdIndex);
 						ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.OpcodeIndex);
 						Type type = NetServices.Instance.GetType(opcode);
-						message = SerializeHelper.Deserialize(type, memoryStream);
+						message = MessageSerializeHelper.Deserialize(type, memoryStream);
 						break;
 					}
 				}

+ 25 - 1
Unity/Assets/Scripts/Core/Module/Network/MessageSerializeHelper.cs

@@ -5,6 +5,30 @@ namespace ET
 {
     public static class MessageSerializeHelper
     {
+        public static byte[] Serialize(MessageObject message)
+        {
+            return MemoryPackHelper.Serialize(message);
+        }
+
+        public static void Serialize(MessageObject message, MemoryBuffer stream)
+        {
+            MemoryPackHelper.Serialize(message, stream);
+        }
+		
+        public static MessageObject Deserialize(Type type, byte[] bytes, int index, int count)
+        {
+            object o = NetServices.Instance.FetchMessage(type);
+            MemoryPackHelper.Deserialize(type, bytes, index, count, ref o);
+            return o as MessageObject;
+        }
+
+        public static MessageObject Deserialize(Type type, MemoryBuffer stream)
+        {
+            object o = NetServices.Instance.FetchMessage(type);
+            MemoryPackHelper.Deserialize(type, stream, ref o);
+            return o as MessageObject;
+        }
+        
         public static ushort MessageToStream(MemoryBuffer stream, MessageObject message)
         {
             int headOffset = Packet.ActorIdLength;
@@ -16,7 +40,7 @@ namespace ET
             
             stream.GetBuffer().WriteTo(headOffset, opcode);
             
-            SerializeHelper.Serialize(message, stream);
+            MessageSerializeHelper.Serialize(message, stream);
             
             stream.Seek(0, SeekOrigin.Begin);
             return opcode;

+ 2 - 2
Unity/Assets/Scripts/Core/Module/Network/TChannel.cs

@@ -369,7 +369,7 @@ namespace ET
 					{
 						ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.KcpOpcodeIndex);
 						Type type = NetServices.Instance.GetType(opcode);
-						message = SerializeHelper.Deserialize(type, memoryStream);
+						message = MessageSerializeHelper.Deserialize(type, memoryStream);
 						break;
 					}
 					case ServiceType.Inner:
@@ -377,7 +377,7 @@ namespace ET
 						actorId = BitConverter.ToInt64(memoryStream.GetBuffer(), Packet.ActorIdIndex);
 						ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.OpcodeIndex);
 						Type type = NetServices.Instance.GetType(opcode);
-						message = SerializeHelper.Deserialize(type, memoryStream);
+						message = MessageSerializeHelper.Deserialize(type, memoryStream);
 						break;
 					}
 				}

+ 2 - 2
Unity/Assets/Scripts/Core/Module/Network/WChannel.cs

@@ -226,7 +226,7 @@ namespace ET
                     {
                         ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.KcpOpcodeIndex);
                         Type type = NetServices.Instance.GetType(opcode);
-                        message = SerializeHelper.Deserialize(type, memoryStream);
+                        message = MessageSerializeHelper.Deserialize(type, memoryStream);
                         break;
                     }
                     case ServiceType.Inner:
@@ -234,7 +234,7 @@ namespace ET
                         actorId = BitConverter.ToInt64(memoryStream.GetBuffer(), Packet.ActorIdIndex);
                         ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.OpcodeIndex);
                         Type type = NetServices.Instance.GetType(opcode);
-                        message = SerializeHelper.Deserialize(type, memoryStream);
+                        message = MessageSerializeHelper.Deserialize(type, memoryStream);
                         break;
                     }
                 }

+ 0 - 34
Unity/Assets/Scripts/Core/Serialize/SerializeHelper.cs

@@ -1,34 +0,0 @@
-using System.IO;
-using System;
-using MemoryPack;
-#pragma warning disable CS0162
-
-namespace ET
-{
-    public static class SerializeHelper
-	{
-		public static byte[] Serialize(MessageObject message)
-		{
-			return MemoryPackHelper.Serialize(message);
-		}
-
-        public static void Serialize(MessageObject message, MemoryBuffer stream)
-        {
-			MemoryPackHelper.Serialize(message, stream);
-		}
-		
-		public static MessageObject Deserialize(Type type, byte[] bytes, int index, int count)
-		{
-			object o = NetServices.Instance.FetchMessage(type);
-			MemoryPackHelper.Deserialize(type, bytes, index, count, ref o);
-			return o as MessageObject;
-		}
-
-		public static MessageObject Deserialize(Type type, MemoryBuffer stream)
-		{
-			object o = NetServices.Instance.FetchMessage(type);
-			MemoryPackHelper.Deserialize(type, stream, ref o);
-			return o as MessageObject;
-        }
-    }
-}

+ 41 - 15
Unity/Assets/Scripts/Core/Singleton/Game.cs

@@ -6,15 +6,15 @@ namespace ET
     public static class Game
     {
         [StaticField]
-        private static readonly Dictionary<Type, ISingleton> singletonTypes = new Dictionary<Type, ISingleton>();
+        private static readonly Stack<ISingleton> singletons = new();
         [StaticField]
-        private static readonly Stack<ISingleton> singletons = new Stack<ISingleton>();
+        private static readonly Queue<ISingleton> updates = new();
         [StaticField]
-        private static readonly Queue<ISingleton> updates = new Queue<ISingleton>();
+        private static readonly Queue<ISingleton> lateUpdates = new();
         [StaticField]
-        private static readonly Queue<ISingleton> lateUpdates = new Queue<ISingleton>();
+        private static readonly Queue<ISingleton> loads = new();
         [StaticField]
-        private static readonly Queue<ETTask> frameFinishTask = new Queue<ETTask>();
+        private static readonly Queue<ETTask> frameFinishTask = new();
 
         public static T AddSingleton<T>() where T: Singleton<T>, new()
         {
@@ -25,17 +25,10 @@ namespace ET
         
         public static void AddSingleton(ISingleton singleton)
         {
-            Type singletonType = singleton.GetType();
-            if (singletonTypes.ContainsKey(singletonType))
-            {
-                throw new Exception($"already exist singleton: {singletonType.Name}");
-            }
-
-            singletonTypes.Add(singletonType, singleton);
+            singleton.Register();
+            
             singletons.Push(singleton);
             
-            singleton.Register();
-
             if (singleton is ISingletonAwake awake)
             {
                 awake.Awake();
@@ -50,6 +43,11 @@ namespace ET
             {
                 lateUpdates.Enqueue(singleton);
             }
+
+            if (singleton is ISingletonLoad)
+            {
+                loads.Enqueue(singleton);
+            }
         }
 
         public static async ETTask WaitFrameFinish()
@@ -116,6 +114,35 @@ namespace ET
                 }
             }
         }
+        
+        public static void Load()
+        {
+            int count = loads.Count;
+            while (count-- > 0)
+            {
+                ISingleton singleton = loads.Dequeue();
+                
+                if (singleton.IsDisposed())
+                {
+                    continue;
+                }
+
+                if (singleton is not ISingletonLoad load)
+                {
+                    continue;
+                }
+                
+                loads.Enqueue(singleton);
+                try
+                {
+                    load.Load();
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
 
         public static void FrameFinishUpdate()
         {
@@ -134,7 +161,6 @@ namespace ET
                 ISingleton iSingleton = singletons.Pop();
                 iSingleton.Destroy();
             }
-            singletonTypes.Clear();
         }
     }
 }

+ 7 - 0
Unity/Assets/Scripts/Core/Singleton/ISingletonLoad.cs

@@ -0,0 +1,7 @@
+namespace ET
+{
+    public interface ISingletonLoad
+    {
+        void Load();
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Core/Serialize/SerializeHelper.cs.meta → Unity/Assets/Scripts/Core/Singleton/ISingletonLoad.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 94e49eb218611e847ac10578b1e66124
+guid: 8ef1119ffe67d423f9988b71ba3e528c
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Client/Demo/Ping/PingComponentSystem.cs

@@ -2,7 +2,7 @@ using System;
 
 namespace ET.Client
 {
-    [ObjectSystem]
+    [EntitySystem]
     public class PingComponentAwakeSystem: AwakeSystem<PingComponent>
     {
         protected override void Awake(PingComponent self)
@@ -56,7 +56,7 @@ namespace ET.Client
         }
     }
 
-    [ObjectSystem]
+    [EntitySystem]
     public class PingComponentDestroySystem: DestroySystem<PingComponent>
     {
         protected override void Destroy(PingComponent self)

+ 7 - 2
Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterAddressComponentSystem.cs

@@ -12,10 +12,15 @@ namespace ET.Client
         {
             protected override void Awake(RouterAddressComponent self, string address, int port)
             {
-                self.RouterManagerHost = address;
-                self.RouterManagerPort = port;
+                self.Awake(address, port);
             }
         }
+
+        private static void Awake(this RouterAddressComponent self, string address, int port)
+        {
+            self.RouterManagerHost = address;
+            self.RouterManagerPort = port;
+        }
         
         public static async ETTask Init(this RouterAddressComponent self)
         {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/Demo/Router/RouterCheckComponentSystem.cs

@@ -3,7 +3,7 @@ using System.Net;
 
 namespace ET.Client
 {
-    [ObjectSystem]
+    [EntitySystem]
     public class RouterCheckComponentAwakeSystem: AwakeSystem<RouterCheckComponent>
     {
         protected override void Awake(RouterCheckComponent self)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Client/LockStep/LSReplayUpdaterSystem.cs

@@ -5,7 +5,7 @@ namespace ET.Client
     [FriendOf(typeof(LSReplayUpdater))]
     public static class LSReplayComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class UpdateSystem: UpdateSystem<LSReplayUpdater>
         {
             protected override void Update(LSReplayUpdater self)

+ 16 - 6
Unity/Assets/Scripts/Hotfix/Client/Module/Message/NetClientComponentSystem.cs

@@ -6,25 +6,35 @@ namespace ET.Client
     [FriendOf(typeof(NetClientComponent))]
     public static class NetClientComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class AwakeSystem: AwakeSystem<NetClientComponent, AddressFamily>
         {
             protected override void Awake(NetClientComponent self, AddressFamily addressFamily)
             {
-                self.ServiceId = NetServices.Instance.AddService(new KService(addressFamily, ServiceType.Outer));
-                NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
-                NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
+                self.Awake(addressFamily);
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class DestroySystem: DestroySystem<NetClientComponent>
         {
             protected override void Destroy(NetClientComponent self)
             {
-                NetServices.Instance.RemoveService(self.ServiceId);
+                self.Destroy();
             }
         }
+        
+        private static void Awake(this NetClientComponent self, AddressFamily addressFamily)
+        {
+            self.ServiceId = NetServices.Instance.AddService(new KService(addressFamily, ServiceType.Outer));
+            NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
+            NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
+        }
+        
+        private static void Destroy(this NetClientComponent self)
+        {
+            NetServices.Instance.RemoveService(self.ServiceId);
+        }
 
         private static void OnRead(this NetClientComponent self, long channelId, long actorId, object message)
         {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Gate/PlayerSystem.cs

@@ -3,7 +3,7 @@
     [FriendOf(typeof(Player))]
     public static class PlayerSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class PlayerAwakeSystem : AwakeSystem<Player, string>
         {
             protected override void Awake(Player self, string a)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/Demo/Scenes/Robot/RobotCaseSystem.cs

@@ -5,7 +5,7 @@ namespace ET.Server
 {
     public static class RobotCaseSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class RobotCaseDestroySystem: DestroySystem<RobotCase>
         {
             protected override void Destroy(RobotCase self)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Map/RoomServerComponentSystem.cs

@@ -5,7 +5,7 @@ namespace ET.Server
     [FriendOf(typeof(RoomServerComponent))]
     public static class RoomServerComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class RoomServerComponentAwakeSystem: AwakeSystem<RoomServerComponent, Match2Map_GetRoom>
         {
             protected override void Awake(RoomServerComponent self, Match2Map_GetRoom match2MapGetRoom)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Match/MatchComponentSystem.cs

@@ -7,7 +7,7 @@ namespace ET.Server
     [FriendOf(typeof(MatchComponent))]
     public static class MatchComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class AwakeSystem: AwakeSystem<MatchComponent>
         {
             protected override void Awake(MatchComponent self)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Server/LockStep/Room/LSServerUpdaterSystem.cs

@@ -6,7 +6,7 @@ namespace ET.Server
     [FriendOf(typeof(LSServerUpdater))]
     public static class LSServerUpdaterSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class UpdateSystem: UpdateSystem<LSServerUpdater>
         {
             protected override void Update(LSServerUpdater self)

+ 28 - 14
Unity/Assets/Scripts/Hotfix/Server/Module/AOI/AOIEntitySystem.cs

@@ -4,35 +4,49 @@ using Unity.Mathematics;
 namespace ET.Server
 {
     [FriendOf(typeof(AOIEntity))]
-    [FriendOf(typeof(Cell))]
-    public static class AOIEntitySystem
+    public static class AOIEntitySystem2
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class AwakeSystem: AwakeSystem<AOIEntity, int, float3>
         {
             protected override void Awake(AOIEntity self, int distance, float3 pos)
             {
-                self.ViewDistance = distance;
-                self.DomainScene().GetComponent<AOIManagerComponent>().Add(self, pos.x, pos.z);
+                self.Awake(distance, pos);
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class DestroySystem: DestroySystem<AOIEntity>
         {
             protected override void Destroy(AOIEntity self)
             {
-                self.DomainScene().GetComponent<AOIManagerComponent>()?.Remove(self);
-                self.ViewDistance = 0;
-                self.SeeUnits.Clear();
-                self.SeePlayers.Clear();
-                self.BeSeePlayers.Clear();
-                self.BeSeeUnits.Clear();
-                self.SubEnterCells.Clear();
-                self.SubLeaveCells.Clear();
+                self.Destroy();
             }
         }
         
+        private static void Awake(this AOIEntity self, int distance, float3 pos)
+        {
+            self.ViewDistance = distance;
+            self.DomainScene().GetComponent<AOIManagerComponent>().Add(self, pos.x, pos.z);
+        }
+        
+        private static void Destroy(this AOIEntity self)
+        {
+            self.DomainScene().GetComponent<AOIManagerComponent>()?.Remove(self);
+            self.ViewDistance = 0;
+            self.SeeUnits.Clear();
+            self.SeePlayers.Clear();
+            self.BeSeePlayers.Clear();
+            self.BeSeeUnits.Clear();
+            self.SubEnterCells.Clear();
+            self.SubLeaveCells.Clear();
+        }
+    }
+    
+    [FriendOf(typeof(AOIEntity))]
+    [FriendOf(typeof(Cell))]
+    public static class AOIEntitySystem
+    {
         // 获取在自己视野中的对象
         public static Dictionary<long, AOIEntity> GetSeeUnits(this AOIEntity self)
         {

+ 10 - 5
Unity/Assets/Scripts/Hotfix/Server/Module/AOI/CellSystem.cs

@@ -6,17 +6,22 @@ namespace ET.Server
     [FriendOf(typeof(Cell))]
     public static class CellSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class CellDestroySystem: DestroySystem<Cell>
         {
             protected override void Destroy(Cell self)
             {
-                self.AOIUnits.Clear();
+                self.Destroy();
+            }
+        }
+        
+        private static void Destroy(this Cell self)
+        {
+            self.AOIUnits.Clear();
 
-                self.SubsEnterEntities.Clear();
+            self.SubsEnterEntities.Clear();
 
-                self.SubsLeaveEntities.Clear();
-            }
+            self.SubsLeaveEntities.Clear();
         }
         
         public static void Add(this Cell self, AOIEntity aoiEntity)

+ 11 - 6
Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageDispatcherComponentSystem.cs

@@ -9,17 +9,16 @@ namespace ET.Server
     [FriendOf(typeof(ActorMessageDispatcherComponent))]
     public static class ActorMessageDispatcherComponentHelper
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class ActorMessageDispatcherComponentAwakeSystem: AwakeSystem<ActorMessageDispatcherComponent>
         {
             protected override void Awake(ActorMessageDispatcherComponent self)
             {
-                ActorMessageDispatcherComponent.Instance = self;
                 self.Awake();
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class ActorMessageDispatcherComponentLoadSystem: LoadSystem<ActorMessageDispatcherComponent>
         {
             protected override void Load(ActorMessageDispatcherComponent self)
@@ -28,20 +27,26 @@ namespace ET.Server
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class ActorMessageDispatcherComponentDestroySystem: DestroySystem<ActorMessageDispatcherComponent>
         {
             protected override void Destroy(ActorMessageDispatcherComponent self)
             {
-                self.ActorMessageHandlers.Clear();
-                ActorMessageDispatcherComponent.Instance = null;
+                self.Destroy();
             }
         }
         
         private static void Awake(this ActorMessageDispatcherComponent self)
         {
+            ActorMessageDispatcherComponent.Instance = self;
             self.Load();
         }
+        
+        private static void Destroy(this ActorMessageDispatcherComponent self)
+        {
+            self.ActorMessageHandlers.Clear();
+            ActorMessageDispatcherComponent.Instance = null;
+        }
 
         private static void Load(this ActorMessageDispatcherComponent self)
         {

+ 19 - 9
Unity/Assets/Scripts/Hotfix/Server/Module/Actor/ActorMessageSenderComponentSystem.cs

@@ -22,28 +22,38 @@ namespace ET.Server
             }
         }
     
-        [ObjectSystem]
+        [EntitySystem]
         public class ActorMessageSenderComponentAwakeSystem: AwakeSystem<ActorMessageSenderComponent>
         {
             protected override void Awake(ActorMessageSenderComponent self)
             {
-                ActorMessageSenderComponent.Instance = self;
-
-                self.TimeoutCheckTimer = TimerComponent.Instance.NewRepeatedTimer(1000, TimerInvokeType.ActorMessageSenderChecker, self);
+                self.Awake();
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class ActorMessageSenderComponentDestroySystem: DestroySystem<ActorMessageSenderComponent>
         {
             protected override void Destroy(ActorMessageSenderComponent self)
             {
-                ActorMessageSenderComponent.Instance = null;
-                TimerComponent.Instance?.Remove(ref self.TimeoutCheckTimer);
-                self.TimeoutCheckTimer = 0;
-                self.TimeoutActorMessageSenders.Clear();
+                self.Destroy();
             }
         }
+        
+        private static void Awake(this ActorMessageSenderComponent self)
+        {
+            ActorMessageSenderComponent.Instance = self;
+
+            self.TimeoutCheckTimer = TimerComponent.Instance.NewRepeatedTimer(1000, TimerInvokeType.ActorMessageSenderChecker, self);
+        }
+        
+        private static void Destroy(this ActorMessageSenderComponent self)
+        {
+            ActorMessageSenderComponent.Instance = null;
+            TimerComponent.Instance?.Remove(ref self.TimeoutCheckTimer);
+            self.TimeoutCheckTimer = 0;
+            self.TimeoutActorMessageSenders.Clear();
+        }
 
         private static void Run(ActorMessageSender self, IActorResponse response)
         {

+ 29 - 13
Unity/Assets/Scripts/Hotfix/Server/Module/Actor/MailBoxComponentSystem.cs

@@ -2,32 +2,48 @@ using System;
 
 namespace ET.Server
 {
-    [ObjectSystem]
-    public class MailBoxComponentAwakeSystem: AwakeSystem<MailBoxComponent>
+    [FriendOf(typeof(MailBoxComponent))]
+    public static class MailBoxComponentSystem
     {
-        protected override void Awake(MailBoxComponent self)
+        public class MailBoxComponentAwakeSystem: AwakeSystem<MailBoxComponent>
+        {
+            protected override void Awake(MailBoxComponent self)
+            {
+                self.Awake();
+            }
+        }
+        
+        private static void Awake(this MailBoxComponent self)
         {
             self.MailboxType = MailboxType.MessageDispatcher;
             self.ParentInstanceId = self.Parent.InstanceId;
             ActorMessageDispatcherComponent.Instance.Add(self.Parent);
         }
-    }
 
-    [ObjectSystem]
-    public class MailBoxComponentAwake1System: AwakeSystem<MailBoxComponent, MailboxType>
-    {
-        protected override void Awake(MailBoxComponent self, MailboxType mailboxType)
+        public class MailBoxComponentAwake1System: AwakeSystem<MailBoxComponent, MailboxType>
+        {
+            protected override void Awake(MailBoxComponent self, MailboxType mailboxType)
+            {
+                self.Awake(mailboxType);
+            }
+        }
+        
+        private static void Awake(this MailBoxComponent self, MailboxType mailboxType)
         {
             self.MailboxType = mailboxType;
             self.ParentInstanceId = self.Parent.InstanceId;
             ActorMessageDispatcherComponent.Instance.Add(self.Parent);
         }
-    }
 
-    [ObjectSystem]
-    public class DestroySystem: DestroySystem<MailBoxComponent>
-    {
-        protected override void Destroy(MailBoxComponent self)
+        public class DestroySystem: DestroySystem<MailBoxComponent>
+        {
+            protected override void Destroy(MailBoxComponent self)
+            {
+                self.Destroy();
+            }
+        }
+        
+        private static void Destroy(this MailBoxComponent self)
         {
             ActorMessageDispatcherComponent.Instance?.Remove(self.ParentInstanceId);
         }

+ 27 - 14
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderComponentSystem.cs

@@ -24,26 +24,34 @@ namespace ET.Server
             }
         }
     
-        [ObjectSystem]
         public class AwakeSystem: AwakeSystem<ActorLocationSenderOneType, int>
         {
             protected override void Awake(ActorLocationSenderOneType self, int locationType)
             {
-                self.LocationType = locationType;
-                // 每10s扫描一次过期的actorproxy进行回收,过期时间是2分钟
-                // 可能由于bug或者进程挂掉,导致ActorLocationSender发送的消息没有确认,结果无法自动删除,每一分钟清理一次这种ActorLocationSender
-                self.CheckTimer = TimerComponent.Instance.NewRepeatedTimer(10 * 1000, TimerInvokeType.ActorLocationSenderChecker, self);
+                self.Awake(locationType);
             }
         }
 
-        [ObjectSystem]
         public class DestroySystem: DestroySystem<ActorLocationSenderOneType>
         {
             protected override void Destroy(ActorLocationSenderOneType self)
             {
-                TimerComponent.Instance?.Remove(ref self.CheckTimer);
+                self.Destroy();
             }
         }
+        
+        private static void Awake(this ActorLocationSenderOneType self, int locationType)
+        {
+            self.LocationType = locationType;
+            // 每10s扫描一次过期的actorproxy进行回收,过期时间是2分钟
+            // 可能由于bug或者进程挂掉,导致ActorLocationSender发送的消息没有确认,结果无法自动删除,每一分钟清理一次这种ActorLocationSender
+            self.CheckTimer = TimerComponent.Instance.NewRepeatedTimer(10 * 1000, TimerInvokeType.ActorLocationSenderChecker, self);
+        }
+        
+        private static void Destroy(this ActorLocationSenderOneType self)
+        {
+            TimerComponent.Instance?.Remove(ref self.CheckTimer);
+        }
 
         private static void Check(this ActorLocationSenderOneType self)
         {
@@ -287,20 +295,16 @@ namespace ET.Server
     [FriendOf(typeof (ActorLocationSenderComponent))]
     public static class ActorLocationSenderManagerComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class AwakeSystem: AwakeSystem<ActorLocationSenderComponent>
         {
             protected override void Awake(ActorLocationSenderComponent self)
             {
-                ActorLocationSenderComponent.Instance = self;
-                for (int i = 0; i < self.ActorLocationSenderComponents.Length; ++i)
-                {
-                    self.ActorLocationSenderComponents[i] = self.AddChild<ActorLocationSenderOneType, int>(i);
-                }
+                self.Awake();
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class DestroySystem: DestroySystem<ActorLocationSenderComponent>
         {
             protected override void Destroy(ActorLocationSenderComponent self)
@@ -309,6 +313,15 @@ namespace ET.Server
             }
         }
         
+        private static void Awake(this ActorLocationSenderComponent self)
+        {
+            ActorLocationSenderComponent.Instance = self;
+            for (int i = 0; i < self.ActorLocationSenderComponents.Length; ++i)
+            {
+                self.ActorLocationSenderComponents[i] = self.AddChild<ActorLocationSenderOneType, int>(i);
+            }
+        }
+        
         public static ActorLocationSenderOneType Get(this ActorLocationSenderComponent self, int locationType)
         {
             return self.ActorLocationSenderComponents[locationType];

+ 21 - 9
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/ActorLocationSenderSystem.cs

@@ -2,21 +2,33 @@ using System;
 
 namespace ET.Server
 {
-    [ObjectSystem]
-    public class ActorLocationSenderAwakeSystem: AwakeSystem<ActorLocationSender>
+    [FriendOf(typeof(ActorLocationSender))]
+    public static class ActorLocationSenderSystem
     {
-        protected override void Awake(ActorLocationSender self)
+        public class ActorLocationSenderAwakeSystem: AwakeSystem<ActorLocationSender>
+        {
+            protected override void Awake(ActorLocationSender self)
+            {
+                self.Awake();
+            }
+        }
+
+        public class ActorLocationSenderDestroySystem: DestroySystem<ActorLocationSender>
+        {
+            protected override void Destroy(ActorLocationSender self)
+            {
+                self.Destroy();
+            }
+        }
+        
+        private static void Awake(this ActorLocationSender self)
         {
             self.LastSendOrRecvTime = TimeHelper.ServerNow();
             self.ActorId = 0;
             self.Error = 0;
         }
-    }
-
-    [ObjectSystem]
-    public class ActorLocationSenderDestroySystem: DestroySystem<ActorLocationSender>
-    {
-        protected override void Destroy(ActorLocationSender self)
+        
+        private static void Destroy(this ActorLocationSender self)
         {
             Log.Debug($"actor location remove: {self.Id}");
             self.LastSendOrRecvTime = 0;

+ 39 - 16
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationOneTypeSystem.cs

@@ -2,39 +2,58 @@
 
 namespace ET.Server
 {
-    [ObjectSystem]
-    public class LockInfoAwakeSystem: AwakeSystem<LockInfo, long, CoroutineLock>
+    [FriendOf(typeof(LockInfo))]
+    public static class LockInfoSystem
     {
-        protected override void Awake(LockInfo self, long lockInstanceId, CoroutineLock coroutineLock)
+        public class LockInfoAwakeSystem: AwakeSystem<LockInfo, long, CoroutineLock>
+        {
+            protected override void Awake(LockInfo self, long lockInstanceId, CoroutineLock coroutineLock)
+            {
+                self.Awake(lockInstanceId, coroutineLock);
+            }
+        }
+    
+        public class LockInfoDestroySystem: DestroySystem<LockInfo>
+        {
+            protected override void Destroy(LockInfo self)
+            {
+                self.Destroy();
+            }
+        }
+        
+        private static void Awake(this LockInfo self, long lockInstanceId, CoroutineLock coroutineLock)
         {
             self.CoroutineLock = coroutineLock;
             self.LockInstanceId = lockInstanceId;
         }
-    }
-    
-    [ObjectSystem]
-    public class LockInfoDestroySystem: DestroySystem<LockInfo>
-    {
-        protected override void Destroy(LockInfo self)
+        
+        private static void Destroy(this LockInfo self)
         {
             self.CoroutineLock.Dispose();
             self.LockInstanceId = 0;
         }
     }
     
+
+    
     [FriendOf(typeof(LocationOneType))]
     [FriendOf(typeof(LockInfo))]
     public static class LocationOneTypeSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class LocationOneTypeAwakeSystem: AwakeSystem<LocationOneType, int>
         {
             protected override void Awake(LocationOneType self, int locationType)
             {
-                self.LocationType = locationType;
+                self.Awake(locationType);
             }
         }
         
+        private static void Awake(this LocationOneType self, int locationType)
+        {
+            self.LocationType = locationType;
+        }
+        
         public static async ETTask Add(this LocationOneType self, long key, long instanceId)
         {
             int coroutineLockType = (self.LocationType << 16) | CoroutineLockType.Location;
@@ -122,15 +141,19 @@ namespace ET.Server
     [FriendOf(typeof (LocationManagerComoponent))]
     public static class LocationComoponentSystem
     {
-        [ObjectSystem]
         public class AwakeSystem: AwakeSystem<LocationManagerComoponent>
         {
             protected override void Awake(LocationManagerComoponent self)
             {
-                for (int i = 0; i < self.LocationOneTypes.Length; ++i)
-                {
-                    self.LocationOneTypes[i] = self.AddChild<LocationOneType, int>(i);
-                }
+                self.Awake();
+            }
+        }
+        
+        private static void Awake(this LocationManagerComoponent self)
+        {
+            for (int i = 0; i < self.LocationOneTypes.Length; ++i)
+            {
+                self.LocationOneTypes[i] = self.AddChild<LocationOneType, int>(i);
             }
         }
         

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/ActorLocation/LocationProxyComponentSystem.cs

@@ -2,7 +2,7 @@
 
 namespace ET.Server
 {
-    [ObjectSystem]
+    [EntitySystem]
     public class LocationProxyComponentAwakeSystem: AwakeSystem<LocationProxyComponent>
     {
         protected override void Awake(LocationProxyComponent self)
@@ -11,7 +11,7 @@ namespace ET.Server
         }
     }
     
-    [ObjectSystem]
+    [EntitySystem]
     public class LocationProxyComponentDestroySystem: DestroySystem<LocationProxyComponent>
     {
         protected override void Destroy(LocationProxyComponent self)

+ 7 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/DB/DBComponentSystem.cs

@@ -12,10 +12,15 @@ namespace ET.Server
 	    {
 			protected override void Awake(DBComponent self, string dbConnection, string dbName, int zone)
 		    {
-			    self.mongoClient = new MongoClient(dbConnection);
-			    self.database = self.mongoClient.GetDatabase(dbName);
+			    self.Awake(dbConnection, dbName, zone);
 		    }
 	    }
+		
+		private static void Awake(this DBComponent self, string dbConnection, string dbName, int zone)
+		{
+			self.mongoClient = new MongoClient(dbConnection);
+			self.database = self.mongoClient.GetDatabase(dbName);
+		}
 
 	    private static IMongoCollection<T> GetCollection<T>(this DBComponent self, string collection = null)
 	    {

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/DB/DBManagerComponentSystem.cs

@@ -5,7 +5,7 @@ namespace ET.Server
     [FriendOf(typeof(DBManagerComponent))]
     public static class DBManagerComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class DBManagerComponentAwakeSystem: AwakeSystem<DBManagerComponent>
         {
             protected override void Awake(DBManagerComponent self)
@@ -14,7 +14,7 @@ namespace ET.Server
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class DBManagerComponentDestroySystem: DestroySystem<DBManagerComponent>
         {
             protected override void Destroy(DBManagerComponent self)

+ 32 - 22
Unity/Assets/Scripts/Hotfix/Server/Module/Http/HttpComponentSystem.cs

@@ -11,33 +11,38 @@ namespace ET.Server
         {
             protected override void Awake(HttpComponent self, string address)
             {
-                try
-                {
-                    self.Load();
+                self.Awake(address);
+            }
+        }
+        
+        private static void Awake(this HttpComponent self, string address)
+        {
+            try
+            {
+                self.Load();
                 
-                    self.Listener = new HttpListener();
+                self.Listener = new HttpListener();
 
-                    foreach (string s in address.Split(';'))
+                foreach (string s in address.Split(';'))
+                {
+                    if (s.Trim() == "")
                     {
-                        if (s.Trim() == "")
-                        {
-                            continue;
-                        }
-                        self.Listener.Prefixes.Add(s);
+                        continue;
                     }
+                    self.Listener.Prefixes.Add(s);
+                }
 
-                    self.Listener.Start();
+                self.Listener.Start();
 
-                    self.Accept().Coroutine();
-                }
-                catch (HttpListenerException e)
-                {
-                    throw new Exception($"请先在cmd中运行: netsh http add urlacl url=http://*:你的address中的端口/ user=Everyone, address: {address}", e);
-                }
+                self.Accept().Coroutine();
+            }
+            catch (HttpListenerException e)
+            {
+                throw new Exception($"请先在cmd中运行: netsh http add urlacl url=http://*:你的address中的端口/ user=Everyone, address: {address}", e);
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class HttpComponentLoadSystem: LoadSystem<HttpComponent>
         {
             protected override void Load(HttpComponent self)
@@ -46,17 +51,22 @@ namespace ET.Server
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class HttpComponentDestroySystem: DestroySystem<HttpComponent>
         {
             protected override void Destroy(HttpComponent self)
             {
-                self.Listener.Stop();
-                self.Listener.Close();
+                self.Destroy();
             }
         }
         
-        public static void Load(this HttpComponent self)
+        private static void Destroy(this HttpComponent self)
+        {
+            self.Listener.Stop();
+            self.Listener.Close();
+        }
+
+        private static void Load(this HttpComponent self)
         {
             self.dispatcher = new Dictionary<string, IHttpHandler>();
 

+ 50 - 35
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetInnerComponentSystem.cs

@@ -6,67 +6,82 @@ namespace ET.Server
     [FriendOf(typeof(NetInnerComponent))]
     public static class NetInnerComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class NetInnerComponentAwakeSystem: AwakeSystem<NetInnerComponent>
         {
             protected override void Awake(NetInnerComponent self)
             {
-                NetInnerComponent.Instance = self;
+                self.Awake();
+            }
+        }
+        
+        private static void Awake(this NetInnerComponent self)
+        {
+            NetInnerComponent.Instance = self;
             
-                switch (self.InnerProtocol)
+            switch (self.InnerProtocol)
+            {
+                case NetworkProtocol.TCP:
                 {
-                    case NetworkProtocol.TCP:
-                    {
-                        self.ServiceId = NetServices.Instance.AddService(new TService(AddressFamily.InterNetwork, ServiceType.Inner));
-                        break;
-                    }
-                    case NetworkProtocol.KCP:
-                    {
-                        self.ServiceId = NetServices.Instance.AddService(new KService(AddressFamily.InterNetwork, ServiceType.Inner));
-                        break;
-                    }
+                    self.ServiceId = NetServices.Instance.AddService(new TService(AddressFamily.InterNetwork, ServiceType.Inner));
+                    break;
+                }
+                case NetworkProtocol.KCP:
+                {
+                    self.ServiceId = NetServices.Instance.AddService(new KService(AddressFamily.InterNetwork, ServiceType.Inner));
+                    break;
                 }
-                
-                NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
-                NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
             }
+                
+            NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
+            NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class NetInnerComponentAwake1System: AwakeSystem<NetInnerComponent, IPEndPoint>
         {
             protected override void Awake(NetInnerComponent self, IPEndPoint address)
             {
-                NetInnerComponent.Instance = self;
+                self.Awake(address);
+            }
+        }
+        
+        private static void Awake(this NetInnerComponent self, IPEndPoint address)
+        {
+            NetInnerComponent.Instance = self;
                 
-                switch (self.InnerProtocol)
+            switch (self.InnerProtocol)
+            {
+                case NetworkProtocol.TCP:
                 {
-                    case NetworkProtocol.TCP:
-                    {
-                        self.ServiceId = NetServices.Instance.AddService(new TService(address, ServiceType.Inner));
-                        break;
-                    }
-                    case NetworkProtocol.KCP:
-                    {
-                        self.ServiceId = NetServices.Instance.AddService(new KService(address, ServiceType.Inner));
-                        break;
-                    }
+                    self.ServiceId = NetServices.Instance.AddService(new TService(address, ServiceType.Inner));
+                    break;
+                }
+                case NetworkProtocol.KCP:
+                {
+                    self.ServiceId = NetServices.Instance.AddService(new KService(address, ServiceType.Inner));
+                    break;
                 }
-                
-                NetServices.Instance.RegisterAcceptCallback(self.ServiceId, self.OnAccept);
-                NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
-                NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
             }
+                
+            NetServices.Instance.RegisterAcceptCallback(self.ServiceId, self.OnAccept);
+            NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
+            NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class NetInnerComponentDestroySystem: DestroySystem<NetInnerComponent>
         {
             protected override void Destroy(NetInnerComponent self)
             {
-                NetServices.Instance.RemoveService(self.ServiceId);
+                self.Destroy();
             }
         }
+        
+        private static void Destroy(this NetInnerComponent self)
+        {
+            NetServices.Instance.RemoveService(self.ServiceId);
+        }
 
         private static void OnRead(this NetInnerComponent self, long channelId, long actorId, object message)
         {

+ 17 - 7
Unity/Assets/Scripts/Hotfix/Server/Module/Message/NetServerComponentSystem.cs

@@ -5,26 +5,36 @@ namespace ET.Server
     [FriendOf(typeof(NetServerComponent))]
     public static class NetServerComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class AwakeSystem: AwakeSystem<NetServerComponent, IPEndPoint>
         {
             protected override void Awake(NetServerComponent self, IPEndPoint address)
             {
-                self.ServiceId = NetServices.Instance.AddService(new KService(address, ServiceType.Outer));
-                NetServices.Instance.RegisterAcceptCallback(self.ServiceId, self.OnAccept);
-                NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
-                NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
+                self.Awake(address);
             }
         }
+        
+        private static void Awake(this NetServerComponent self, IPEndPoint address)
+        {
+            self.ServiceId = NetServices.Instance.AddService(new KService(address, ServiceType.Outer));
+            NetServices.Instance.RegisterAcceptCallback(self.ServiceId, self.OnAccept);
+            NetServices.Instance.RegisterReadCallback(self.ServiceId, self.OnRead);
+            NetServices.Instance.RegisterErrorCallback(self.ServiceId, self.OnError);
+        }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class NetKcpComponentDestroySystem: DestroySystem<NetServerComponent>
         {
             protected override void Destroy(NetServerComponent self)
             {
-                NetServices.Instance.RemoveService(self.ServiceId);
+                self.Destroy();
             }
         }
+        
+        private static void Destroy(this NetServerComponent self)
+        {
+            NetServices.Instance.RemoveService(self.ServiceId);
+        }
 
         private static void OnError(this NetServerComponent self, long channelId, int error)
         {

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Server/Module/RobotCase/RobotCaseComponentSystem.cs

@@ -6,7 +6,7 @@ namespace ET.Server
     [FriendOf(typeof(RobotCaseComponent))]
     public static class RobotCaseComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class RobotCaseComponentAwakeSystem: AwakeSystem<RobotCaseComponent>
         {
             protected override void Awake(RobotCaseComponent self)
@@ -15,7 +15,7 @@ namespace ET.Server
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class RobotCaseComponentDestroySystem: DestroySystem<RobotCaseComponent>
         {
             protected override void Destroy(RobotCaseComponent self)

+ 48 - 33
Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterComponentSystem.cs

@@ -9,60 +9,75 @@ namespace ET.Server
     [FriendOf(typeof (RouterNode))]
     public static class RouterComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class RouterComponentAwakeSystem: AwakeSystem<RouterComponent, IPEndPoint, string>
         {
             protected override void Awake(RouterComponent self, IPEndPoint outerAddress, string innerIP)
             {
-                self.OuterSocket = new Socket(outerAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
-                self.OuterSocket.Bind(outerAddress);
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
-                {
-                    self.OuterSocket.SendBufferSize = 16 * Kcp.OneM;
-                    self.OuterSocket.ReceiveBufferSize = 16 * Kcp.OneM;
-                }
+                self.Awake(outerAddress, innerIP);
+            }
+        }
+        
+        private static void Awake(this RouterComponent self, IPEndPoint outerAddress, string innerIP)
+        {
+            self.OuterSocket = new Socket(outerAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
+            self.OuterSocket.Bind(outerAddress);
+            if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            {
+                self.OuterSocket.SendBufferSize = 16 * Kcp.OneM;
+                self.OuterSocket.ReceiveBufferSize = 16 * Kcp.OneM;
+            }
 
-                self.InnerSocket = new Socket(outerAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
-                self.InnerSocket.Bind(new IPEndPoint(IPAddress.Parse(innerIP), 0));
+            self.InnerSocket = new Socket(outerAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
+            self.InnerSocket.Bind(new IPEndPoint(IPAddress.Parse(innerIP), 0));
 
-                if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
-                {
-                    self.InnerSocket.SendBufferSize = 16 * Kcp.OneM;
-                    self.InnerSocket.ReceiveBufferSize = 16 * Kcp.OneM;
-                }
-                
-                NetworkHelper.SetSioUdpConnReset(self.OuterSocket);
-                NetworkHelper.SetSioUdpConnReset(self.InnerSocket);
+            if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
+            {
+                self.InnerSocket.SendBufferSize = 16 * Kcp.OneM;
+                self.InnerSocket.ReceiveBufferSize = 16 * Kcp.OneM;
             }
+                
+            NetworkHelper.SetSioUdpConnReset(self.OuterSocket);
+            NetworkHelper.SetSioUdpConnReset(self.InnerSocket);
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class RouterComponentDestroySystem: DestroySystem<RouterComponent>
         {
             protected override void Destroy(RouterComponent self)
             {
-                self.OuterSocket.Dispose();
-                self.InnerSocket.Dispose();
-                self.OuterNodes.Clear();
-                self.IPEndPoint = null;
+                self.Destroy();
             }
         }
+        
+        private static void Destroy(this RouterComponent self)
+        {
+            self.OuterSocket.Dispose();
+            self.InnerSocket.Dispose();
+            self.OuterNodes.Clear();
+            self.IPEndPoint = null;
+        }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class RouterComponentUpdateSystem: UpdateSystem<RouterComponent>
         {
             protected override void Update(RouterComponent self)
             {
-                long timeNow = TimeHelper.ClientNow();
-                self.RecvOuter(timeNow);
-                self.RecvInner(timeNow);
+                self.Update();
+            }
+        }
+        
+        private static void Update(this RouterComponent self)
+        {
+            long timeNow = TimeHelper.ClientNow();
+            self.RecvOuter(timeNow);
+            self.RecvInner(timeNow);
 
-                // 每秒钟检查一次
-                if (timeNow - self.LastCheckTime > 1000)
-                {
-                    self.CheckConnectTimeout(timeNow);
-                    self.LastCheckTime = timeNow;
-                }
+            // 每秒钟检查一次
+            if (timeNow - self.LastCheckTime > 1000)
+            {
+                self.CheckConnectTimeout(timeNow);
+                self.LastCheckTime = timeNow;
             }
         }
 

+ 29 - 19
Unity/Assets/Scripts/Hotfix/Server/Module/Router/RouterNodeSystem.cs

@@ -3,39 +3,49 @@
     [FriendOf(typeof(RouterNode))]
     public static class RouterNodeSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class RouterNodeAwakeSystem: AwakeSystem<RouterNode>
         {
             protected override void Awake(RouterNode self)
             {
-                long timeNow = TimeHelper.ServerNow();
-                self.LastRecvInnerTime = timeNow;
-                self.LastRecvOuterTime = timeNow;
-                self.OuterIpEndPoint = null;
-                self.InnerIpEndPoint = null;
-                self.RouterSyncCount = 0;
-                self.OuterConn = 0;
-                self.InnerConn = 0;
+                self.Awake();
             }
         }
+        
+        private static void Awake(this RouterNode self)
+        {
+            long timeNow = TimeHelper.ServerNow();
+            self.LastRecvInnerTime = timeNow;
+            self.LastRecvOuterTime = timeNow;
+            self.OuterIpEndPoint = null;
+            self.InnerIpEndPoint = null;
+            self.RouterSyncCount = 0;
+            self.OuterConn = 0;
+            self.InnerConn = 0;
+        }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class RouterNodeDestroySystem: DestroySystem<RouterNode>
         {
             protected override void Destroy(RouterNode self)
             {
-                self.OuterConn = 0;
-                self.InnerConn = 0;
-                self.LastRecvInnerTime = 0;
-                self.LastRecvOuterTime = 0;
-                self.OuterIpEndPoint = null;
-                self.InnerIpEndPoint = null;
-                self.InnerAddress = null;
-                self.RouterSyncCount = 0;
-                self.SyncCount = 0;
+                self.Destroy();
             }
         }
         
+        private static void Destroy(this RouterNode self)
+        {
+            self.OuterConn = 0;
+            self.InnerConn = 0;
+            self.LastRecvInnerTime = 0;
+            self.LastRecvOuterTime = 0;
+            self.OuterIpEndPoint = null;
+            self.InnerIpEndPoint = null;
+            self.InnerAddress = null;
+            self.RouterSyncCount = 0;
+            self.SyncCount = 0;
+        }
+        
         public static bool CheckOuterCount(this RouterNode self, long timeNow)
         {
             if (self.LastCheckTime == 0)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/LockStep/LSHelper.cs

@@ -12,7 +12,7 @@ namespace ET
                 return;
             }
             
-            LSSington.Instance.Rollback(entity);
+            LSEntitySystemSington.Instance.Rollback(entity);
             
             if (entity.ComponentsCount() > 0)
             {

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/LockStep/LSInputComponentSystem.cs

@@ -6,7 +6,7 @@ namespace ET
 {
     public static class LSInputComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class LSUpdateSystem: LSUpdateSystem<LSInputComponent>
         {
             protected override void LSUpdate(LSInputComponent self)

+ 18 - 8
Unity/Assets/Scripts/Hotfix/Share/Module/AI/AIComponentSystem.cs

@@ -22,28 +22,38 @@ namespace ET
             }
         }
     
-        [ObjectSystem]
+        [EntitySystem]
         public class AIComponentAwakeSystem: AwakeSystem<AIComponent, int>
         {
             protected override void Awake(AIComponent self, int aiConfigId)
             {
-                self.AIConfigId = aiConfigId;
-                self.Timer = TimerComponent.Instance.NewRepeatedTimer(1000, TimerInvokeType.AITimer, self);
+                self.Awake(aiConfigId);
             }
         }
+        
+        private static void Awake(this AIComponent self, int aiConfigId)
+        {
+            self.AIConfigId = aiConfigId;
+            self.Timer = TimerComponent.Instance.NewRepeatedTimer(1000, TimerInvokeType.AITimer, self);
+        }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class AIComponentDestroySystem: DestroySystem<AIComponent>
         {
             protected override void Destroy(AIComponent self)
             {
-                TimerComponent.Instance?.Remove(ref self.Timer);
-                self.CancellationToken?.Cancel();
-                self.CancellationToken = null;
-                self.Current = 0;
+                self.Destroy();
             }
         }
         
+        private static void Destroy(this AIComponent self)
+        {
+            TimerComponent.Instance?.Remove(ref self.Timer);
+            self.CancellationToken?.Cancel();
+            self.CancellationToken = null;
+            self.Current = 0;
+        }
+        
         public static void Check(this AIComponent self)
         {
             if (self.Parent == null)

+ 17 - 7
Unity/Assets/Scripts/Hotfix/Share/Module/AI/AIDispatcherComponentSystem.cs

@@ -5,17 +5,22 @@ namespace ET
     [FriendOf(typeof(AIDispatcherComponent))]
     public static class AIDispatcherComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class AIDispatcherComponentAwakeSystem: AwakeSystem<AIDispatcherComponent>
         {
             protected override void Awake(AIDispatcherComponent self)
             {
-                AIDispatcherComponent.Instance = self;
-                self.Load();
+                self.Awake();
             }
         }
+        
+        private static void Awake(this AIDispatcherComponent self)
+        {
+            AIDispatcherComponent.Instance = self;
+            self.Load();
+        }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class AIDispatcherComponentLoadSystem: LoadSystem<AIDispatcherComponent>
         {
             protected override void Load(AIDispatcherComponent self)
@@ -24,16 +29,21 @@ namespace ET
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class AIDispatcherComponentDestroySystem: DestroySystem<AIDispatcherComponent>
         {
             protected override void Destroy(AIDispatcherComponent self)
             {
-                self.AIHandlers.Clear();
-                AIDispatcherComponent.Instance = null;
+                self.Destroy();
             }
         }
         
+        private static void Destroy(this AIDispatcherComponent self)
+        {
+            self.AIHandlers.Clear();
+            AIDispatcherComponent.Instance = null;
+        }
+        
         private static void Load(this AIDispatcherComponent self)
         {
             self.AIHandlers.Clear();

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Share/Module/Console/ConsoleComponentSystem.cs

@@ -9,7 +9,7 @@ namespace ET
     [FriendOf(typeof(ModeContex))]
     public static class ConsoleComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class ConsoleComponentAwakeSystem: AwakeSystem<ConsoleComponent>
         {
             protected override void Awake(ConsoleComponent self)
@@ -20,7 +20,7 @@ namespace ET
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class ConsoleComponentLoadSystem: LoadSystem<ConsoleComponent>
         {
             protected override void Load(ConsoleComponent self)

+ 17 - 7
Unity/Assets/Scripts/Hotfix/Share/Module/Message/MessageDispatcherComponentSystem.cs

@@ -9,17 +9,16 @@ namespace ET
     [FriendOf(typeof(MessageDispatcherComponent))]
     public static class MessageDispatcherComponentHelper
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class MessageDispatcherComponentAwakeSystem: AwakeSystem<MessageDispatcherComponent>
         {
             protected override void Awake(MessageDispatcherComponent self)
             {
-                MessageDispatcherComponent.Instance = self;
-                self.Load();
+                self.Awake();
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class MessageDispatcherComponentLoadSystem: LoadSystem<MessageDispatcherComponent>
         {
             protected override void Load(MessageDispatcherComponent self)
@@ -28,15 +27,26 @@ namespace ET
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class MessageDispatcherComponentDestroySystem: DestroySystem<MessageDispatcherComponent>
         {
             protected override void Destroy(MessageDispatcherComponent self)
             {
-                MessageDispatcherComponent.Instance = null;
-                self.Handlers.Clear();
+                self.Destroy();
             }
         }
+        
+        private static void Awake(this MessageDispatcherComponent self)
+        {
+            MessageDispatcherComponent.Instance = self;
+            self.Load();
+        }
+        
+        private static void Destroy(this MessageDispatcherComponent self)
+        {
+            MessageDispatcherComponent.Instance = null;
+            self.Handlers.Clear();
+        }
 
         private static void Load(this MessageDispatcherComponent self)
         {

+ 35 - 18
Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionAcceptTimeoutComponentSystem.cs

@@ -2,37 +2,54 @@
 
 namespace ET
 {
-    [Invoke(TimerInvokeType.SessionAcceptTimeout)]
-    public class SessionAcceptTimeout: ATimer<SessionAcceptTimeoutComponent>
+    [FriendOf(typeof(SessionAcceptTimeoutComponent))]
+    public static class SessionAcceptTimeoutComponentHelper
     {
-        protected override void Run(SessionAcceptTimeoutComponent self)
+        [Invoke(TimerInvokeType.SessionAcceptTimeout)]
+        public class SessionAcceptTimeout: ATimer<SessionAcceptTimeoutComponent>
         {
-            try
+            protected override void Run(SessionAcceptTimeoutComponent self)
             {
-                self.Parent.Dispose();
+                try
+                {
+                    self.Parent.Dispose();
+                }
+                catch (Exception e)
+                {
+                    Log.Error($"move timer error: {self.Id}\n{e}");
+                }
             }
-            catch (Exception e)
+        }
+    
+        [EntitySystem]
+        public class SessionAcceptTimeoutComponentAwakeSystem: AwakeSystem<SessionAcceptTimeoutComponent>
+        {
+            protected override void Awake(SessionAcceptTimeoutComponent self)
             {
-                Log.Error($"move timer error: {self.Id}\n{e}");
+                self.Awake();
             }
         }
-    }
-    
-    [ObjectSystem]
-    public class SessionAcceptTimeoutComponentAwakeSystem: AwakeSystem<SessionAcceptTimeoutComponent>
-    {
-        protected override void Awake(SessionAcceptTimeoutComponent self)
+
+        [EntitySystem]
+        public class SessionAcceptTimeoutComponentDestroySystem: DestroySystem<SessionAcceptTimeoutComponent>
+        {
+            protected override void Destroy(SessionAcceptTimeoutComponent self)
+            {
+                self.Destroy();
+            }
+        }
+
+        private static void Awake(this SessionAcceptTimeoutComponent self)
         {
             self.Timer = TimerComponent.Instance.NewOnceTimer(TimeHelper.ServerNow() + 5000, TimerInvokeType.SessionAcceptTimeout, self);
         }
-    }
 
-    [ObjectSystem]
-    public class SessionAcceptTimeoutComponentDestroySystem: DestroySystem<SessionAcceptTimeoutComponent>
-    {
-        protected override void Destroy(SessionAcceptTimeoutComponent self)
+        private static void Destroy(this SessionAcceptTimeoutComponent self)
         {
             TimerComponent.Instance.Remove(ref self.Timer);
         }
+        
     }
+    
+    
 }

+ 36 - 25
Unity/Assets/Scripts/Hotfix/Share/Module/Message/SessionIdleCheckerComponentSystem.cs

@@ -2,45 +2,56 @@ using System;
 
 namespace ET
 {
-    [Invoke(TimerInvokeType.SessionIdleChecker)]
-    public class SessionIdleChecker: ATimer<SessionIdleCheckerComponent>
+    [FriendOf(typeof(SessionIdleCheckerComponent))]
+    public static class SessionIdleCheckerComponentSystem
     {
-        protected override void Run(SessionIdleCheckerComponent self)
+        [Invoke(TimerInvokeType.SessionIdleChecker)]
+        public class SessionIdleChecker: ATimer<SessionIdleCheckerComponent>
         {
-            try
+            protected override void Run(SessionIdleCheckerComponent self)
             {
-                self.Check();
+                try
+                {
+                    self.Check();
+                }
+                catch (Exception e)
+                {
+                    Log.Error($"move timer error: {self.Id}\n{e}");
+                }
             }
-            catch (Exception e)
+        }
+    
+        [EntitySystem]
+        public class SessionIdleCheckerComponentAwakeSystem: AwakeSystem<SessionIdleCheckerComponent>
+        {
+            protected override void Awake(SessionIdleCheckerComponent self)
             {
-                Log.Error($"move timer error: {self.Id}\n{e}");
+                self.Awake();
             }
         }
-    }
-    
-    [ObjectSystem]
-    public class SessionIdleCheckerComponentAwakeSystem: AwakeSystem<SessionIdleCheckerComponent>
-    {
-        protected override void Awake(SessionIdleCheckerComponent self)
+
+        [EntitySystem]
+        public class SessionIdleCheckerComponentDestroySystem: DestroySystem<SessionIdleCheckerComponent>
+        {
+            protected override void Destroy(SessionIdleCheckerComponent self)
+            {
+                self.Destroy();
+            }
+        }
+        
+        private static void Awake(this SessionIdleCheckerComponent self)
         {
             self.RepeatedTimer = TimerComponent.Instance.NewRepeatedTimer(SessionIdleCheckerComponentSystem.CheckInteral, TimerInvokeType.SessionIdleChecker, self);
         }
-    }
-
-    [ObjectSystem]
-    public class SessionIdleCheckerComponentDestroySystem: DestroySystem<SessionIdleCheckerComponent>
-    {
-        protected override void Destroy(SessionIdleCheckerComponent self)
+        
+        private static void Destroy(this SessionIdleCheckerComponent self)
         {
             TimerComponent.Instance?.Remove(ref self.RepeatedTimer);
         }
-    }
-
-    public static class SessionIdleCheckerComponentSystem
-    {
-        public const int CheckInteral = 2000;
         
-        public static void Check(this SessionIdleCheckerComponent self)
+        public const int CheckInteral = 2000;
+
+        private static void Check(this SessionIdleCheckerComponent self)
         {
             Session session = self.GetParent<Session>();
             long timeNow = TimeHelper.ClientNow();

+ 22 - 12
Unity/Assets/Scripts/Hotfix/Share/Module/Move/MoveComponentSystem.cs

@@ -23,32 +23,42 @@ namespace ET
             }
         }
     
-        [ObjectSystem]
+        [EntitySystem]
         public class DestroySystem: DestroySystem<MoveComponent>
         {
             protected override void Destroy(MoveComponent self)
             {
-                self.MoveFinish(false);
+                self.Destroy();
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class AwakeSystem: AwakeSystem<MoveComponent>
         {
             protected override void Awake(MoveComponent self)
             {
-                self.StartTime = 0;
-                self.StartPos = float3.zero;
-                self.NeedTime = 0;
-                self.MoveTimer = 0;
-                self.tcs = null;
-                self.Targets.Clear();
-                self.Speed = 0;
-                self.N = 0;
-                self.TurnTime = 0;
+                self.Awake();
             }
         }
         
+        private static void Destroy(this MoveComponent self)
+        {
+            self.MoveFinish(false);
+        }
+        
+        private static void Awake(this MoveComponent self)
+        {
+            self.StartTime = 0;
+            self.StartPos = float3.zero;
+            self.NeedTime = 0;
+            self.MoveTimer = 0;
+            self.tcs = null;
+            self.Targets.Clear();
+            self.Speed = 0;
+            self.N = 0;
+            self.TurnTime = 0;
+        }
+        
         public static bool IsArrived(this MoveComponent self)
         {
             return self.Targets.Count == 0;

+ 20 - 10
Unity/Assets/Scripts/Hotfix/Share/Module/Recast/PathfindingComponentSystem.cs

@@ -7,31 +7,41 @@ namespace ET
     [FriendOf(typeof(PathfindingComponent))]
     public static class PathfindingComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class AwakeSystem: AwakeSystem<PathfindingComponent, string>
         {
             protected override void Awake(PathfindingComponent self, string name)
             {
-                self.Name = name;
-                self.NavMesh = NavmeshComponent.Instance.Get(name);
+                self.Awake(name);
+            }
+        }
+        
+        private static void Awake(this PathfindingComponent self, string name)
+        {
+            self.Name = name;
+            self.NavMesh = NavmeshComponent.Instance.Get(name);
 
-                if (self.NavMesh == 0)
-                {
-                    throw new Exception($"nav load fail: {name}");
-                }
+            if (self.NavMesh == 0)
+            {
+                throw new Exception($"nav load fail: {name}");
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class DestroySystem: DestroySystem<PathfindingComponent>
         {
             protected override void Destroy(PathfindingComponent self)
             {
-                self.Name = string.Empty;
-                self.NavMesh = 0;
+                self.Destroy();
             }
         }
         
+        private static void Destroy(this PathfindingComponent self)
+        {
+            self.Name = string.Empty;
+            self.NavMesh = 0;
+        }
+        
         public static void Find(this PathfindingComponent self, float3 start, float3 target, List<float3> result)
         {
             if (self.NavMesh == 0)

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Share/Module/Scene/ClientSceneManagerComponentSystem.cs

@@ -3,7 +3,7 @@
     [FriendOf(typeof(ClientSceneManagerComponent))]
     public static class ClientSceneManagerComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class ClientSceneManagerComponentAwakeSystem: AwakeSystem<ClientSceneManagerComponent>
         {
             protected override void Awake(ClientSceneManagerComponent self)
@@ -12,7 +12,7 @@
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class ClientSceneManagerComponentDestroySystem: DestroySystem<ClientSceneManagerComponent>
         {
             protected override void Destroy(ClientSceneManagerComponent self)

+ 2 - 2
Unity/Assets/Scripts/Hotfix/Share/Module/Scene/ServerSceneManagerComponentSystem.cs

@@ -3,7 +3,7 @@
     [FriendOf(typeof(ServerSceneManagerComponent))]
     public static class ServerSceneManagerComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class ServerSceneManagerComponentAwakeSystem: AwakeSystem<ServerSceneManagerComponent>
         {
             protected override void Awake(ServerSceneManagerComponent self)
@@ -12,7 +12,7 @@
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class ServerSceneManagerComponentDestroySystem: DestroySystem<ServerSceneManagerComponent>
         {
             protected override void Destroy(ServerSceneManagerComponent self)

+ 0 - 16
Unity/Assets/Scripts/Hotfix/Share/Module/Unit/UnitComponentSystem.cs

@@ -1,21 +1,5 @@
 namespace ET
 {
-	[ObjectSystem]
-	public class UnitComponentAwakeSystem : AwakeSystem<UnitComponent>
-	{
-		protected override void Awake(UnitComponent self)
-		{
-		}
-	}
-	
-	[ObjectSystem]
-	public class UnitComponentDestroySystem : DestroySystem<UnitComponent>
-	{
-		protected override void Destroy(UnitComponent self)
-		{
-		}
-	}
-	
 	public static class UnitComponentSystem
 	{
 		public static void Add(this UnitComponent self, Unit unit)

+ 1 - 1
Unity/Assets/Scripts/Hotfix/Share/Module/Unit/UnitSystem.cs

@@ -1,6 +1,6 @@
 namespace ET
 {
-    [ObjectSystem]
+    [EntitySystem]
     public class UnitSystem: AwakeSystem<Unit, int>
     {
         protected override void Awake(Unit self, int configId)

+ 3 - 3
Unity/Assets/Scripts/HotfixView/Client/Demo/Opera/OperaComponentSystem.cs

@@ -6,7 +6,7 @@ namespace ET.Client
     [FriendOf(typeof(OperaComponent))]
     public static class OperaComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class OperaComponentAwakeSystem : AwakeSystem<OperaComponent>
         {
             protected override void Awake(OperaComponent self)
@@ -15,7 +15,7 @@ namespace ET.Client
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class OperaComponentUpdateSystem : UpdateSystem<OperaComponent>
         {
             protected override void Update(OperaComponent self)
@@ -34,7 +34,7 @@ namespace ET.Client
 
                 if (Input.GetKeyDown(KeyCode.R))
                 {
-                    EventSystem.Instance.Load();
+                    Game.Load();
                     Log.Debug("hot reload success!");
                 }
             

+ 1 - 1
Unity/Assets/Scripts/HotfixView/Client/Demo/UI/UILobby/UILobbyComponentSystem.cs

@@ -6,7 +6,7 @@ namespace ET.Client
     [FriendOf(typeof(UILobbyComponent))]
     public static class UILobbyComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class UILobbyComponentAwakeSystem: AwakeSystem<UILobbyComponent>
         {
             protected override void Awake(UILobbyComponent self)

+ 1 - 1
Unity/Assets/Scripts/HotfixView/Client/Demo/UI/UILogin/UILoginComponentSystem.cs

@@ -6,7 +6,7 @@ namespace ET.Client
 	[FriendOf(typeof(UILoginComponent))]
 	public static class UILoginComponentSystem
 	{
-		[ObjectSystem]
+		[EntitySystem]
 		public class UILoginComponentAwakeSystem : AwakeSystem<UILoginComponent>
 		{
 			protected override void Awake(UILoginComponent self)

+ 3 - 3
Unity/Assets/Scripts/HotfixView/Client/Demo/Unit/AnimatorComponentSystem.cs

@@ -6,7 +6,7 @@ namespace ET.Client
 	[FriendOf(typeof(AnimatorComponent))]
 	public static class AnimatorComponentSystem
 	{
-		[ObjectSystem]
+		[EntitySystem]
 		public class AwakeSystem : AwakeSystem<AnimatorComponent>
 		{
 			protected override void Awake(AnimatorComponent self)
@@ -15,7 +15,7 @@ namespace ET.Client
 			}
 		}
 
-		[ObjectSystem]
+		[EntitySystem]
 		public class UpdateSystem : UpdateSystem<AnimatorComponent>
 		{
 			protected override void Update(AnimatorComponent self)
@@ -24,7 +24,7 @@ namespace ET.Client
 			}
 		}
 	
-		[ObjectSystem]
+		[EntitySystem]
 		public class DestroySystem : DestroySystem<AnimatorComponent>
 		{
 			protected override void Destroy(AnimatorComponent self)

+ 1 - 1
Unity/Assets/Scripts/HotfixView/Client/Demo/Unit/GameObjectComponentSystem.cs

@@ -4,7 +4,7 @@ namespace ET.Client
 {
     public static class GameObjectComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class DestroySystem: DestroySystem<GameObjectComponent>
         {
             protected override void Destroy(GameObjectComponent self)

+ 2 - 2
Unity/Assets/Scripts/HotfixView/Client/LockStep/Camera/LSCameraComponentSystem.cs

@@ -5,7 +5,7 @@ namespace ET.Client
 	[FriendOf(typeof(LSCameraComponent))]
 	public static class LSCameraComponentSystem
 	{
-		[ObjectSystem]
+		[EntitySystem]
 		public class AwakeSystem : AwakeSystem<LSCameraComponent>
 		{
 			protected override void Awake(LSCameraComponent self)
@@ -14,7 +14,7 @@ namespace ET.Client
 			}
 		}
 
-		[ObjectSystem]
+		[EntitySystem]
 		public class LateUpdateSystem : LateUpdateSystem<LSCameraComponent>
 		{
 			protected override void LateUpdate(LSCameraComponent self)

+ 3 - 3
Unity/Assets/Scripts/HotfixView/Client/LockStep/LSAnimatorComponentSystem.cs

@@ -6,7 +6,7 @@ namespace ET.Client
 	[FriendOf(typeof(LSAnimatorComponent))]
 	public static class LSAnimatorComponentSystem
 	{
-		[ObjectSystem]
+		[EntitySystem]
 		public class AwakeSystem : AwakeSystem<LSAnimatorComponent>
 		{
 			protected override void Awake(LSAnimatorComponent self)
@@ -15,7 +15,7 @@ namespace ET.Client
 			}
 		}
 
-		[ObjectSystem]
+		[EntitySystem]
 		public class UpdateSystem : UpdateSystem<LSAnimatorComponent>
 		{
 			protected override void Update(LSAnimatorComponent self)
@@ -24,7 +24,7 @@ namespace ET.Client
 			}
 		}
 	
-		[ObjectSystem]
+		[EntitySystem]
 		public class DestroySystem : DestroySystem<LSAnimatorComponent>
 		{
 			protected override void Destroy(LSAnimatorComponent self)

+ 1 - 1
Unity/Assets/Scripts/HotfixView/Client/LockStep/UI/UILSLobby/UILSLobbyComponentSystem.cs

@@ -7,7 +7,7 @@ namespace ET.Client
     [FriendOf(typeof(UILSLobbyComponent))]
     public static class UILSLobbyComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class UILSLobbyComponentAwakeSystem: AwakeSystem<UILSLobbyComponent>
         {
             protected override void Awake(UILSLobbyComponent self)

+ 1 - 1
Unity/Assets/Scripts/HotfixView/Client/LockStep/UI/UILSLogin/UILoginComponentSystem.cs

@@ -6,7 +6,7 @@ namespace ET.Client
 	[FriendOf(typeof(UILoginComponent))]
 	public static class UILSLoginComponentSystem
 	{
-		[ObjectSystem]
+		[EntitySystem]
 		public class UILSLoginComponentAwakeSystem : AwakeSystem<UILSLoginComponent>
 		{
 			protected override void Awake(UILSLoginComponent self)

+ 1 - 1
Unity/Assets/Scripts/HotfixView/Client/Module/UI/UIEventComponentSystem.cs

@@ -10,7 +10,7 @@ namespace ET.Client
 	[FriendOf(typeof(UIEventComponent))]
 	public static class UIEventComponentSystem
 	{
-		[ObjectSystem]
+		[EntitySystem]
 		public class UIEventComponentAwakeSystem : AwakeSystem<UIEventComponent>
 		{
 			protected override void Awake(UIEventComponent self)

+ 4 - 1
Unity/Assets/Scripts/Model/Share/Entry.cs

@@ -36,10 +36,13 @@ namespace ET
             
             MongoHelper.RegisterStruct<LSInput>();
             MongoHelper.Register();
+            
+            Game.AddSingleton<EntitySystemSingleton>();
+            Game.AddSingleton<LSEntitySystemSington>();
 
             Game.AddSingleton<NetServices>();
             Game.AddSingleton<Root>();
-            Game.AddSingleton<LSSington>();
+
             
             await Game.AddSingleton<ConfigComponent>().LoadAsync();
 

+ 1 - 1
Unity/Assets/Scripts/Model/Share/LockStep/ILSUpdateSystem.cs

@@ -11,7 +11,7 @@ namespace ET
         void Run(LSEntity o);
     }
     
-    [LSSystem]
+    [LSEntitySystem]
     public abstract class LSUpdateSystem<T> : ILSUpdateSystem where T: LSEntity, ILSUpdate
     {
         void ILSUpdateSystem.Run(LSEntity o)

+ 1 - 1
Unity/Assets/Scripts/Model/Share/LockStep/IRollbackSystem.cs

@@ -12,7 +12,7 @@ namespace ET
         void Run(Entity o);
     }
     
-    [LSSystem]
+    [LSEntitySystem]
     public abstract class RollbackSystem<T> : IRollbackSystem where T: Entity, IRollback
     {
         void IRollbackSystem.Run(Entity o)

+ 1 - 1
Unity/Assets/Scripts/Model/Share/LockStep/LSEntity.cs

@@ -48,7 +48,7 @@ namespace ET
         protected override void RegisterSystem()
         {
             LSWorld lsWorld = this.LSWorld();
-            TypeSystems.OneTypeSystems oneTypeSystems = LSSington.Instance.GetOneTypeSystems(this.GetType());
+            TypeSystems.OneTypeSystems oneTypeSystems = LSEntitySystemSington.Instance.GetOneTypeSystems(this.GetType());
             if (oneTypeSystems == null)
             {
                 return;

+ 1 - 1
Unity/Assets/Scripts/Model/Share/LockStep/LSSystemAttribute.cs → Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemAttribute.cs

@@ -3,7 +3,7 @@ using System;
 namespace ET
 {
     [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
-    public class LSSystemAttribute: BaseAttribute
+    public class LSEntitySystemAttribute: SystemAttribute
     {
     }
 }

+ 11 - 0
Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemAttribute.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 83785c2329d8c4847b6fab0468c7f4d4
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 9 - 3
Unity/Assets/Scripts/Model/Share/LockStep/LSSington.cs → Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemSington.cs

@@ -11,13 +11,19 @@ namespace ET
         public const int Max = 1;
     }
     
-    public class LSSington: Singleton<LSSington>, ISingletonAwake
+    public class LSEntitySystemSington: Singleton<LSEntitySystemSington>, ISingletonAwake, ISingletonLoad
     {
-        private readonly TypeSystems typeSystems = new(LSQueneUpdateIndex.Max);
+        private TypeSystems typeSystems;
         
         public void Awake()
         {
-            foreach (Type type in EventSystem.Instance.GetTypes(typeof (LSSystemAttribute)))
+            this.Load();
+        }
+        
+        public void Load()
+        {
+            this.typeSystems = new(LSQueneUpdateIndex.Max);
+            foreach (Type type in EventSystem.Instance.GetTypes(typeof (LSEntitySystemAttribute)))
             {
                 object obj = Activator.CreateInstance(type);
 

+ 11 - 0
Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemSington.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 60b58200b36214d73abf951137a237bb
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Assets/Scripts/Model/Share/LockStep/LSUpdater.cs

@@ -31,7 +31,7 @@ namespace ET
                     continue;
                 }
                 this.newUpdateIds.Add(id);
-                LSSington.Instance.LSUpdate(entity);
+                LSEntitySystemSington.Instance.LSUpdate(entity);
             }
             this.updateIds.Clear();
             ObjectHelper.Swap(ref this.updateIds, ref this.newUpdateIds);

+ 25 - 9
Unity/Assets/Scripts/Model/Share/Module/Console/ModeContex.cs

@@ -1,22 +1,38 @@
 namespace ET
 {
-    [ObjectSystem]
-    public class ModeContexAwakeSystem: AwakeSystem<ModeContex>
+    [FriendOf(typeof(ModeContex))]
+    public static class ModeContexSystem
     {
-        protected override void Awake(ModeContex self)
+        [EntitySystem]
+        public class ModeContexAwakeSystem: AwakeSystem<ModeContex>
         {
-            self.Mode = "";
+            protected override void Awake(ModeContex self)
+            {
+                self.Awake();
+            }
         }
-    }
 
-    [ObjectSystem]
-    public class ModeContexDestroySystem: DestroySystem<ModeContex>
-    {
-        protected override void Destroy(ModeContex self)
+        [EntitySystem]
+        public class ModeContexDestroySystem: DestroySystem<ModeContex>
+        {
+            protected override void Destroy(ModeContex self)
+            {
+                self.Destroy();
+            }
+        }
+
+        private static void Awake(this ModeContex self)
+        {
+            self.Mode = "";
+        }
+        
+        private static void Destroy(this ModeContex self)
         {
             self.Mode = "";
         }
     }
+    
+
 
     [ComponentOf(typeof(ConsoleComponent))]
     public class ModeContex: Entity, IAwake, IDestroy

+ 54 - 47
Unity/Assets/Scripts/Model/Share/Module/Message/OpcodeTypeComponent.cs

@@ -1,73 +1,79 @@
 using System;
 using System.Collections.Generic;
+using MongoDB.Driver.Core.Events;
 
 namespace ET
 {
-    [FriendOf(typeof(OpcodeTypeComponent))]
+    [FriendOf(typeof (OpcodeTypeComponent))]
     public static class OpcodeTypeComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class OpcodeTypeComponentAwakeSystem: AwakeSystem<OpcodeTypeComponent>
         {
             protected override void Awake(OpcodeTypeComponent self)
             {
                 OpcodeTypeComponent.Instance = self;
-                
-                self.requestResponse.Clear();
+                self.Awake();
+            }
+        }
+
+        [EntitySystem]
+        public class OpcodeTypeComponentDestroySystem: DestroySystem<OpcodeTypeComponent>
+        {
+            protected override void Destroy(OpcodeTypeComponent self)
+            {
+                OpcodeTypeComponent.Instance = null;
+            }
+        }
+
+        private static void Awake(this OpcodeTypeComponent self)
+        {
+            self.requestResponse.Clear();
+
+            HashSet<Type> types = EventSystem.Instance.GetTypes(typeof (MessageAttribute));
+            foreach (Type type in types)
+            {
+                object[] att = type.GetCustomAttributes(typeof (MessageAttribute), false);
+                if (att.Length == 0)
+                {
+                    continue;
+                }
+
+                MessageAttribute messageAttribute = att[0] as MessageAttribute;
+                if (messageAttribute == null)
+                {
+                    continue;
+                }
 
-                HashSet<Type> types = EventSystem.Instance.GetTypes(typeof (MessageAttribute));
-                foreach (Type type in types)
+                ushort opcode = messageAttribute.Opcode;
+
+                if (OpcodeHelper.IsOuterMessage(opcode) && typeof (IActorMessage).IsAssignableFrom(type))
                 {
-                    object[] att = type.GetCustomAttributes(typeof (MessageAttribute), false);
-                    if (att.Length == 0)
+                    self.outrActorMessage.Add(opcode);
+                }
+
+                // 检查request response
+                if (typeof (IRequest).IsAssignableFrom(type))
+                {
+                    if (typeof (IActorLocationMessage).IsAssignableFrom(type))
                     {
+                        self.requestResponse.Add(type, typeof (ActorResponse));
                         continue;
                     }
 
-                    MessageAttribute messageAttribute = att[0] as MessageAttribute;
-                    if (messageAttribute == null)
+                    var attrs = type.GetCustomAttributes(typeof (ResponseTypeAttribute), false);
+                    if (attrs.Length == 0)
                     {
+                        Log.Error($"not found responseType: {type}");
                         continue;
                     }
-                    ushort opcode = messageAttribute.Opcode;
 
-                    if (OpcodeHelper.IsOuterMessage(opcode) && typeof (IActorMessage).IsAssignableFrom(type))
-                    {
-                        self.outrActorMessage.Add(opcode);
-                    }
-                
-                    // 检查request response
-                    if (typeof (IRequest).IsAssignableFrom(type))
-                    {
-                        if (typeof (IActorLocationMessage).IsAssignableFrom(type))
-                        {
-                            self.requestResponse.Add(type, typeof(ActorResponse));
-                            continue;
-                        }
-                    
-                        var attrs = type.GetCustomAttributes(typeof (ResponseTypeAttribute), false);
-                        if (attrs.Length == 0)
-                        {
-                            Log.Error($"not found responseType: {type}");
-                            continue;
-                        }
-
-                        ResponseTypeAttribute responseTypeAttribute = attrs[0] as ResponseTypeAttribute;
-                        self.requestResponse.Add(type, EventSystem.Instance.GetType($"ET.{responseTypeAttribute.Type}"));
-                    }
+                    ResponseTypeAttribute responseTypeAttribute = attrs[0] as ResponseTypeAttribute;
+                    self.requestResponse.Add(type, EventSystem.Instance.GetType($"ET.{responseTypeAttribute.Type}"));
                 }
             }
         }
 
-        [ObjectSystem]
-        public class OpcodeTypeComponentDestroySystem: DestroySystem<OpcodeTypeComponent>
-        {
-            protected override void Destroy(OpcodeTypeComponent self)
-            {
-                OpcodeTypeComponent.Instance = null;
-            }
-        }
-
         public static bool IsOutrActorMessage(this OpcodeTypeComponent self, ushort opcode)
         {
             return self.outrActorMessage.Contains(opcode);
@@ -79,18 +85,19 @@ namespace ET
             {
                 throw new Exception($"not found response type, request type: {request.GetType().FullName}");
             }
+
             return response;
         }
     }
 
-    [ComponentOf(typeof(Scene))]
+    [ComponentOf(typeof (Scene))]
     public class OpcodeTypeComponent: Entity, IAwake, IDestroy
     {
         [StaticField]
         public static OpcodeTypeComponent Instance;
-        
+
         public HashSet<ushort> outrActorMessage = new HashSet<ushort>();
-        
+
         public readonly Dictionary<Type, Type> requestResponse = new Dictionary<Type, Type>();
     }
 }

+ 27 - 17
Unity/Assets/Scripts/Model/Share/Module/Message/Session.cs

@@ -21,38 +21,48 @@ namespace ET
     [FriendOf(typeof(Session))]
     public static class SessionSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class SessionAwakeSystem: AwakeSystem<Session, int>
         {
             protected override void Awake(Session self, int serviceId)
             {
-                self.ServiceId = serviceId;
-                long timeNow = TimeHelper.ClientNow();
-                self.LastRecvTime = timeNow;
-                self.LastSendTime = timeNow;
+                self.Awake(serviceId);
+            }
+        }
+        
+        private static void Awake(this Session self, int serviceId)
+        {
+            self.ServiceId = serviceId;
+            long timeNow = TimeHelper.ClientNow();
+            self.LastRecvTime = timeNow;
+            self.LastSendTime = timeNow;
 
-                self.requestCallbacks.Clear();
+            self.requestCallbacks.Clear();
             
-                Log.Info($"session create: zone: {self.DomainZone()} id: {self.Id} {timeNow} ");
-            }
+            Log.Info($"session create: zone: {self.DomainZone()} id: {self.Id} {timeNow} ");
         }
         
-        [ObjectSystem]
+        [EntitySystem]
         public class SessionDestroySystem: DestroySystem<Session>
         {
             protected override void Destroy(Session self)
             {
-                NetServices.Instance.RemoveChannel(self.ServiceId, self.Id, self.Error);
+                self.Destroy();
+            }
+        }
+        
+        private static void Destroy(this Session self)
+        {
+            NetServices.Instance.RemoveChannel(self.ServiceId, self.Id, self.Error);
             
-                foreach (RpcInfo responseCallback in self.requestCallbacks.Values.ToArray())
-                {
-                    responseCallback.Tcs.SetException(new RpcException(self.Error, $"session dispose: {self.Id} {self.RemoteAddress}"));
-                }
+            foreach (RpcInfo responseCallback in self.requestCallbacks.Values.ToArray())
+            {
+                responseCallback.Tcs.SetException(new RpcException(self.Error, $"session dispose: {self.Id} {self.RemoteAddress}"));
+            }
 
-                Log.Info($"session dispose: {self.RemoteAddress} id: {self.Id} ErrorCode: {self.Error}, please see ErrorCode.cs! {TimeHelper.ClientNow()}");
+            Log.Info($"session dispose: {self.RemoteAddress} id: {self.Id} ErrorCode: {self.Error}, please see ErrorCode.cs! {TimeHelper.ClientNow()}");
             
-                self.requestCallbacks.Clear();
-            }
+            self.requestCallbacks.Clear();
         }
         
         public static void OnResponse(this Session self, IResponse response)

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Numeric/NumericWatcherComponent.cs

@@ -6,7 +6,7 @@ namespace ET
     [FriendOf(typeof(NumericWatcherComponent))]
     public static class NumericWatcherComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class NumericWatcherComponentAwakeSystem : AwakeSystem<NumericWatcherComponent>
         {
             protected override void Awake(NumericWatcherComponent self)

+ 17 - 7
Unity/Assets/Scripts/Model/Share/Module/ObjectWait/ObjectWait.cs

@@ -24,24 +24,34 @@ namespace ET
     [FriendOf(typeof(ObjectWait))]
     public static class ObjectWaitSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class ObjectWaitAwakeSystem: AwakeSystem<ObjectWait>
         {
             protected override void Awake(ObjectWait self)
             {
-                self.tcss.Clear();
+                self.Awake();
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class ObjectWaitDestroySystem: DestroySystem<ObjectWait>
         {
             protected override void Destroy(ObjectWait self)
             {
-                foreach (object v in self.tcss.Values.ToArray())
-                {
-                    ((IDestroyRun) v).SetResult();
-                }
+                self.Destroy();
+            }
+        }
+        
+        private static void Awake(this ObjectWait self)
+        {
+            self.tcss.Clear();
+        }
+        
+        private static void Destroy(this ObjectWait self)
+        {
+            foreach (object v in self.tcss.Values.ToArray())
+            {
+                ((IDestroyRun) v).SetResult();
             }
         }
 

+ 4 - 4
Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesComponent.cs

@@ -10,7 +10,7 @@ namespace ET.Client
     [FriendOf(typeof(ABInfo))]
     public static class ABInfoSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class ABInfoAwakeSystem: AwakeSystem<ABInfo, string, AssetBundle>
         {
             protected override void Awake(ABInfo self, string abName, AssetBundle a)
@@ -22,7 +22,7 @@ namespace ET.Client
             }
         }
 
-        [ObjectSystem]
+        [EntitySystem]
         public class ABInfoDestroySystem: DestroySystem<ABInfo>
         {
             protected override void Destroy(ABInfo self)
@@ -114,7 +114,7 @@ namespace ET.Client
     [FriendOf(typeof(ResourcesComponent))]
     public static class ResourcesComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class ResourcesComponentAwakeSystem: AwakeSystem<ResourcesComponent>
         {
             protected override void Awake(ResourcesComponent self)
@@ -129,7 +129,7 @@ namespace ET.Client
             }
         }
         
-        [ObjectSystem]
+        [EntitySystem]
         public class ResourcesComponentDestroySystem: DestroySystem<ResourcesComponent>
         {
             protected override void Destroy(ResourcesComponent self)

+ 1 - 1
Unity/Assets/Scripts/ModelView/Client/Module/Resource/ResourcesLoaderComponent.cs

@@ -5,7 +5,7 @@ namespace ET.Client
     [FriendOf(typeof(ResourcesLoaderComponent))]
     public static class ResourcesLoaderComponentSystem
     {
-        [ObjectSystem]
+        [EntitySystem]
             public class ResourcesLoaderComponentDestroySystem: DestroySystem<ResourcesLoaderComponent>
             {
                 protected override void Destroy(ResourcesLoaderComponent self)

+ 2 - 2
Unity/Assets/Scripts/ModelView/Client/Module/UI/UI.cs

@@ -6,7 +6,7 @@ namespace ET.Client
     [FriendOf(typeof(UI))]
     public static class UISystem
     {
-        [ObjectSystem]
+        [EntitySystem]
         public class UIAwakeSystem : AwakeSystem<UI, string, GameObject>
         {
             protected override void Awake(UI self, string name, GameObject gameObject)
@@ -18,7 +18,7 @@ namespace ET.Client
             }
         }
 		
-        [ObjectSystem]
+        [EntitySystem]
         public class UIDestroySystem : DestroySystem<UI>
         {
             protected override void Destroy(UI self)