提交 a883cffe 编写于 作者: T tanghai

修改对象池机制,如果Entity没有使用对象池,那么挂载组件也不使用对象池

上级 a064917d
......@@ -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<K>(this);
K component = ComponentFactory.CreateWithParent<K>(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<K, P1>(this, p1);
K component = ComponentFactory.CreateWithParent<K, P1>(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<K, P1, P2>(this, p1, p2);
K component = ComponentFactory.CreateWithParent<K, P1, P2>(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<K, P1, P2, P3>(this, p1, p2, p3);
K component = ComponentFactory.CreateWithParent<K, P1, P2, P3>(this, p1, p2, p3, this.IsFromPool);
this.componentDict.Add(type, component);
return component;
......
......@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace ETHotfix
{
public class ObjectPool
public class ObjectPool: Component
{
private readonly Dictionary<Type, Queue<Component>> dictionary = new Dictionary<Type, Queue<Component>>();
......@@ -36,6 +36,7 @@ namespace ETHotfix
public void Recycle(Component obj)
{
obj.Parent = this;
Type type = obj.GetType();
Queue<Component> queue;
if (!this.dictionary.TryGetValue(type, out queue))
......
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;
}
}
......
......@@ -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<K>(this);
K component = ComponentFactory.CreateWithParent<K>(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<K, P1>(this, p1);
K component = ComponentFactory.CreateWithParent<K, P1>(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<K, P1, P2>(this, p1, p2);
K component = ComponentFactory.CreateWithParent<K, P1, P2>(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<K, P1, P2, P3>(this, p1, p2, p3);
K component = ComponentFactory.CreateWithParent<K, P1, P2, P3>(this, p1, p2, p3, this.IsFromPool);
this.componentDict.Add(type, component);
return component;
......
......@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace ETModel
{
public class ObjectPool
public class ObjectPool: Component
{
private readonly Dictionary<Type, Queue<Component>> dictionary = new Dictionary<Type, Queue<Component>>();
......@@ -36,6 +36,7 @@ namespace ETModel
public void Recycle(Component obj)
{
obj.Parent = this;
Type type = obj.GetType();
Queue<Component> queue;
if (!this.dictionary.TryGetValue(type, out queue))
......
......@@ -53,14 +53,13 @@ namespace ETModel
{
return;
}
base.Dispose();
if (this.Entity.IsDisposed)
{
return;
this.Entity.RemoveComponent<SceneChangeComponent>();
}
this.Entity.RemoveComponent<SceneChangeComponent>();
base.Dispose();
}
}
}
\ No newline at end of file
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;
}
}
......
......@@ -64,8 +64,8 @@ namespace ETModel
return;
}
long id = this.Id;
this.Network.Remove(this.Id);
base.Dispose();
foreach (Action<IResponse> action in this.requestCallback.Values.ToArray())
......@@ -80,7 +80,6 @@ namespace ETModel
//}
this.channel.Dispose();
this.Network.Remove(id);
this.requestCallback.Clear();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册