Syntriax.Engine/Engine.Core/Factory/GameObjectFactory.cs
Syntriax f729cdc0a8 revert: refactor: ITransformWithGameObject
This reverts commit f96c58cbd49f6612d44a138e294205576d26389f.
2024-02-07 11:45:14 +03:00

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>(
ITransform? transform = null,
IBehaviourController? behaviourController = null,
IStateEnable? stateEnable = null,
params object?[]? args
)
where T : class, IGameObject
{
T gameObject = TypeFactory.Get<T>(args);
transform ??= TypeFactory.Get<Transform>();
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;
}
}