Finished docking
This commit is contained in:
23
Awperative/Kernel/Entities/DockerEntity/Addition.cs
Normal file
23
Awperative/Kernel/Entities/DockerEntity/Addition.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace Awperative;
|
||||
|
||||
public abstract partial class DockerEntity
|
||||
{
|
||||
|
||||
public Component AddComponent<Generic>() where Generic : Component => AddComponent<Generic>([]);
|
||||
public Component AddComponent<Generic>(object[] __args) where Generic : Component {
|
||||
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);
|
||||
return component;
|
||||
|
||||
}catch { Debug.LogError("Failed to create component"); return null; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user