using Engine.Core.Exceptions; namespace Engine.Core.Factory; public class BehaviourFactory { public static T Instantiate(params object?[]? args) where T : class, IBehaviour => Instantiate(stateEnable: null, args); public static T Instantiate(IStateEnable? stateEnable, params object?[]? args) where T : class, IBehaviour { T behaviour = TypeFactory.Get(args); if (stateEnable is not null) { if (!stateEnable.Assign(behaviour)) throw AssignFailedException.From(stateEnable, behaviour); if (!behaviour.Assign(stateEnable)) throw AssignFailedException.From(behaviour, stateEnable); } else StateEnableFactory.Instantiate(behaviour); return behaviour; } }