About to remove events

This commit is contained in:
2026-02-08 15:07:02 -05:00
parent e987c8092f
commit 6f16a1170f
19 changed files with 209 additions and 168 deletions

View File

@@ -0,0 +1,28 @@
using System;
namespace Awperative;
public sealed partial class Body
{
public Component AddComponent<Generic>() where Generic : Component => AddComponent<Generic>([]);
public Component AddComponent<Generic>(object[] __args) where Generic : Component {
if (SingletonExists<Generic>()) { Debug.LogError("Cannot add component when singleton exists"); return null; }
if(typeof(Generic).GetConstructor((Type[]) __args) == null) { Debug.LogError("Component does not contain a valid constructor"); return null; };
try {
Component component = (Generic)Activator.CreateInstance(typeof(Generic), __args);
if(component == null) { Debug.LogError("Failed to create component"); return null; };
_components.Add(component);
component.Initiate(this);
ComponentCreatedEvent?.Invoke(this, new ComponentCreateEvent(component, this, Scene));
return component;
}catch { Debug.LogError("Failed to create component"); return null; }
}
}