28 lines
816 B
C#
28 lines
816 B
C#
using Engine.Core.Exceptions;
|
|
|
|
namespace 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);
|
|
|
|
if (stateEnable is not null)
|
|
{
|
|
if (!stateEnable.Assign(behaviour))
|
|
throw AssignFailedException.From(stateEnable, behaviour);
|
|
if (!behaviour.Assign(stateEnable))
|
|
throw AssignFailedException.From(behaviour, stateEnable);
|
|
}
|
|
else
|
|
StateEnableFactory.Instantiate(behaviour);
|
|
|
|
return behaviour;
|
|
}
|
|
}
|