43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
using Syntriax.Engine.Core.Abstract;
|
|
using Syntriax.Engine.Core.Exceptions;
|
|
|
|
namespace Syntriax.Engine.Core.Factory;
|
|
|
|
public class GameObjectFactory
|
|
{
|
|
public T Instantiate<T>(params object?[]? args) where T : class, IGameObject
|
|
=> Instantiate<T>(transform: null, behaviourController: null, stateEnable: null, args);
|
|
|
|
public T Instantiate<T>(
|
|
ITransformWithGameObject? transform = null,
|
|
IBehaviourController? behaviourController = null,
|
|
IStateEnable? stateEnable = null,
|
|
params object?[]? args
|
|
)
|
|
where T : class, IGameObject
|
|
{
|
|
T gameObject = TypeFactory.Get<T>(args);
|
|
|
|
transform ??= TypeFactory.Get<TransformWithGameObject>();
|
|
behaviourController ??= TypeFactory.Get<BehaviourController>();
|
|
stateEnable ??= TypeFactory.Get<StateEnable>();
|
|
|
|
if (!transform.Assign(gameObject))
|
|
throw AssignException.From(transform, gameObject);
|
|
|
|
if (!behaviourController.Assign(gameObject))
|
|
throw AssignException.From(behaviourController, gameObject);
|
|
if (!stateEnable.Assign(gameObject))
|
|
throw AssignException.From(stateEnable, gameObject);
|
|
|
|
if (!gameObject.Assign(transform))
|
|
throw AssignException.From(gameObject, transform);
|
|
if (!gameObject.Assign(behaviourController))
|
|
throw AssignException.From(gameObject, behaviourController);
|
|
if (!gameObject.Assign(stateEnable))
|
|
throw AssignException.From(gameObject, stateEnable);
|
|
|
|
return gameObject;
|
|
}
|
|
}
|