chore: Added Initial Engine Code
This commit is contained in:
27
Engine.Core/Factory/BehaviourFactory.cs
Normal file
27
Engine.Core/Factory/BehaviourFactory.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user