|
@@ -51,6 +51,22 @@ namespace ETModel
|
|
|
this.components.Clear();
|
|
this.components.Clear();
|
|
|
this.componentDict.Clear();
|
|
this.componentDict.Clear();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public Component AddComponent(Component component)
|
|
|
|
|
+ {
|
|
|
|
|
+ Type type = component.GetType();
|
|
|
|
|
+ if (this.componentDict.ContainsKey(type))
|
|
|
|
|
+ {
|
|
|
|
|
+ throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {type.Name}");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (component is ISerializeToEntity)
|
|
|
|
|
+ {
|
|
|
|
|
+ this.components.Add(component);
|
|
|
|
|
+ }
|
|
|
|
|
+ this.componentDict.Add(type, component);
|
|
|
|
|
+ return component;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
public Component AddComponent(Type type)
|
|
public Component AddComponent(Type type)
|
|
|
{
|
|
{
|
|
@@ -65,13 +81,14 @@ namespace ETModel
|
|
|
{
|
|
{
|
|
|
this.components.Add(component);
|
|
this.components.Add(component);
|
|
|
}
|
|
}
|
|
|
- this.componentDict.Add(component.GetType(), component);
|
|
|
|
|
|
|
+ this.componentDict.Add(type, component);
|
|
|
return component;
|
|
return component;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public K AddComponent<K>() where K : Component, new()
|
|
public K AddComponent<K>() where K : Component, new()
|
|
|
{
|
|
{
|
|
|
- if (this.componentDict.ContainsKey(typeof(K)))
|
|
|
|
|
|
|
+ Type type = typeof (K);
|
|
|
|
|
+ if (this.componentDict.ContainsKey(type))
|
|
|
{
|
|
{
|
|
|
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
|
|
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
|
|
|
}
|
|
}
|
|
@@ -82,13 +99,14 @@ namespace ETModel
|
|
|
{
|
|
{
|
|
|
this.components.Add(component);
|
|
this.components.Add(component);
|
|
|
}
|
|
}
|
|
|
- this.componentDict.Add(component.GetType(), component);
|
|
|
|
|
|
|
+ this.componentDict.Add(type, component);
|
|
|
return component;
|
|
return component;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public K AddComponent<K, P1>(P1 p1) where K : Component, new()
|
|
public K AddComponent<K, P1>(P1 p1) where K : Component, new()
|
|
|
{
|
|
{
|
|
|
- if (this.componentDict.ContainsKey(typeof(K)))
|
|
|
|
|
|
|
+ Type type = typeof (K);
|
|
|
|
|
+ if (this.componentDict.ContainsKey(type))
|
|
|
{
|
|
{
|
|
|
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
|
|
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
|
|
|
}
|
|
}
|
|
@@ -99,13 +117,14 @@ namespace ETModel
|
|
|
{
|
|
{
|
|
|
this.components.Add(component);
|
|
this.components.Add(component);
|
|
|
}
|
|
}
|
|
|
- this.componentDict.Add(component.GetType(), component);
|
|
|
|
|
|
|
+ this.componentDict.Add(type, component);
|
|
|
return component;
|
|
return component;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public K AddComponent<K, P1, P2>(P1 p1, P2 p2) where K : Component, new()
|
|
public K AddComponent<K, P1, P2>(P1 p1, P2 p2) where K : Component, new()
|
|
|
{
|
|
{
|
|
|
- if (this.componentDict.ContainsKey(typeof(K)))
|
|
|
|
|
|
|
+ Type type = typeof (K);
|
|
|
|
|
+ if (this.componentDict.ContainsKey(type))
|
|
|
{
|
|
{
|
|
|
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
|
|
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
|
|
|
}
|
|
}
|
|
@@ -116,13 +135,14 @@ namespace ETModel
|
|
|
{
|
|
{
|
|
|
this.components.Add(component);
|
|
this.components.Add(component);
|
|
|
}
|
|
}
|
|
|
- this.componentDict.Add(component.GetType(), component);
|
|
|
|
|
|
|
+ this.componentDict.Add(type, component);
|
|
|
return component;
|
|
return component;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3) where K : Component, new()
|
|
public K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3) where K : Component, new()
|
|
|
{
|
|
{
|
|
|
- if (this.componentDict.ContainsKey(typeof(K)))
|
|
|
|
|
|
|
+ Type type = typeof (K);
|
|
|
|
|
+ if (this.componentDict.ContainsKey(type))
|
|
|
{
|
|
{
|
|
|
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
|
|
throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
|
|
|
}
|
|
}
|
|
@@ -133,20 +153,21 @@ namespace ETModel
|
|
|
{
|
|
{
|
|
|
this.components.Add(component);
|
|
this.components.Add(component);
|
|
|
}
|
|
}
|
|
|
- this.componentDict.Add(component.GetType(), component);
|
|
|
|
|
|
|
+ this.componentDict.Add(type, component);
|
|
|
return component;
|
|
return component;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void RemoveComponent<K>() where K : Component
|
|
public void RemoveComponent<K>() where K : Component
|
|
|
{
|
|
{
|
|
|
|
|
+ Type type = typeof (K);
|
|
|
Component component;
|
|
Component component;
|
|
|
- if (!this.componentDict.TryGetValue(typeof(K), out component))
|
|
|
|
|
|
|
+ if (!this.componentDict.TryGetValue(type, out component))
|
|
|
{
|
|
{
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
this.components.Remove(component);
|
|
this.components.Remove(component);
|
|
|
- this.componentDict.Remove(typeof(K));
|
|
|
|
|
|
|
+ this.componentDict.Remove(type);
|
|
|
|
|
|
|
|
component.Dispose();
|
|
component.Dispose();
|
|
|
}
|
|
}
|