25 lines
750 B
C#
25 lines
750 B
C#
using Syntriax.Engine.Core.Exceptions;
|
|
|
|
namespace Syntriax.Engine.Core.Factory;
|
|
|
|
public class BehaviourFactory
|
|
{
|
|
public static T Instantiate<T>(params object?[]? args) where T : class, IBehaviour
|
|
=> Instantiate<T>(stateEnable: null, args);
|
|
|
|
public static T Instantiate<T>(IStateEnable? stateEnable, params object?[]? args)
|
|
where T : class, IBehaviour
|
|
{
|
|
T behaviour = TypeFactory.Get<T>(args);
|
|
|
|
stateEnable ??= TypeFactory.Get<StateEnable>();
|
|
if (!stateEnable.Assign(behaviour))
|
|
throw AssignFailedException.From(stateEnable, behaviour);
|
|
|
|
if (!behaviour.Assign(stateEnable))
|
|
throw AssignFailedException.From(behaviour, stateEnable);
|
|
|
|
return behaviour;
|
|
}
|
|
}
|