using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Exceptions; namespace Syntriax.Engine.Core.Factory; public class GameObjectFactory { public T Instantiate(params object?[]? args) where T : class, IGameObject => Instantiate(transform: null, behaviourController: null, stateEnable: null, args); public T Instantiate( ITransform? transform = null, IBehaviourController? behaviourController = null, IStateEnable? stateEnable = null, params object?[]? args ) where T : class, IGameObject { T gameObject = TypeFactory.Get(args); transform ??= TypeFactory.Get(); behaviourController ??= TypeFactory.Get(); stateEnable ??= TypeFactory.Get(); 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; } }