Преглед изворни кода

Entit.Create改成Entity的AddChild方法,以后创建Entity只有两种方法AddComponent跟AddChild(AddChildWithId),这样创建方式就完美统一了

tanghai пре 4 година
родитељ
комит
1d226af72b

+ 1 - 1
Robot/Hotfix/Module/RobotCase/RobotCaseComponentSystem.cs

@@ -31,7 +31,7 @@ namespace ET
         public static async ETTask<RobotCase> New(this RobotCaseComponent self)
         {
             await ETTask.CompletedTask;
-            RobotCase robotCase = Entity.Create<RobotCase>(self);
+            RobotCase robotCase = self.AddChild<RobotCase>();
             return robotCase;
         }
     }

+ 1 - 1
Server/Hotfix/Demo/C2G_LoginGateHandler.cs

@@ -19,7 +19,7 @@ namespace ET
 			}
 
 			PlayerComponent playerComponent = scene.GetComponent<PlayerComponent>();
-			Player player = Entity.Create<Player, string>(playerComponent, account);
+			Player player = playerComponent.AddChild<Player, string>(account);
 			playerComponent.Add(player);
 			session.AddComponent<SessionPlayerComponent>().Player = player;
 			session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);

+ 1 - 1
Server/Hotfix/Demo/G2M_CreateUnitHandler.cs

@@ -9,7 +9,7 @@ namespace ET
 		protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
 		{
 			UnitComponent unitComponent = scene.GetComponent<UnitComponent>();
-			Unit unit = Entity.CreateWithId<Unit, int>(unitComponent, IdGenerater.Instance.GenerateId(), 1001);
+			Unit unit = unitComponent.AddChildWithId<Unit, int>(IdGenerater.Instance.GenerateId(), 1001);
 			unit.AddComponent<MoveComponent>();
 			unit.Position = new Vector3(-10, 0, -10);
 			

+ 1 - 1
Server/Hotfix/Module/ActorLocation/ActorLocationSenderComponentSystem.cs

@@ -62,7 +62,7 @@ namespace ET
                 return (ActorLocationSender) actorLocationSender;
             }
 
-            actorLocationSender = Entity.CreateWithId<ActorLocationSender>(self, id);
+            actorLocationSender = self.AddChildWithId<ActorLocationSender>(id);
             return (ActorLocationSender) actorLocationSender;
         }
 

+ 2 - 2
Server/Hotfix/Module/Message/NetInnerComponentSystem.cs

@@ -87,7 +87,7 @@ namespace ET
         // 这个channelId是由CreateAcceptChannelId生成的
         public static void OnAccept(this NetInnerComponent self, long channelId, IPEndPoint ipEndPoint)
         {
-            Session session = Entity.CreateWithId<Session, AService>(self, channelId, self.Service);
+            Session session = self.AddChildWithId<Session, AService>(channelId, self.Service);
             session.RemoteAddress = ipEndPoint;
             //session.AddComponent<SessionIdleCheckerComponent, int, int, int>(NetThreadComponent.checkInteral, NetThreadComponent.recvMaxIdleTime, NetThreadComponent.sendMaxIdleTime);
         }
@@ -103,7 +103,7 @@ namespace ET
 
         private static Session CreateInner(this NetInnerComponent self, long channelId, IPEndPoint ipEndPoint)
         {
-            Session session = Entity.CreateWithId<Session, AService>(self, channelId, self.Service);
+            Session session = self.AddChildWithId<Session, AService>(channelId, self.Service);
 
             session.RemoteAddress = ipEndPoint;
 

+ 1 - 1
Server/Model/Demo/RecastNav/RecastPathComponent.cs

@@ -71,7 +71,7 @@ namespace ET
 
             if (RecastInterface.LoadMap(mapId, navDataPath))
             {
-                RecastPathProcessor recastPathProcessor = Entity.Create<RecastPathProcessor>(this);
+                RecastPathProcessor recastPathProcessor = this.AddChild<RecastPathProcessor>();
                 recastPathProcessor.MapId = mapId;
                 m_RecastPathProcessorDic[mapId] = recastPathProcessor;
                 Log.Debug($"加载Id为{mapId}的地图Nav数据成功!");

+ 1 - 1
Server/Model/Module/ActorLocation/LocationComponent.cs

@@ -60,7 +60,7 @@ namespace ET
         {
             CoroutineLock coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Location, key);
 
-            LockInfo lockInfo = Entity.Create<LockInfo, long, CoroutineLock>(this, instanceId, coroutineLock);
+            LockInfo lockInfo = this.AddChild<LockInfo, long, CoroutineLock>(instanceId, coroutineLock);
             this.lockInfos.Add(key, lockInfo);
 
             Log.Debug($"location lock key: {key} instanceId: {instanceId}");

+ 1 - 1
Unity/Assets/Hotfix/Demo/Unit/UnitFactory.cs

@@ -7,7 +7,7 @@ namespace ET
         public static Unit Create(Entity domain, UnitInfo unitInfo)
         {
 	        UnitComponent unitComponent = domain.GetComponent<UnitComponent>();
-	        Unit unit = Entity.CreateWithId<Unit, int>(unitComponent, unitInfo.UnitId, unitInfo.ConfigId);
+	        Unit unit = unitComponent.AddChildWithId<Unit, int>(unitInfo.UnitId, unitInfo.ConfigId);
 	        unitComponent.Add(unit);
 	        
 	        unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);

+ 2 - 2
Unity/Assets/Hotfix/Module/Message/NetKcpComponentSystem.cs

@@ -83,7 +83,7 @@ namespace ET
         // 这个channelId是由CreateAcceptChannelId生成的
         public static void OnAccept(this NetKcpComponent self, long channelId, IPEndPoint ipEndPoint)
         {
-            Session session = Entity.CreateWithId<Session, AService>(self, channelId, self.Service);
+            Session session = self.AddChildWithId<Session, AService>(channelId, self.Service);
             session.RemoteAddress = ipEndPoint;
 
             session.AddComponent<SessionAcceptTimeoutComponent>();
@@ -100,7 +100,7 @@ namespace ET
         public static Session Create(this NetKcpComponent self, IPEndPoint realIPEndPoint)
         {
             long channelId = RandomHelper.RandInt64();
-            Session session = Entity.CreateWithId<Session, AService>(self, channelId, self.Service);
+            Session session = self.AddChildWithId<Session, AService>(channelId, self.Service);
             session.RemoteAddress = realIPEndPoint;
             session.AddComponent<SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);
             

+ 1 - 1
Unity/Assets/HotfixView/Demo/UI/UILoading/UILoadingEvent.cs

@@ -14,7 +14,7 @@ namespace ET
 				GameObject bundleGameObject = ((GameObject)Resources.Load("KV")).Get<GameObject>(UIType.UILoading);
 				GameObject go = UnityEngine.Object.Instantiate(bundleGameObject);
 				go.layer = LayerMask.NameToLayer(LayerNames.UI);
-				UI ui = Entity.Create<UI, string, GameObject>(uiComponent, UIType.UILoading, go);
+				UI ui = uiComponent.AddChild<UI, string, GameObject>(UIType.UILoading, go);
 
 				ui.AddComponent<UILoadingComponent>();
 				return ui;

+ 1 - 1
Unity/Assets/HotfixView/Demo/UI/UILobby/UILobbyEvent.cs

@@ -12,7 +12,7 @@ namespace ET
             ResourcesComponent.Instance.LoadBundle(UIType.UILobby.StringToAB());
             GameObject bundleGameObject = (GameObject) ResourcesComponent.Instance.GetAsset(UIType.UILobby.StringToAB(), UIType.UILobby);
             GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject);
-            UI ui = Entity.Create<UI, string, GameObject>(uiComponent, UIType.UILobby, gameObject);
+            UI ui = uiComponent.AddChild<UI, string, GameObject>(UIType.UILobby, gameObject);
 
             ui.AddComponent<UILobbyComponent>();
             return ui;

+ 1 - 1
Unity/Assets/HotfixView/Demo/UI/UILogin/UILoginEvent.cs

@@ -12,7 +12,7 @@ namespace ET
             GameObject bundleGameObject = (GameObject) ResourcesComponent.Instance.GetAsset(UIType.UILogin.StringToAB(), UIType.UILogin);
             GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject);
 
-            UI ui = Entity.Create<UI, string, GameObject>(uiComponent, UIType.UILogin, gameObject);
+            UI ui = uiComponent.AddChild<UI, string, GameObject>(UIType.UILogin, gameObject);
 
             ui.AddComponent<UILoginComponent>();
             return ui;

+ 4 - 4
Unity/Assets/Model/Core/Entity/TimerComponent.cs

@@ -176,7 +176,7 @@ namespace ET
             }
 
             ETTask<bool> tcs = ETTask<bool>.Create(true);
-            TimerAction timer = Entity.Create<TimerAction, TimerClass, long, object>(this, TimerClass.OnceWaitTimer, 0, tcs, true);
+            TimerAction timer = this.AddChild<TimerAction, TimerClass, long, object>(TimerClass.OnceWaitTimer, 0, tcs, true);
             this.AddTimer(tillTime, timer);
             long timerId = timer.Id;
 
@@ -216,7 +216,7 @@ namespace ET
 
             ETTask<bool> tcs = ETTask<bool>.Create(true);
             
-            TimerAction timer = Entity.Create<TimerAction, TimerClass, long, object>(this, TimerClass.OnceWaitTimer, 0, tcs, true);
+            TimerAction timer = this.AddChild<TimerAction, TimerClass, long, object>(TimerClass.OnceWaitTimer, 0, tcs, true);
             this.AddTimer(tillTime, timer);
             long timerId = timer.Id;
 
@@ -262,7 +262,7 @@ namespace ET
 			}
 #endif
             long tillTime = TimeHelper.ServerNow() + time;
-            TimerAction timer = Entity.Create<TimerAction, TimerClass, long, object>(this, TimerClass.RepeatedTimer, time, action, true);
+            TimerAction timer = this.AddChild<TimerAction, TimerClass, long, object>(TimerClass.RepeatedTimer, time, action, true);
             this.AddTimer(tillTime, timer);
             return timer.Id;
         }
@@ -300,7 +300,7 @@ namespace ET
             {
                 Log.Error($"new once time too small: {tillTime}");
             }
-            TimerAction timer = Entity.Create<TimerAction, TimerClass, long, object>(this, TimerClass.OnceTimer, 0, action, true);
+            TimerAction timer = this.AddChild<TimerAction, TimerClass, long, object>(TimerClass.OnceTimer, 0, action, true);
             this.AddTimer(tillTime, timer);
             return timer.Id;
         }

+ 219 - 88
Unity/Assets/Model/Core/Object/Entity.cs

@@ -547,6 +547,123 @@ namespace ET
             return child as K;
         }
 
+        public void RemoveComponent<K>() where K : Entity
+        {
+            if (this.IsDisposed)
+            {
+                return;
+            }
+
+            if (this.components == null)
+            {
+                return;
+            }
+
+            Type type = typeof (K);
+            Entity c = this.GetComponent(type);
+            if (c == null)
+            {
+                return;
+            }
+
+            this.RemoveFromComponent(type, c);
+            c.Dispose();
+        }
+
+        public void RemoveComponent(Entity component)
+        {
+            if (this.IsDisposed)
+            {
+                return;
+            }
+
+            if (this.components == null)
+            {
+                return;
+            }
+
+            Type type = component.GetType();
+            Entity c = this.GetComponent(component.GetType());
+            if (c == null)
+            {
+                return;
+            }
+
+            if (c.InstanceId != component.InstanceId)
+            {
+                return;
+            }
+
+            this.RemoveFromComponent(type, c);
+            c.Dispose();
+        }
+
+        public void RemoveComponent(Type type)
+        {
+            if (this.IsDisposed)
+            {
+                return;
+            }
+
+            Entity c = this.GetComponent(type);
+            if (c == null)
+            {
+                return;
+            }
+
+            RemoveFromComponent(type, c);
+            c.Dispose();
+        }
+
+        public virtual K GetComponent<K>() where K : Entity
+        {
+            if (this.components == null)
+            {
+                return null;
+            }
+
+            Entity component;
+            if (!this.components.TryGetValue(typeof (K), out component))
+            {
+                return default;
+            }
+
+            return (K) component;
+        }
+
+        public virtual Entity GetComponent(Type type)
+        {
+            if (this.components == null)
+            {
+                return null;
+            }
+
+            Entity component;
+            if (!this.components.TryGetValue(type, out component))
+            {
+                return null;
+            }
+
+            return component;
+        }
+        
+        private static Entity Create(Type type, bool isFromPool)
+        {
+            Entity component;
+            if (isFromPool)
+            {
+                component = (Entity)ObjectPool.Instance.Fetch(type);
+            }
+            else
+            {
+                component = (Entity)Activator.CreateInstance(type);
+            }
+            component.IsFromPool = isFromPool;
+            component.IsCreate = true;
+            component.Id = 0;
+            return component;
+        }
+
         public Entity AddComponent(Entity component)
         {
             Type type = component.GetType();
@@ -562,21 +679,24 @@ namespace ET
             return component;
         }
 
-        public Entity AddComponent(Type type)
+        public Entity AddComponent(Type type, bool isFromPool = false)
         {
             if (this.components != null && this.components.ContainsKey(type))
             {
                 throw new Exception($"entity already has component: {type.FullName}");
             }
 
-            Entity component = CreateWithComponentParent(type);
+            Entity component = Create(type, isFromPool);
+            component.Id = this.Id;
+            component.ComponentParent = this;
+            EventSystem.Instance.Awake(component);
 
             this.AddToComponent(type, component);
 
             return component;
         }
 
-        public K AddComponent<K>() where K : Entity, new()
+        public K AddComponent<K>(bool isFromPool = false) where K : Entity, new()
         {
             Type type = typeof (K);
             if (this.components != null && this.components.ContainsKey(type))
@@ -584,14 +704,17 @@ namespace ET
                 throw new Exception($"entity already has component: {type.FullName}");
             }
 
-            K component = CreateWithComponentParent<K>();
+            Entity component = Create(type, isFromPool);
+            component.Id = this.Id;
+            component.ComponentParent = this;
+            EventSystem.Instance.Awake(component);
 
             this.AddToComponent(type, component);
             
-            return component;
+            return component as K;
         }
 
-        public K AddComponent<K, P1>(P1 p1) where K : Entity, new()
+        public K AddComponent<K, P1>(P1 p1, bool isFromPool = false) where K : Entity, new()
         {
             Type type = typeof (K);
             if (this.components != null && this.components.ContainsKey(type))
@@ -599,14 +722,17 @@ namespace ET
                 throw new Exception($"entity already has component: {type.FullName}");
             }
 
-            K component = CreateWithComponentParent<K, P1>(p1);
+            Entity component = Create(type, isFromPool);
+            component.Id = this.Id;
+            component.ComponentParent = this;
+            EventSystem.Instance.Awake(component, p1);
 
             this.AddToComponent(type, component);
 
-            return component;
+            return component as K;
         }
 
-        public K AddComponent<K, P1, P2>(P1 p1, P2 p2) where K : Entity, new()
+        public K AddComponent<K, P1, P2>(P1 p1, P2 p2, bool isFromPool = false) where K : Entity, new()
         {
             Type type = typeof (K);
             if (this.components != null && this.components.ContainsKey(type))
@@ -614,14 +740,17 @@ namespace ET
                 throw new Exception($"entity already has component: {type.FullName}");
             }
 
-            K component = CreateWithComponentParent<K, P1, P2>(p1, p2);
-
+            Entity component = Create(type, isFromPool);
+            component.Id = this.Id;
+            component.ComponentParent = this;
+            EventSystem.Instance.Awake(component, p1, p2);
+            
             this.AddToComponent(type, component);
 
-            return component;
+            return component as K;
         }
 
-        public K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3) where K : Entity, new()
+        public K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3, bool isFromPool = false) where K : Entity, new()
         {
             Type type = typeof (K);
             if (this.components != null && this.components.ContainsKey(type))
@@ -629,110 +758,112 @@ namespace ET
                 throw new Exception($"entity already has component: {type.FullName}");
             }
 
-            K component = CreateWithComponentParent<K, P1, P2, P3>(p1, p2, p3);
+            Entity component = Create(type, isFromPool);
+            component.Id = this.Id;
+            component.ComponentParent = this;
+            EventSystem.Instance.Awake(component, p1, p2, p3);
 
             this.AddToComponent(type, component);
 
-            return component;
+            return component as K;
         }
 
-        public void RemoveComponent<K>() where K : Entity
+        public T AddChild<T>(bool isFromPool = false) where T : Entity
         {
-            if (this.IsDisposed)
-            {
-                return;
-            }
+            Type type = typeof (T);
+            T component = (T) Entity.Create(type, isFromPool);
+            component.Id = IdGenerater.Instance.GenerateId();
+            component.Parent = this;
 
-            if (this.components == null)
-            {
-                return;
-            }
+            EventSystem.Instance.Awake(component);
+            return component;
+        }
 
-            Type type = typeof (K);
-            Entity c = this.GetComponent(type);
-            if (c == null)
-            {
-                return;
-            }
+        public T AddChild<T, A>(A a, bool isFromPool = false) where T : Entity
+        {
+            Type type = typeof (T);
+            T component = (T) Entity.Create(type, isFromPool);
+            component.Id = IdGenerater.Instance.GenerateId();
+            component.Parent = this;
 
-            this.RemoveFromComponent(type, c);
-            c.Dispose();
+            EventSystem.Instance.Awake(component, a);
+            return component;
         }
 
-        public void RemoveComponent(Entity component)
+        public T AddChild<T, A, B>(A a, B b, bool isFromPool = false) where T : Entity
         {
-            if (this.IsDisposed)
-            {
-                return;
-            }
+            Type type = typeof (T);
+            T component = (T) Entity.Create(type, isFromPool);
+            component.Id = IdGenerater.Instance.GenerateId();
+            component.Parent = parent;
 
-            if (this.components == null)
-            {
-                return;
-            }
-
-            Type type = component.GetType();
-            Entity c = this.GetComponent(component.GetType());
-            if (c == null)
-            {
-                return;
-            }
+            EventSystem.Instance.Awake(component, a, b);
+            return component;
+        }
 
-            if (c.InstanceId != component.InstanceId)
-            {
-                return;
-            }
+        public T AddChild<T, A, B, C>(A a, B b, C c, bool isFromPool = false) where T : Entity
+        {
+            Type type = typeof (T);
+            T component = (T) Entity.Create(type, isFromPool);
+            component.Id = IdGenerater.Instance.GenerateId();
+            component.Parent = this;
 
-            this.RemoveFromComponent(type, c);
-            c.Dispose();
+            EventSystem.Instance.Awake(component, a, b, c);
+            return component;
         }
 
-        public void RemoveComponent(Type type)
+        public T AddChild<T, A, B, C, D>(A a, B b, C c, D d, bool isFromPool = false) where T : Entity
         {
-            if (this.IsDisposed)
-            {
-                return;
-            }
+            Type type = typeof (T);
+            T component = (T) Entity.Create(type, isFromPool);
+            component.Id = IdGenerater.Instance.GenerateId();
+            component.Parent = this;
 
-            Entity c = this.GetComponent(type);
-            if (c == null)
-            {
-                return;
-            }
-
-            RemoveFromComponent(type, c);
-            c.Dispose();
+            EventSystem.Instance.Awake(component, a, b, c, d);
+            return component;
         }
 
-        public virtual K GetComponent<K>() where K : Entity
+        public T AddChildWithId<T>(long id, bool isFromPool = false) where T : Entity
         {
-            if (this.components == null)
-            {
-                return null;
-            }
+            Type type = typeof (T);
+            T component = (T) Entity.Create(type, isFromPool);
+            component.Id = id;
+            component.Parent = this;
 
-            Entity component;
-            if (!this.components.TryGetValue(typeof (K), out component))
-            {
-                return default;
-            }
+            EventSystem.Instance.Awake(component);
+            return component;
+        }
 
-            return (K) component;
+        public T AddChildWithId<T, A>(long id, A a, bool isFromPool = false) where T : Entity
+        {
+            Type type = typeof (T);
+            T component = (T) Entity.Create(type, isFromPool);
+            component.Id = id;
+            component.Parent = this;
+
+            EventSystem.Instance.Awake(component, a);
+            return component;
         }
 
-        public virtual Entity GetComponent(Type type)
+        public T AddChildWithId<T, A, B>(long id, A a, B b, bool isFromPool = false) where T : Entity
         {
-            if (this.components == null)
-            {
-                return null;
-            }
+            Type type = typeof (T);
+            T component = (T) Entity.Create(type, isFromPool);
+            component.Id = id;
+            component.Parent = this;
 
-            Entity component;
-            if (!this.components.TryGetValue(type, out component))
-            {
-                return null;
-            }
+            EventSystem.Instance.Awake(component, a, b);
+            return component;
+        }
+
+        public T AddChildWithId<T, A, B, C>(long id, A a, B b, C c, bool isFromPool = false) where T : Entity
+        {
+            Type type = typeof (T);
+            T component = (T) Entity.Create(type, isFromPool);
+            component.Id = id;
+            component.Parent = this;
 
+            EventSystem.Instance.Awake(component, a, b, c);
             return component;
         }
     }

+ 0 - 193
Unity/Assets/Model/Core/Object/EntityFactory.cs

@@ -1,193 +0,0 @@
-using System;
-
-namespace ET
-{
-    public partial class Entity
-    {
-        public static T Create<T>(Entity parent, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = IdGenerater.Instance.GenerateId();
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component);
-            return component;
-        }
-
-        public static T Create<T, A>(Entity parent, A a, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = IdGenerater.Instance.GenerateId();
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component, a);
-            return component;
-        }
-
-        public static T Create<T, A, B>(Entity parent, A a, B b, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = IdGenerater.Instance.GenerateId();
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component, a, b);
-            return component;
-        }
-
-        public static T Create<T, A, B, C>(Entity parent, A a, B b, C c, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = IdGenerater.Instance.GenerateId();
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component, a, b, c);
-            return component;
-        }
-
-        public static T Create<T, A, B, C, D>(Entity parent, A a, B b, C c, D d, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = IdGenerater.Instance.GenerateId();
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component, a, b, c, d);
-            return component;
-        }
-
-        public static T CreateWithId<T>(Entity parent, long id, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = id;
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component);
-            return component;
-        }
-
-        public static T CreateWithId<T, A>(Entity parent, long id, A a, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = id;
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component, a);
-            return component;
-        }
-
-        public static T CreateWithId<T, A, B>(Entity parent, long id, A a, B b, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = id;
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component, a, b);
-            return component;
-        }
-
-        public static T CreateWithId<T, A, B, C>(Entity parent, long id, A a, B b, C c, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = id;
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component, a, b, c);
-            return component;
-        }
-
-        public static T CreateWithId<T, A, B, C, D>(Entity parent, long id, A a, B b, C c, D d, bool isFromPool = false) where T : Entity
-        {
-            Type type = typeof (T);
-            T component = (T) Entity.Create(type, isFromPool);
-            component.Id = id;
-            component.Parent = parent;
-
-            EventSystem.Instance.Awake(component, a, b, c, d);
-            return component;
-        }
-        
-        private static Entity Create(Type type, bool isFromPool)
-        {
-            Entity component;
-            if (isFromPool)
-            {
-                component = (Entity)ObjectPool.Instance.Fetch(type);
-            }
-            else
-            {
-                component = (Entity)Activator.CreateInstance(type);
-            }
-            component.IsFromPool = isFromPool;
-            component.IsCreate = true;
-            component.Id = 0;
-            return component;
-        }
-		
-        private Entity CreateWithComponentParent(Type type, bool isFromPool = true)
-        {
-            Entity component = Create(type, isFromPool);
-			
-            component.Id = this.Id;
-            component.ComponentParent = this;
-			
-            EventSystem.Instance.Awake(component);
-            return component;
-        }
-
-        private T CreateWithComponentParent<T>(bool isFromPool = true) where T : Entity
-        {
-            Type type = typeof (T);
-            Entity component = Create(type, isFromPool);
-			
-            component.Id = this.Id;
-            component.ComponentParent = this;
-			
-            EventSystem.Instance.Awake(component);
-            return (T)component;
-        }
-
-        private T CreateWithComponentParent<T, A>(A a, bool isFromPool = true) where T : Entity
-        {
-            Type type = typeof (T);
-            Entity component = Create(type, isFromPool);
-			
-            component.Id = this.Id;
-            component.ComponentParent = this;
-			
-            EventSystem.Instance.Awake(component, a);
-            return (T)component;
-        }
-
-        private T CreateWithComponentParent<T, A, B>(A a, B b, bool isFromPool = true) where T : Entity
-        {
-            Type type = typeof (T);
-            Entity component = Create(type, isFromPool);
-			
-            component.Id = this.Id;
-            component.ComponentParent = this;
-			
-            EventSystem.Instance.Awake(component, a, b);
-            return (T)component;
-        }
-
-        private T CreateWithComponentParent<T, A, B, C>(A a, B b, C c, bool isFromPool = true) where T : Entity
-        {
-            Type type = typeof (T);
-            Entity component = Create(type, isFromPool);
-			
-            component.Id = this.Id;
-            component.ComponentParent = this;
-			
-            EventSystem.Instance.Awake(component, a, b, c);
-            return (T)component;
-        }
-    }
-}

+ 0 - 11
Unity/Assets/Model/Core/Object/EntityFactory.cs.meta

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

+ 3 - 3
Unity/Assets/Model/Module/CoroutineLock/CoroutineLockComponent.cs

@@ -10,7 +10,7 @@ namespace ET
             CoroutineLockComponent.Instance = self;
             for (int i = 0; i < self.list.Capacity; ++i)
             {
-                self.list.Add(Entity.CreateWithId<CoroutineLockQueueType>(self, ++self.idGenerator));
+                self.list.Add(self.AddChildWithId<CoroutineLockQueueType>(++self.idGenerator));
             }
         }
     }
@@ -123,7 +123,7 @@ namespace ET
    
             if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
             {
-                coroutineLockQueueType.Add(key, Entity.CreateWithId<CoroutineLockQueue>(self, ++self.idGenerator, true));
+                coroutineLockQueueType.Add(key, self.AddChildWithId<CoroutineLockQueue>(++self.idGenerator, true));
                 return self.CreateCoroutineLock(coroutineLockType, key, time, 1);
             }
 
@@ -135,7 +135,7 @@ namespace ET
 
         public static CoroutineLock CreateCoroutineLock(this CoroutineLockComponent self, CoroutineLockType coroutineLockType, long key, int time, int count)
         {
-            CoroutineLock coroutineLock = Entity.CreateWithId<CoroutineLock, CoroutineLockType, long, int>(self, ++self.idGenerator, coroutineLockType, key, count, true);
+            CoroutineLock coroutineLock = self.AddChildWithId<CoroutineLock, CoroutineLockType, long, int>(++self.idGenerator, coroutineLockType, key, count, true);
             if (time > 0)
             {
                 self.AddTimer(TimeHelper.ClientFrameTime() + time, coroutineLock);

+ 4 - 4
Unity/Assets/ModelView/Demo/Resource/ResourcesComponent.cs

@@ -401,7 +401,7 @@ namespace ET
 
                 if (realPath.Length > 0)
                 {
-                    abInfo = Entity.Create<ABInfo, string, AssetBundle>(this, assetBundleName, null);
+                    abInfo = this.AddChild<ABInfo, string, AssetBundle>(assetBundleName, null);
                     this.bundles[assetBundleName] = abInfo;
                     //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
                 }
@@ -442,7 +442,7 @@ namespace ET
                 }
             }
 
-            abInfo = Entity.Create<ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle);
+            abInfo = this.AddChild<ABInfo, string, AssetBundle>(assetBundleName, assetBundle);
             this.bundles[assetBundleName] = abInfo;
 
             //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
@@ -525,7 +525,7 @@ namespace ET
 
                 if (realPath.Length > 0)
                 {
-                    abInfo = Entity.Create<ABInfo, string, AssetBundle>(this, assetBundleName, null);
+                    abInfo = this.AddChild<ABInfo, string, AssetBundle>(assetBundleName, null);
                     this.bundles[assetBundleName] = abInfo;
                     //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
                 }
@@ -563,7 +563,7 @@ namespace ET
                 return null;
             }
 
-            abInfo = Entity.Create<ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle);
+            abInfo = this.AddChild<ABInfo, string, AssetBundle>(assetBundleName, assetBundle);
             this.bundles[assetBundleName] = abInfo;
             return abInfo;
             //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");

+ 1 - 1
Unity/Assets/ModelView/Module/UI/UI.cs

@@ -82,7 +82,7 @@ namespace ET
 			{
 				return null;
 			}
-			child = Entity.Create<UI, string, GameObject>(this, name, childGameObject);
+			child = this.AddChild<UI, string, GameObject>(name, childGameObject);
 			this.Add(child);
 			return child;
 		}