diff --git a/Unity/Assets/Hotfix/Base/Object/Entity.cs b/Unity/Assets/Hotfix/Base/Object/Entity.cs index 1d3849792d4b4be1b717d2af8ccd50c0502b7492..92d2a610686f274474f875ffe079d476acb2c308 100644 --- a/Unity/Assets/Hotfix/Base/Object/Entity.cs +++ b/Unity/Assets/Hotfix/Base/Object/Entity.cs @@ -69,7 +69,7 @@ namespace ETHotfix throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {type.Name}"); } - Component component = ComponentFactory.CreateWithParent(type, this); + Component component = ComponentFactory.CreateWithParent(type, this, this.IsFromPool); this.componentDict.Add(type, component); return component; @@ -83,7 +83,7 @@ namespace ETHotfix throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } - K component = ComponentFactory.CreateWithParent(this); + K component = ComponentFactory.CreateWithParent(this, this.IsFromPool); this.componentDict.Add(type, component); return component; @@ -97,7 +97,7 @@ namespace ETHotfix throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } - K component = ComponentFactory.CreateWithParent(this, p1); + K component = ComponentFactory.CreateWithParent(this, p1, this.IsFromPool); this.componentDict.Add(type, component); return component; @@ -111,7 +111,7 @@ namespace ETHotfix throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } - K component = ComponentFactory.CreateWithParent(this, p1, p2); + K component = ComponentFactory.CreateWithParent(this, p1, p2, this.IsFromPool); this.componentDict.Add(type, component); return component; @@ -125,7 +125,7 @@ namespace ETHotfix throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } - K component = ComponentFactory.CreateWithParent(this, p1, p2, p3); + K component = ComponentFactory.CreateWithParent(this, p1, p2, p3, this.IsFromPool); this.componentDict.Add(type, component); return component; diff --git a/Unity/Assets/Hotfix/Base/Object/ObjectPool.cs b/Unity/Assets/Hotfix/Base/Object/ObjectPool.cs index 1c94140b5423e1b7db1dfc0beb1ffdd2ad7f3be4..d7b6378a45c2ab40edc4f03e25748eec8954cb4c 100644 --- a/Unity/Assets/Hotfix/Base/Object/ObjectPool.cs +++ b/Unity/Assets/Hotfix/Base/Object/ObjectPool.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace ETHotfix { - public class ObjectPool + public class ObjectPool: Component { private readonly Dictionary> dictionary = new Dictionary>(); @@ -36,6 +36,7 @@ namespace ETHotfix public void Recycle(Component obj) { + obj.Parent = this; Type type = obj.GetType(); Queue queue; if (!this.dictionary.TryGetValue(type, out queue)) diff --git a/Unity/Assets/Hotfix/Entity/Game.cs b/Unity/Assets/Hotfix/Entity/Game.cs index 17dc37542b9f4cfbe983919dae2a4eb8f47fb8f9..3effbe2d8866d8d7a619afe0ef76ae1ed19231a8 100644 --- a/Unity/Assets/Hotfix/Entity/Game.cs +++ b/Unity/Assets/Hotfix/Entity/Game.cs @@ -1,7 +1,19 @@ -namespace ETHotfix +using UnityEngine; + +namespace ETHotfix { public static class Game { + private static EventSystem eventSystem; + + public static EventSystem EventSystem + { + get + { + return eventSystem ?? (eventSystem = new EventSystem()); + } + } + private static Scene scene; public static Scene Scene @@ -18,23 +30,19 @@ } } - private static EventSystem eventSystem; - - public static EventSystem EventSystem - { - get - { - return eventSystem ?? (eventSystem = new EventSystem()); - } - } - private static ObjectPool objectPool; public static ObjectPool ObjectPool { get { - return objectPool ?? (objectPool = new ObjectPool()); + if (objectPool != null) + { + return objectPool; + } + objectPool = new ObjectPool(); + objectPool.GameObject.transform.SetParent(GameObject.Find("/Global").transform); + return objectPool; } } @@ -43,6 +51,7 @@ scene.Dispose(); scene = null; eventSystem = null; + objectPool.Dispose(); objectPool = null; } } diff --git a/Unity/Assets/Model/Base/Object/Entity.cs b/Unity/Assets/Model/Base/Object/Entity.cs index c5d653b8e7d673e53c6a40d549b275d6520d10b2..b49479e729a40b5f5a0e2c6b3927cd2867019e7d 100644 --- a/Unity/Assets/Model/Base/Object/Entity.cs +++ b/Unity/Assets/Model/Base/Object/Entity.cs @@ -69,7 +69,7 @@ namespace ETModel throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {type.Name}"); } - Component component = ComponentFactory.CreateWithParent(type, this); + Component component = ComponentFactory.CreateWithParent(type, this, this.IsFromPool); this.componentDict.Add(type, component); return component; @@ -83,7 +83,7 @@ namespace ETModel throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } - K component = ComponentFactory.CreateWithParent(this); + K component = ComponentFactory.CreateWithParent(this, this.IsFromPool); this.componentDict.Add(type, component); return component; @@ -97,7 +97,7 @@ namespace ETModel throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } - K component = ComponentFactory.CreateWithParent(this, p1); + K component = ComponentFactory.CreateWithParent(this, p1, this.IsFromPool); this.componentDict.Add(type, component); return component; @@ -111,7 +111,7 @@ namespace ETModel throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } - K component = ComponentFactory.CreateWithParent(this, p1, p2); + K component = ComponentFactory.CreateWithParent(this, p1, p2, this.IsFromPool); this.componentDict.Add(type, component); return component; @@ -125,7 +125,7 @@ namespace ETModel throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}"); } - K component = ComponentFactory.CreateWithParent(this, p1, p2, p3); + K component = ComponentFactory.CreateWithParent(this, p1, p2, p3, this.IsFromPool); this.componentDict.Add(type, component); return component; diff --git a/Unity/Assets/Model/Base/Object/ObjectPool.cs b/Unity/Assets/Model/Base/Object/ObjectPool.cs index a94012e17bdff481f8cccbfe70fd2f9b9907693a..71a5755ac79a38d6d1f86e4c503fd882542a97c4 100644 --- a/Unity/Assets/Model/Base/Object/ObjectPool.cs +++ b/Unity/Assets/Model/Base/Object/ObjectPool.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace ETModel { - public class ObjectPool + public class ObjectPool: Component { private readonly Dictionary> dictionary = new Dictionary>(); @@ -36,6 +36,7 @@ namespace ETModel public void Recycle(Component obj) { + obj.Parent = this; Type type = obj.GetType(); Queue queue; if (!this.dictionary.TryGetValue(type, out queue)) diff --git a/Unity/Assets/Model/Component/SceneChangeComponent.cs b/Unity/Assets/Model/Component/SceneChangeComponent.cs index 0545fd6fc37e3e4d6e34a75c4f38bf7d2005fd1a..ed1a9cde59043512bfcbd09df9c7a47d5f38c75e 100644 --- a/Unity/Assets/Model/Component/SceneChangeComponent.cs +++ b/Unity/Assets/Model/Component/SceneChangeComponent.cs @@ -53,14 +53,13 @@ namespace ETModel { return; } - base.Dispose(); if (this.Entity.IsDisposed) { - return; + this.Entity.RemoveComponent(); } - - this.Entity.RemoveComponent(); + + base.Dispose(); } } } \ No newline at end of file diff --git a/Unity/Assets/Model/Entity/Game.cs b/Unity/Assets/Model/Entity/Game.cs index 07153f2c69c620ac2ecaa6e8735b0e6fb2add3c9..f35a2b9a6db2177df207d24a1a06a11126abda21 100644 --- a/Unity/Assets/Model/Entity/Game.cs +++ b/Unity/Assets/Model/Entity/Game.cs @@ -1,7 +1,19 @@ -namespace ETModel +using UnityEngine; + +namespace ETModel { public static class Game { + private static EventSystem eventSystem; + + public static EventSystem EventSystem + { + get + { + return eventSystem ?? (eventSystem = new EventSystem()); + } + } + private static Scene scene; public static Scene Scene @@ -13,28 +25,24 @@ return scene; } scene = new Scene(); - scene.GameObject.transform.SetParent(scene.GameObject.transform.Find("/Global")); + scene.GameObject.transform.SetParent(GameObject.Find("/Global").transform); return scene; } } - private static EventSystem eventSystem; - - public static EventSystem EventSystem - { - get - { - return eventSystem ?? (eventSystem = new EventSystem()); - } - } - private static ObjectPool objectPool; public static ObjectPool ObjectPool { get { - return objectPool ?? (objectPool = new ObjectPool()); + if (objectPool != null) + { + return objectPool; + } + objectPool = new ObjectPool(); + objectPool.GameObject.transform.SetParent(GameObject.Find("/Global").transform); + return objectPool; } } @@ -50,10 +58,14 @@ public static void Close() { - scene.Dispose(); eventSystem = null; + + scene.Dispose(); scene = null; + + objectPool.Dispose(); objectPool = null; + hotfix = null; } } diff --git a/Unity/Assets/Model/Module/Message/Session.cs b/Unity/Assets/Model/Module/Message/Session.cs index ba739e3eea7170e31302b3bf03fca5fd051c7c36..f0dffe58518c080ec12aca64a781408e482c6d0d 100644 --- a/Unity/Assets/Model/Module/Message/Session.cs +++ b/Unity/Assets/Model/Module/Message/Session.cs @@ -64,8 +64,8 @@ namespace ETModel return; } - long id = this.Id; - + this.Network.Remove(this.Id); + base.Dispose(); foreach (Action action in this.requestCallback.Values.ToArray()) @@ -80,7 +80,6 @@ namespace ETModel //} this.channel.Dispose(); - this.Network.Remove(id); this.requestCallback.Clear(); } diff --git a/Unity/Assets/Res/Code/Hotfix.mdb.bytes b/Unity/Assets/Res/Code/Hotfix.mdb.bytes deleted file mode 100644 index 36614963dc1c24792c4a654a57158373f40f7084..0000000000000000000000000000000000000000 Binary files a/Unity/Assets/Res/Code/Hotfix.mdb.bytes and /dev/null differ