|
@@ -547,6 +547,123 @@ namespace ET
|
|
|
return child as K;
|
|
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)
|
|
public Entity AddComponent(Entity component)
|
|
|
{
|
|
{
|
|
|
Type type = component.GetType();
|
|
Type type = component.GetType();
|
|
@@ -562,21 +679,24 @@ namespace ET
|
|
|
return component;
|
|
return component;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public Entity AddComponent(Type type)
|
|
|
|
|
|
|
+ public Entity AddComponent(Type type, bool isFromPool = false)
|
|
|
{
|
|
{
|
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
|
{
|
|
{
|
|
|
throw new Exception($"entity already has component: {type.FullName}");
|
|
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);
|
|
this.AddToComponent(type, component);
|
|
|
|
|
|
|
|
return 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);
|
|
Type type = typeof (K);
|
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
@@ -584,14 +704,17 @@ namespace ET
|
|
|
throw new Exception($"entity already has component: {type.FullName}");
|
|
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);
|
|
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);
|
|
Type type = typeof (K);
|
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
@@ -599,14 +722,17 @@ namespace ET
|
|
|
throw new Exception($"entity already has component: {type.FullName}");
|
|
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);
|
|
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);
|
|
Type type = typeof (K);
|
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
@@ -614,14 +740,17 @@ namespace ET
|
|
|
throw new Exception($"entity already has component: {type.FullName}");
|
|
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);
|
|
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);
|
|
Type type = typeof (K);
|
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
if (this.components != null && this.components.ContainsKey(type))
|
|
@@ -629,110 +758,112 @@ namespace ET
|
|
|
throw new Exception($"entity already has component: {type.FullName}");
|
|
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);
|
|
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;
|
|
return component;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|