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