35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using Engine.Core.Exceptions;
|
|
|
|
namespace Engine.Core.Factory;
|
|
|
|
public class BehaviourControllerFactory
|
|
{
|
|
public static IBehaviourController Instantiate(IUniverseObject universeObject, IStateEnable? stateEnable = null)
|
|
=> Instantiate<BehaviourController>(universeObject, stateEnable);
|
|
|
|
public static T Instantiate<T>(IUniverseObject universeObject, IStateEnable? stateEnable = null, params object?[]? args)
|
|
where T : class, IBehaviourController
|
|
{
|
|
T behaviourController = TypeFactory.Get<T>(args);
|
|
|
|
if (!universeObject.Assign(behaviourController))
|
|
throw AssignFailedException.From(universeObject, behaviourController);
|
|
|
|
if (!behaviourController.Assign(universeObject))
|
|
throw AssignFailedException.From(behaviourController, universeObject);
|
|
|
|
if (stateEnable is not null)
|
|
{
|
|
if (!stateEnable.Assign(behaviourController))
|
|
throw AssignFailedException.From(stateEnable, behaviourController);
|
|
|
|
if (!behaviourController.Assign(stateEnable))
|
|
throw AssignFailedException.From(behaviourController, stateEnable);
|
|
}
|
|
else
|
|
StateEnableFactory.Instantiate(behaviourController);
|
|
|
|
return behaviourController;
|
|
}
|
|
}
|