Awperative Completely Reworked!
This commit is contained in:
23
Awperative/Kernel/Docker/Addition.cs
Normal file
23
Awperative/Kernel/Docker/Addition.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace Awperative;
|
||||
|
||||
public abstract partial class Docker
|
||||
{
|
||||
|
||||
public Behavior Add<Generic>() where Generic : Behavior => Add<Generic>([]);
|
||||
public Behavior Add<Generic>(object[] __args) where Generic : Behavior {
|
||||
if(typeof(Generic).GetConstructor((Type[]) __args) == null) { Debug.LogError("Component does not contain a valid constructor"); return null; };
|
||||
|
||||
try {
|
||||
Behavior behavior = (Generic)Activator.CreateInstance(typeof(Generic), __args);
|
||||
|
||||
if(behavior == null) { Debug.LogError("Failed to create component"); return null; }
|
||||
|
||||
_components.Add(behavior);
|
||||
behavior.Initiate(this);
|
||||
return behavior;
|
||||
|
||||
}catch { Debug.LogError("Failed to create component"); return null; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user