Bladeren bron

EntitySystemSingleton拆成两部分,一部分是TypeSystem,一部分是Queue
这样方便做热重载

tanghai 2 jaren geleden
bovenliggende
commit
5215f731a2
42 gewijzigde bestanden met toevoegingen van 614 en 564 verwijderingen
  1. 1 1
      Unity/Assets/Scripts/Core/MainVProcessInit.cs
  2. 40 30
      Unity/Assets/Scripts/Core/VProcess/Module/Entity/Entity.cs
  3. 1 1
      Unity/Assets/Scripts/Core/VProcess/Module/Entity/EntityHelper.cs
  4. 4 430
      Unity/Assets/Scripts/Core/VProcess/Module/Entity/EntitySystemSingleton.cs
  5. 32 0
      Unity/Assets/Scripts/Core/VProcess/Module/Entity/Root.cs
  6. 1 1
      Unity/Assets/Scripts/Core/VProcess/Module/Entity/Root.cs.meta
  7. 0 28
      Unity/Assets/Scripts/Core/VProcess/Module/Entity/RootEntity.cs
  8. 4 1
      Unity/Assets/Scripts/Core/VProcess/Module/Entity/Scene.cs
  9. 8 0
      Unity/Assets/Scripts/Core/VProcess/Module/EntitySystem.meta
  10. 436 0
      Unity/Assets/Scripts/Core/VProcess/Module/EntitySystem/EntitySystem.cs
  11. 11 0
      Unity/Assets/Scripts/Core/VProcess/Module/EntitySystem/EntitySystem.cs.meta
  12. 12 5
      Unity/Assets/Scripts/Core/VProcess/Module/VProcessActor/VProcessActor.cs
  13. 2 2
      Unity/Assets/Scripts/Core/VProcess/VProcess.cs
  14. 1 1
      Unity/Assets/Scripts/Core/VProcess/VProcessSingleton.cs
  15. 2 1
      Unity/Assets/Scripts/Core/World/Module/VProcess/VProcessManager.cs
  16. 1 1
      Unity/Assets/Scripts/Hotfix/Client/LockStep/LSClientHelper.cs
  17. 11 12
      Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs
  18. 5 6
      Unity/Assets/Scripts/Hotfix/Share/Demo/EntryEvent1_InitShare.cs
  19. 1 2
      Unity/Assets/Scripts/HotfixView/Client/Demo/EntryEvent3_InitClient.cs
  20. 3 3
      Unity/Assets/Scripts/Loader/CodeLoader.cs
  21. 0 1
      Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs
  22. 1 1
      Unity/Assets/Scripts/Model/Server/Demo/Watcher/WatcherComponent.cs
  23. 1 1
      Unity/Assets/Scripts/Model/Server/Module/Actor/ActorMessageDispatcherComponent.cs
  24. 1 1
      Unity/Assets/Scripts/Model/Server/Module/Actor/ActorMessageSenderComponent.cs
  25. 1 1
      Unity/Assets/Scripts/Model/Server/Module/ActorLocation/ActorLocationSenderOneType.cs
  26. 1 1
      Unity/Assets/Scripts/Model/Server/Module/ActorLocation/LocationProxyComponent.cs
  27. 1 1
      Unity/Assets/Scripts/Model/Server/Module/Message/NetInnerComponent.cs
  28. 1 1
      Unity/Assets/Scripts/Model/Server/Module/RobotCase/RobotCaseComponent.cs
  29. 8 7
      Unity/Assets/Scripts/Model/Share/Entry.cs
  30. 1 1
      Unity/Assets/Scripts/Model/Share/LockStep/LSEntity.cs
  31. 7 12
      Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemSingleton.cs
  32. 1 1
      Unity/Assets/Scripts/Model/Share/LockStep/LSUpdater.cs
  33. 4 1
      Unity/Assets/Scripts/Model/Share/LockStep/LSWorld.cs
  34. 2 1
      Unity/Assets/Scripts/Model/Share/LockStep/Room.cs
  35. 1 1
      Unity/Assets/Scripts/Model/Share/Module/AI/AIDispatcherComponent.cs
  36. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Console/ConsoleComponent.cs
  37. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Message/MessageDispatcherComponent.cs
  38. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Message/OpcodeTypeComponent.cs
  39. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Numeric/NumericWatcherComponent.cs
  40. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Recast/NavmeshComponent.cs
  41. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Scene/ClientSceneManagerComponent.cs
  42. 1 1
      Unity/Assets/Scripts/Model/Share/Module/Scene/ServerSceneManagerComponent.cs

+ 1 - 1
Unity/Assets/Scripts/Core/MainVProcessInit.cs

@@ -4,7 +4,7 @@
     {
         public static void Init(VProcess vProcess)
         {
-            vProcess.AddSingleton<RootEntity>();
+            vProcess.AddSingleton<Root>();
         }
     }
 }

+ 40 - 30
Unity/Assets/Scripts/Core/VProcess/Module/Entity/Entity.cs

@@ -17,7 +17,8 @@ namespace ET
 
     public interface IScene
     {
-        RootEntity Root { get; set; }
+        IScene Root { get; set; }
+        VProcess VProcess { get; set; }
         SceneType SceneType { get; set; }
     }
 
@@ -97,7 +98,7 @@ namespace ET
 
         protected virtual void RegisterSystem()
         {
-            EntitySystemSingleton.Instance.RegisterSystem(this);
+            EntitySystem.Instance.RegisterSystem(this);
         }
 
         protected virtual string ViewName
@@ -207,6 +208,7 @@ namespace ET
                 if (this is IScene scene)
                 {
                     scene.Root = this.parent.iScene.Root;
+                    scene.VProcess = this.parent.iScene.VProcess;
                     this.IScene = scene;
                 }
                 else
@@ -214,8 +216,6 @@ namespace ET
                     this.IScene = this.parent.iScene;
                 }
 
-                this.IScene = this is IScene? this as IScene : this.parent.iScene;
-
 #if ENABLE_VIEW && UNITY_EDITOR
                 this.viewGO.GetComponent<ComponentView>().Component = this;
                 this.viewGO.transform.SetParent(this.Parent == null ?
@@ -269,7 +269,17 @@ namespace ET
                 this.parent = value;
                 this.IsComponent = true;
                 this.parent.AddToComponents(this);
-                this.IScene = this is IScene? this as IScene : this.parent.iScene;
+                
+                if (this is IScene scene)
+                {
+                    scene.Root = this.parent.iScene.Root;
+                    scene.VProcess = this.parent.iScene.VProcess;
+                    this.IScene = scene;
+                }
+                else
+                {
+                    this.IScene = this.parent.iScene;
+                }
             }
         }
 
@@ -360,7 +370,7 @@ namespace ET
                 if (!this.IsCreated)
                 {
                     this.IsCreated = true;
-                    EntitySystemSingleton.Instance.Deserialize(this);
+                    EntitySystem.Instance.Deserialize(this);
                 }
             }
         }
@@ -497,7 +507,7 @@ namespace ET
             // 触发Destroy事件
             if (this is IDestroy)
             {
-                EntitySystemSingleton.Instance.Destroy(this);
+                EntitySystem.Instance.Destroy(this);
             }
 
             this.iScene = null;
@@ -597,7 +607,7 @@ namespace ET
             c.Dispose();
         }
 
-        private protected void RemoveComponent(Entity component)
+        private void RemoveComponent(Entity component)
         {
             if (this.IsDisposed)
             {
@@ -657,7 +667,7 @@ namespace ET
             // 如果有IGetComponent接口,则触发GetComponentSystem
             if (this is IGetComponent)
             {
-                EntitySystemSingleton.Instance.GetComponent(this, component);
+                EntitySystem.Instance.GetComponent(this, component);
             }
 
             return (K) component;
@@ -679,7 +689,7 @@ namespace ET
             // 如果有IGetComponent接口,则触发GetComponentSystem
             if (this is IGetComponent)
             {
-                EntitySystemSingleton.Instance.GetComponent(this, component);
+                EntitySystem.Instance.GetComponent(this, component);
             }
 
             return component;
@@ -716,7 +726,7 @@ namespace ET
 
             if (this is IAddComponent)
             {
-                EntitySystemSingleton.Instance.AddComponent(this, component);
+                EntitySystem.Instance.AddComponent(this, component);
             }
 
             return component;
@@ -732,11 +742,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = this.Id;
             component.ComponentParent = this;
-            EntitySystemSingleton.Instance.Awake(component);
+            EntitySystem.Instance.Awake(component);
 
             if (this is IAddComponent)
             {
-                EntitySystemSingleton.Instance.AddComponent(this, component);
+                EntitySystem.Instance.AddComponent(this, component);
             }
 
             return component;
@@ -753,11 +763,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = id;
             component.ComponentParent = this;
-            EntitySystemSingleton.Instance.Awake(component);
+            EntitySystem.Instance.Awake(component);
 
             if (this is IAddComponent)
             {
-                EntitySystemSingleton.Instance.AddComponent(this, component);
+                EntitySystem.Instance.AddComponent(this, component);
             }
 
             return component as K;
@@ -774,11 +784,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = id;
             component.ComponentParent = this;
-            EntitySystemSingleton.Instance.Awake(component, p1);
+            EntitySystem.Instance.Awake(component, p1);
 
             if (this is IAddComponent)
             {
-                EntitySystemSingleton.Instance.AddComponent(this, component);
+                EntitySystem.Instance.AddComponent(this, component);
             }
 
             return component as K;
@@ -795,11 +805,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = id;
             component.ComponentParent = this;
-            EntitySystemSingleton.Instance.Awake(component, p1, p2);
+            EntitySystem.Instance.Awake(component, p1, p2);
 
             if (this is IAddComponent)
             {
-                EntitySystemSingleton.Instance.AddComponent(this, component);
+                EntitySystem.Instance.AddComponent(this, component);
             }
 
             return component as K;
@@ -816,11 +826,11 @@ namespace ET
             Entity component = Create(type, isFromPool);
             component.Id = id;
             component.ComponentParent = this;
-            EntitySystemSingleton.Instance.Awake(component, p1, p2, p3);
+            EntitySystem.Instance.Awake(component, p1, p2, p3);
 
             if (this is IAddComponent)
             {
-                EntitySystemSingleton.Instance.AddComponent(this, component);
+                EntitySystem.Instance.AddComponent(this, component);
             }
 
             return component as K;
@@ -859,7 +869,7 @@ namespace ET
             component.Id = IdGenerater.Instance.GenerateId();
             component.Parent = this;
 
-            EntitySystemSingleton.Instance.Awake(component);
+            EntitySystem.Instance.Awake(component);
             return component;
         }
 
@@ -870,7 +880,7 @@ namespace ET
             component.Id = IdGenerater.Instance.GenerateId();
             component.Parent = this;
 
-            EntitySystemSingleton.Instance.Awake(component, a);
+            EntitySystem.Instance.Awake(component, a);
             return component;
         }
 
@@ -881,7 +891,7 @@ namespace ET
             component.Id = IdGenerater.Instance.GenerateId();
             component.Parent = this;
 
-            EntitySystemSingleton.Instance.Awake(component, a, b);
+            EntitySystem.Instance.Awake(component, a, b);
             return component;
         }
 
@@ -892,7 +902,7 @@ namespace ET
             component.Id = IdGenerater.Instance.GenerateId();
             component.Parent = this;
 
-            EntitySystemSingleton.Instance.Awake(component, a, b, c);
+            EntitySystem.Instance.Awake(component, a, b, c);
             return component;
         }
 
@@ -902,7 +912,7 @@ namespace ET
             T component = Entity.Create(type, isFromPool) as T;
             component.Id = id;
             component.Parent = this;
-            EntitySystemSingleton.Instance.Awake(component);
+            EntitySystem.Instance.Awake(component);
             return component;
         }
 
@@ -913,7 +923,7 @@ namespace ET
             component.Id = id;
             component.Parent = this;
 
-            EntitySystemSingleton.Instance.Awake(component, a);
+            EntitySystem.Instance.Awake(component, a);
             return component;
         }
 
@@ -924,7 +934,7 @@ namespace ET
             component.Id = id;
             component.Parent = this;
 
-            EntitySystemSingleton.Instance.Awake(component, a, b);
+            EntitySystem.Instance.Awake(component, a, b);
             return component;
         }
 
@@ -935,13 +945,13 @@ namespace ET
             component.Id = id;
             component.Parent = this;
 
-            EntitySystemSingleton.Instance.Awake(component, a, b, c);
+            EntitySystem.Instance.Awake(component, a, b, c);
             return component;
         }
 
         public override void BeginInit()
         {
-            EntitySystemSingleton.Instance.Serialize(this);
+            EntitySystem.Instance.Serialize(this);
             
             this.componentsDB?.Clear();
             if (this.components != null && this.components.Count != 0)

+ 1 - 1
Unity/Assets/Scripts/Core/VProcess/Module/Entity/EntityHelper.cs

@@ -12,7 +12,7 @@ namespace ET
             return entity.IScene as Scene;
         }
         
-        public static RootEntity Root(this Entity entity)
+        public static IScene Root(this Entity entity)
         {
             return entity.IScene.Root;
         }

+ 4 - 430
Unity/Assets/Scripts/Core/VProcess/Module/Entity/EntitySystemSingleton.cs

@@ -3,24 +3,13 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    public class EntitySystemSingleton: VProcessSingleton<EntitySystemSingleton>, ISingletonAwake, IVProcessSingletonUpdate, IVProcessSingletonLateUpdate, IVProcessSingletonLoad
+    public class EntitySystemSingleton: Singleton<EntitySystemSingleton>, ISingletonAwake
     {
-        private TypeSystems typeSystems;
-
-        private readonly Queue<EntityRef<Entity>>[] queues = new Queue<EntityRef<Entity>>[InstanceQueueIndex.Max];
+        public TypeSystems TypeSystems { get; private set; }
         
         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);
+            this.TypeSystems = new TypeSystems(InstanceQueueIndex.Max);
 
             foreach (Type type in EventSystem.Instance.GetTypes(typeof (EntitySystemAttribute)))
             {
@@ -28,7 +17,7 @@ namespace ET
 
                 if (obj is ISystemType iSystemType)
                 {
-                    TypeSystems.OneTypeSystems oneTypeSystems = this.typeSystems.GetOrCreateOneTypeSystems(iSystemType.Type());
+                    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)
@@ -37,421 +26,6 @@ namespace ET
                     }
                 }
             }
-            
-            
-            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 Serialize(Entity component)
-        {
-            if (component is not ISerialize)
-            {
-                return;
-            }
-            
-            List<object> iSerializeSystems = this.typeSystems.GetSystems(component.GetType(), typeof (ISerializeSystem));
-            if (iSerializeSystems == null)
-            {
-                return;
-            }
-
-            foreach (ISerializeSystem serializeSystem in iSerializeSystems)
-            {
-                if (serializeSystem == null)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    serializeSystem.Run(component);
-                }
-                catch (Exception e)
-                {
-                    Log.Error(e);
-                }
-            }
-        }
-        
-        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);
-                    }
-                }
-            }
         }
     }
 }

+ 32 - 0
Unity/Assets/Scripts/Core/VProcess/Module/Entity/Root.cs

@@ -0,0 +1,32 @@
+using System.Collections.Generic;
+
+namespace ET
+{
+    // 管理根部的Scene
+    [EnableMethod]
+    public class Root: VProcessSingleton<Root>
+    {
+        public Scene Scene { get; private set; }
+
+        public Root()
+        {
+            this.Scene = EntitySceneFactory.CreateScene(IdGenerater.Instance.GenerateId(), IdGenerater.Instance.GenerateInstanceId(), 0, SceneType.Root, "Root");
+        }
+
+        public override void Dispose()
+        {
+            if (this.IsDisposed)
+            {
+                return;
+            }
+            
+            base.Dispose();
+            
+            
+            
+            Scene scene = this.Scene;
+            this.Scene = null;
+            scene.Dispose();
+        }
+    }
+}

+ 1 - 1
Unity/Assets/Scripts/Core/VProcess/Module/Entity/RootEntity.cs.meta → Unity/Assets/Scripts/Core/VProcess/Module/Entity/Root.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 1c0208d9ebaff0c4b94c527c6e9d1354
+guid: 0fc9be97bbcd0a04498f9a1792cb09b2
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 0 - 28
Unity/Assets/Scripts/Core/VProcess/Module/Entity/RootEntity.cs

@@ -1,28 +0,0 @@
-using System.Collections.Generic;
-
-namespace ET
-{
-    // 管理根部的Scene
-    [EnableMethod]
-    public class RootEntity: Entity, IScene, IVProcessSingleton
-    {
-        public RootEntity Root { get; set; }
-        
-        public VProcess VProcess { get; set; }
-
-        public SceneType SceneType { get; set; }
-
-        public RootEntity()
-        {
-            this.Root = this;
-            this.Id = 0;
-            this.InstanceId = IdGenerater.Instance.GenerateInstanceId();
-            this.SceneType = SceneType.Root;
-            this.IsCreated = true;
-            this.IsNew = true;
-            this.IsRegister = true;
-            this.IScene = this;
-            Log.Info($"Root create: {this.SceneType} {this.Id} {this.InstanceId}");
-        }
-    }
-}

+ 4 - 1
Unity/Assets/Scripts/Core/VProcess/Module/Entity/Scene.cs

@@ -8,8 +8,11 @@ namespace ET
     public class Scene: Entity, IScene
     {
         [BsonIgnore]
-        public RootEntity Root { get; set; }
+        public VProcess VProcess { get; set; }
         
+        [BsonIgnore]
+        public IScene Root { get; set; }
+
         public int Zone
         {
             get;

+ 8 - 0
Unity/Assets/Scripts/Core/VProcess/Module/EntitySystem.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 6d1ec9e4c1a06f947a99ea56de697abd
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 436 - 0
Unity/Assets/Scripts/Core/VProcess/Module/EntitySystem/EntitySystem.cs

@@ -0,0 +1,436 @@
+using System;
+using System.Collections.Generic;
+
+namespace ET
+{
+    public class EntitySystem: VProcessSingleton<EntitySystem>, ISingletonAwake, IVProcessSingletonUpdate, IVProcessSingletonLateUpdate, IVProcessSingletonLoad
+    {
+        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()
+        {
+            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 = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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 Serialize(Entity component)
+        {
+            if (component is not ISerialize)
+            {
+                return;
+            }
+            
+            List<object> iSerializeSystems = EntitySystemSingleton.Instance.TypeSystems.GetSystems(component.GetType(), typeof (ISerializeSystem));
+            if (iSerializeSystems == null)
+            {
+                return;
+            }
+
+            foreach (ISerializeSystem serializeSystem in iSerializeSystems)
+            {
+                if (serializeSystem == null)
+                {
+                    continue;
+                }
+
+                try
+                {
+                    serializeSystem.Run(component);
+                }
+                catch (Exception e)
+                {
+                    Log.Error(e);
+                }
+            }
+        }
+        
+        public void Deserialize(Entity component)
+        {
+            if (component is not IDeserialize)
+            {
+                return;
+            }
+            
+            List<object> iDeserializeSystems = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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 = EntitySystemSingleton.Instance.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);
+                    }
+                }
+            }
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Scripts/Core/VProcess/Module/EntitySystem/EntitySystem.cs.meta

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

+ 12 - 5
Unity/Assets/Scripts/Core/VProcess/Module/VProcessActor/VProcessActor.cs

@@ -2,7 +2,7 @@
 
 namespace ET
 {
-    public class VProcessActor: VProcessSingleton<VProcessActor>, IVProcessSingletonUpdate, IVProcessSingletonAwake
+    public class VProcessActor: VProcessSingleton<VProcessActor>, IVProcessSingletonAwake
     {
         private readonly Dictionary<int, ETTask<IResponse>> requestCallbacks = new();
 
@@ -10,14 +10,21 @@ namespace ET
 
         private int rpcId;
         
-        public void Awake()
+        public override void Dispose()
         {
-            WorldActor.Instance.AddActor(this.VProcess.Id);
+            if (this.IsDisposed)
+            {
+                return;
+            }
+            
+            base.Dispose();
+            
+            WorldActor.Instance.RemoveActor(this.VProcess.Id);
         }
 
-        public override void Dispose()
+        public void Awake()
         {
-            WorldActor.Instance.RemoveActor(this.VProcess.Id);
+            WorldActor.Instance.AddActor(this.VProcess.Id);
         }
 
         public void Update()

+ 2 - 2
Unity/Assets/Scripts/Core/VProcess/VProcess.cs

@@ -7,14 +7,14 @@ namespace ET
     {
         [ThreadStatic]
         [StaticField]
-        public static VProcess Instance;
+        public static VProcess Instance;    
         
         public int Id { get; private set; }
 
         public bool IsRuning;
 
         // 保存虚拟进程中的Instance,方便快速获取
-        private readonly Dictionary<Type, object> instances = new();
+        private readonly Dictionary<Type, object> instances = new(); 
 
         private readonly Stack<IVProcessSingleton> singletons = new();
 

+ 1 - 1
Unity/Assets/Scripts/Core/VProcess/VProcessSingleton.cs

@@ -25,7 +25,7 @@ namespace ET
             }
         }
 
-        bool IVProcessSingleton.IsDisposed
+        public bool IsDisposed
         {
             get
             {

+ 2 - 1
Unity/Assets/Scripts/Core/World/Module/VProcess/VProcessManager.cs

@@ -16,7 +16,8 @@ namespace ET
                     processId = --this.idGenerator;
                 }
                 VProcess vProcess = new(processId);
-                vProcess.AddSingleton<VProcessActor>();
+                vProcess.AddSingleton<Root>();
+                vProcess.AddSingleton<EntitySystem>();
                 this.vProcesses.TryAdd(vProcess.Id, vProcess);
                 return vProcess.Id;
             }

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

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

+ 11 - 12
Unity/Assets/Scripts/Hotfix/Server/Demo/EntryEvent2_InitServer.cs

@@ -7,25 +7,24 @@ namespace ET.Server
     {
         protected override async ETTask Run(Scene scene, ET.EventType.EntryEvent2 args)
         {
-            RootEntity root = scene.Root;
             // 发送普通actor消息
-            root.AddComponent<ActorMessageSenderComponent>();
+            scene.AddComponent<ActorMessageSenderComponent>();
             // 发送location actor消息
-            root.AddComponent<ActorLocationSenderComponent>();
+            scene.AddComponent<ActorLocationSenderComponent>();
             // 访问location server的组件
-            root.AddComponent<LocationProxyComponent>();
-            root.AddComponent<ActorMessageDispatcherComponent>();
-            root.AddComponent<ServerSceneManagerComponent>();
-            root.AddComponent<RobotCaseComponent>();
+            scene.AddComponent<LocationProxyComponent>();
+            scene.AddComponent<ActorMessageDispatcherComponent>();
+            scene.AddComponent<ServerSceneManagerComponent>();
+            scene.AddComponent<RobotCaseComponent>();
 
-            root.AddComponent<NavmeshComponent>();
+            scene.AddComponent<NavmeshComponent>();
 
             StartProcessConfig processConfig = StartProcessConfigCategory.Instance.Get(Options.Instance.Process);
             switch (Options.Instance.AppType)
             {
                 case AppType.Server:
                 {
-                    root.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
+                    scene.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
 
                     var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Options.Instance.Process);
                     foreach (StartSceneConfig startConfig in processScenes)
@@ -39,9 +38,9 @@ namespace ET.Server
                 case AppType.Watcher:
                 {
                     StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
-                    WatcherComponent watcherComponent = root.AddComponent<WatcherComponent>();
+                    WatcherComponent watcherComponent = scene.AddComponent<WatcherComponent>();
                     watcherComponent.Start(Options.Instance.CreateScenes);
-                    root.AddComponent<NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
+                    scene.AddComponent<NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
                     break;
                 }
                 case AppType.GameTool:
@@ -50,7 +49,7 @@ namespace ET.Server
 
             if (Options.Instance.Console == 1)
             {
-                root.AddComponent<ConsoleComponent>();
+                scene.AddComponent<ConsoleComponent>();
             }
         }
     }

+ 5 - 6
Unity/Assets/Scripts/Hotfix/Share/Demo/EntryEvent1_InitShare.cs

@@ -5,12 +5,11 @@ namespace ET
     {
         protected override async ETTask Run(Scene scene, EventType.EntryEvent1 args)
         {
-            RootEntity root = scene.Root();
-            root.AddComponent<OpcodeTypeComponent>();
-            root.AddComponent<MessageDispatcherComponent>();
-            root.AddComponent<NumericWatcherComponent>();
-            root.AddComponent<AIDispatcherComponent>();
-            root.AddComponent<ClientSceneManagerComponent>();
+            scene.AddComponent<OpcodeTypeComponent>();
+            scene.AddComponent<MessageDispatcherComponent>();
+            scene.AddComponent<NumericWatcherComponent>();
+            scene.AddComponent<AIDispatcherComponent>();
+            scene.AddComponent<ClientSceneManagerComponent>();
 
             await ETTask.CompletedTask;
         }

+ 1 - 2
Unity/Assets/Scripts/HotfixView/Client/Demo/EntryEvent3_InitClient.cs

@@ -8,9 +8,8 @@ namespace ET.Client
     {
         protected override async ETTask Run(Scene scene, ET.EventType.EntryEvent3 args)
         {
-            RootEntity root = scene.Root();
             // 加载配置
-            root.AddComponent<ResourcesComponent>();
+            scene.AddComponent<ResourcesComponent>();
 
             await ResourcesComponent.Instance.LoadBundleAsync("unit.unity3d");
 

+ 3 - 3
Unity/Assets/Scripts/Loader/CodeLoader.cs

@@ -23,7 +23,7 @@ namespace ET
 				
 				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
 				Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(assemblies);
-				EventSystem.Instance.Add(types);
+				World.Instance.AddSingleton<EventSystem, Dictionary<string, Type>>(types);
 				foreach (Assembly ass in assemblies)
 				{
 					string name = ass.GetName().Name;
@@ -89,8 +89,8 @@ namespace ET
 			
 			Assembly hotfixAssembly = Assembly.Load(assBytes, pdbBytes);
 			
-			Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (Game).Assembly, typeof(Init).Assembly, this.assembly, hotfixAssembly);
-			EventSystem.Instance.Add(types);
+			Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(typeof (World).Assembly, typeof(Init).Assembly, this.assembly, hotfixAssembly);
+			World.Instance.AddSingleton<EventSystem, Dictionary<string, Type>>(types);
 		}
 	}
 }

+ 0 - 1
Unity/Assets/Scripts/Loader/MonoBehaviour/Init.cs

@@ -28,7 +28,6 @@ namespace ET
 			World.Instance.AddSingleton<ObjectPool>();
 			World.Instance.AddSingleton<WorldActor>();
 			World.Instance.AddSingleton<CodeLoader>();
-			
 			World.Instance.AddSingleton<VProcessManager>();
 			VProcessManager.MainThreadScheduler mainThreadScheduler = World.Instance.AddSingleton<VProcessManager.MainThreadScheduler>();
 

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Demo/Watcher/WatcherComponent.cs

@@ -3,7 +3,7 @@ using System.Diagnostics;
 
 namespace ET.Server
 {
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class WatcherComponent: Entity, IAwake, IDestroy
     {
         public static WatcherComponent Instance { get; set; }

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/Actor/ActorMessageDispatcherComponent.cs

@@ -19,7 +19,7 @@ namespace ET.Server
     /// <summary>
     /// Actor消息分发组件
     /// </summary>
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class ActorMessageDispatcherComponent: Entity, IAwake, IDestroy, ILoad
     {
         [ThreadStatic]

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/Actor/ActorMessageSenderComponent.cs

@@ -2,7 +2,7 @@
 
 namespace ET.Server
 {
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class ActorMessageSenderComponent: Entity, IAwake, IDestroy
     {
         public const long TIMEOUT_TIME = 40 * 1000;

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/ActorLocation/ActorLocationSenderOneType.cs

@@ -14,7 +14,7 @@ namespace ET.Server
     }
     
     
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class ActorLocationSenderComponent: Entity, IAwake, IDestroy
     {
         public const long TIMEOUT_TIME = 60 * 1000;

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/ActorLocation/LocationProxyComponent.cs

@@ -2,7 +2,7 @@
 
 namespace ET.Server
 {
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class LocationProxyComponent: Entity, IAwake, IDestroy
     {
         [ThreadStatic]

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/Message/NetInnerComponent.cs

@@ -23,7 +23,7 @@ namespace ET.Server
         public object Message;
     }
     
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class NetInnerComponent: Entity, IAwake<IPEndPoint>, IAwake, IDestroy
     {
         public int ServiceId;

+ 1 - 1
Unity/Assets/Scripts/Model/Server/Module/RobotCase/RobotCaseComponent.cs

@@ -4,7 +4,7 @@ using System.Collections.Generic;
 namespace ET.Server
 {
     
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class RobotCaseComponent: Entity, IAwake, IDestroy
     {
         [ThreadStatic]

+ 8 - 7
Unity/Assets/Scripts/Model/Share/Entry.cs

@@ -36,6 +36,9 @@ namespace ET
             
             MongoHelper.RegisterStruct<LSInput>();
             MongoHelper.Register();
+            
+            World.Instance.AddSingleton<EntitySystemSingleton>();
+            World.Instance.AddSingleton<LSEntitySystemSingleton>();
 
             VProcess vProcess = VProcess.Instance;
             
@@ -44,17 +47,15 @@ namespace ET
             vProcess.AddSingleton<IdGenerater>();
             vProcess.AddSingleton<TimerComponent>();
             vProcess.AddSingleton<CoroutineLockComponent>();
-            vProcess.AddSingleton<EntitySystemSingleton>();
-            vProcess.AddSingleton<LSEntitySystemSington>();
-
+            
             vProcess.AddSingleton<NetServices>();
-            RootEntity root = vProcess.AddSingleton<RootEntity>();
+            Root root = vProcess.AddSingleton<Root>();
 
             await World.Instance.AddSingleton<ConfigComponent>().LoadAsync();
 
-            await EventSystem.Instance.PublishAsync(root, new EventType.EntryEvent1());
-            await EventSystem.Instance.PublishAsync(root, new EventType.EntryEvent2());
-            await EventSystem.Instance.PublishAsync(root, new EventType.EntryEvent3());
+            await EventSystem.Instance.PublishAsync(root.Scene, new EventType.EntryEvent1());
+            await EventSystem.Instance.PublishAsync(root.Scene, new EventType.EntryEvent2());
+            await EventSystem.Instance.PublishAsync(root.Scene, new EventType.EntryEvent3());
         }
     }
 }

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

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

+ 7 - 12
Unity/Assets/Scripts/Model/Share/LockStep/LSEntitySystemSingleton.cs

@@ -11,18 +11,13 @@ namespace ET
         public const int Max = 1;
     }
     
-    public class LSEntitySystemSington: VProcessSingleton<LSEntitySystemSington>, ISingletonAwake, IVProcessSingletonLoad
+    public class LSEntitySystemSingleton: Singleton<LSEntitySystemSingleton>, ISingletonAwake
     {
-        private TypeSystems typeSystems;
+        public TypeSystems TypeSystems { get; private set; }
         
         public void Awake()
         {
-            this.Load();
-        }
-        
-        public void Load()
-        {
-            this.typeSystems = new(LSQueneUpdateIndex.Max);
+            this.TypeSystems = new(LSQueneUpdateIndex.Max);
             foreach (Type type in EventSystem.Instance.GetTypes(typeof (LSEntitySystemAttribute)))
             {
                 object obj = Activator.CreateInstance(type);
@@ -32,7 +27,7 @@ namespace ET
                     continue;
                 }
 
-                TypeSystems.OneTypeSystems oneTypeSystems = this.typeSystems.GetOrCreateOneTypeSystems(iSystemType.Type());
+                TypeSystems.OneTypeSystems oneTypeSystems = this.TypeSystems.GetOrCreateOneTypeSystems(iSystemType.Type());
                 oneTypeSystems.Map.Add(iSystemType.SystemType(), obj);
                 int index = iSystemType.GetInstanceQueueIndex();
                 if (index > LSQueneUpdateIndex.None && index < LSQueneUpdateIndex.Max)
@@ -44,7 +39,7 @@ namespace ET
         
         public TypeSystems.OneTypeSystems GetOneTypeSystems(Type type)
         {
-            return this.typeSystems.GetOneTypeSystems(type);
+            return this.TypeSystems.GetOneTypeSystems(type);
         }
         
         public void LSRollback(Entity entity)
@@ -54,7 +49,7 @@ namespace ET
                 return;
             }
             
-            List<object> iLSRollbackSystems = this.typeSystems.GetSystems(entity.GetType(), typeof (ILSRollbackSystem));
+            List<object> iLSRollbackSystems = this.TypeSystems.GetSystems(entity.GetType(), typeof (ILSRollbackSystem));
             if (iLSRollbackSystems == null)
             {
                 return;
@@ -85,7 +80,7 @@ namespace ET
                 return;
             }
             
-            List<object> iLSUpdateSystems = typeSystems.GetSystems(entity.GetType(), typeof (ILSUpdateSystem));
+            List<object> iLSUpdateSystems = TypeSystems.GetSystems(entity.GetType(), typeof (ILSUpdateSystem));
             if (iLSUpdateSystems == null)
             {
                 return;

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

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

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

@@ -44,7 +44,10 @@ namespace ET
         private readonly LSUpdater updater = new();
         
         [BsonIgnore]
-        public RootEntity Root { get; set; }
+        public VProcess VProcess { get; set; }
+        
+        [BsonIgnore]
+        public IScene Root { get; set; }
 
         [BsonElement]
         private long idGenerator;

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

@@ -6,7 +6,8 @@ namespace ET
     [ComponentOf]
     public class Room: Entity, IScene, IAwake, IUpdate
     {
-        public RootEntity Root { get; set; }
+        public VProcess VProcess { get; set; }
+        public IScene Root { get; set; }
         public SceneType SceneType { get; set; } = SceneType.Room;
         public string Name { get; set; }
         

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/AI/AIDispatcherComponent.cs

@@ -2,7 +2,7 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class AIDispatcherComponent: Entity, IAwake, IDestroy, ILoad
     {
         [StaticField]

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Console/ConsoleComponent.cs

@@ -14,7 +14,7 @@ namespace ET
         public const string Robot = "Robot";
     }
 
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class ConsoleComponent: Entity, IAwake, ILoad
     {
         public CancellationTokenSource CancellationTokenSource;

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Message/MessageDispatcherComponent.cs

@@ -17,7 +17,7 @@ namespace ET
     /// <summary>
     /// 消息分发组件
     /// </summary>
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class MessageDispatcherComponent: Entity, IAwake, IDestroy, ILoad
     {
         public static MessageDispatcherComponent Instance

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

@@ -80,7 +80,7 @@ namespace ET
         }
     }
 
-    [ComponentOf(typeof (RootEntity))]
+    [ComponentOf(typeof (Scene))]
     public class OpcodeTypeComponent: Entity, IAwake, IDestroy
     {
         [ThreadStatic]

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

@@ -78,7 +78,7 @@ namespace ET
     /// <summary>
     /// 监视数值变化组件,分发监听
     /// </summary>
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class NumericWatcherComponent : Entity, IAwake, ILoad
     {
         public static NumericWatcherComponent Instance { get; set; }

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Recast/NavmeshComponent.cs

@@ -3,7 +3,7 @@ using System.Collections.Generic;
 
 namespace ET
 {
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class NavmeshComponent: Entity, IAwake
     {
         [ThreadStatic]

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Scene/ClientSceneManagerComponent.cs

@@ -2,7 +2,7 @@ using System;
 
 namespace ET
 {
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class ClientSceneManagerComponent: Entity, IAwake, IDestroy
     {
         [ThreadStatic]

+ 1 - 1
Unity/Assets/Scripts/Model/Share/Module/Scene/ServerSceneManagerComponent.cs

@@ -2,7 +2,7 @@ using System;
 
 namespace ET
 {
-    [ComponentOf(typeof(RootEntity))]
+    [ComponentOf(typeof(Scene))]
     public class ServerSceneManagerComponent: Entity, IAwake, IDestroy
     {
         [ThreadStatic]