36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using Syntriax.Engine.Core.Abstract;
|
|
using Syntriax.Engine.Core.Exceptions;
|
|
|
|
namespace Syntriax.Engine.Core.Factory;
|
|
|
|
public class HierarchyObjectFactory
|
|
{
|
|
public static T Instantiate<T>(params object?[]? args) where T : class, IHierarchyObject
|
|
=> Instantiate<T>(behaviourController: null, stateEnable: null, args);
|
|
|
|
public static T Instantiate<T>(
|
|
IBehaviourController? behaviourController = null,
|
|
IStateEnable? stateEnable = null,
|
|
params object?[]? args
|
|
)
|
|
where T : class, IHierarchyObject
|
|
{
|
|
T hierarchyObject = TypeFactory.Get<T>(args);
|
|
|
|
behaviourController ??= TypeFactory.Get<BehaviourController>();
|
|
stateEnable ??= TypeFactory.Get<StateEnable>();
|
|
|
|
if (!behaviourController.Assign(hierarchyObject))
|
|
throw AssignException.From(behaviourController, hierarchyObject);
|
|
if (!stateEnable.Assign(hierarchyObject))
|
|
throw AssignException.From(stateEnable, hierarchyObject);
|
|
|
|
if (!hierarchyObject.Assign(behaviourController))
|
|
throw AssignException.From(hierarchyObject, behaviourController);
|
|
if (!hierarchyObject.Assign(stateEnable))
|
|
throw AssignException.From(hierarchyObject, stateEnable);
|
|
|
|
return hierarchyObject;
|
|
}
|
|
}
|