aa
This commit is contained in:
@@ -12,15 +12,12 @@ public sealed partial class Body
|
|||||||
if(typeof(Generic).GetConstructor((Type[]) __args) == null) { Debug.LogError("Component does not contain a valid constructor"); return null; };
|
if(typeof(Generic).GetConstructor((Type[]) __args) == null) { Debug.LogError("Component does not contain a valid constructor"); return null; };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Component component = (Generic)Activator.CreateInstance(typeof(Generic), __args);
|
Component component = (Generic)Activator.CreateInstance(typeof(Generic), __args);
|
||||||
|
|
||||||
if(component == null) { Debug.LogError("Failed to create component"); return null; };
|
if(component == null) { Debug.LogError("Failed to create component"); return null; }
|
||||||
|
|
||||||
_components.Add(component);
|
_components.Add(component);
|
||||||
component.Initiate(this);
|
component.Initiate(this);
|
||||||
ComponentCreatedEvent?.Invoke(this, new ComponentCreateEvent(component, this, Scene));
|
|
||||||
|
|
||||||
return component;
|
return component;
|
||||||
|
|
||||||
}catch { Debug.LogError("Failed to create component"); return null; }
|
}catch { Debug.LogError("Failed to create component"); return null; }
|
||||||
|
|||||||
@@ -17,16 +17,17 @@ public sealed partial class Body
|
|||||||
return returnValue.ToArray();
|
return returnValue.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Generic FindSingleton<Generic>() where Generic : Component
|
public Component FindSingleton<Generic>() where Generic : Component {
|
||||||
{
|
|
||||||
foreach (Component component in _components)
|
foreach (Component component in _components)
|
||||||
if (component.GetType() == typeof(Generic))
|
if (component.GetType() == typeof(Generic))
|
||||||
if(component.EnforceSingleton)
|
if(component.EnforceSingleton)
|
||||||
return (Generic) component;
|
return component;
|
||||||
else
|
else {
|
||||||
throw new Exception("Component is not a singleton");
|
Debug.LogError("Component is not a singleton");
|
||||||
|
return null;
|
||||||
throw new Exception("Component not found");
|
}
|
||||||
|
|
||||||
|
Debug.LogError("Scene does not contain a component of this type");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ public sealed partial class Body
|
|||||||
|
|
||||||
foundComponent.End();
|
foundComponent.End();
|
||||||
_components.Remove(foundComponent);
|
_components.Remove(foundComponent);
|
||||||
ComponentDestroyedEvent?.Invoke(this, new ComponentDestroyEvent(foundComponent, this, Scene));
|
|
||||||
}catch { Debug.LogError("Removal failed"); }
|
}catch { Debug.LogError("Removal failed"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +25,6 @@ public sealed partial class Body
|
|||||||
foreach (Component component in GetComponents<Generic>()) {
|
foreach (Component component in GetComponents<Generic>()) {
|
||||||
component.End();
|
component.End();
|
||||||
_components.Remove(component);
|
_components.Remove(component);
|
||||||
ComponentDestroyedEvent?.Invoke(this, new ComponentDestroyEvent(component, this, Scene));
|
|
||||||
}
|
}
|
||||||
}catch { Debug.LogError("Removal failed"); }
|
}catch { Debug.LogError("Removal failed"); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
|
|
||||||
namespace Awperative;
|
|
||||||
|
|
||||||
public sealed partial class Body
|
|
||||||
{
|
|
||||||
public event EventHandler<ComponentCreateEvent> ComponentCreatedEvent;
|
|
||||||
public event EventHandler<ComponentDestroyEvent> ComponentDestroyedEvent;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user