using Syntriax.Engine.Core.Exceptions; namespace Syntriax.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); stateEnable ??= TypeFactory.Get(); if (!stateEnable.Assign(behaviour)) throw AssignFailedException.From(stateEnable, behaviour); if (!behaviour.Assign(stateEnable)) throw AssignFailedException.From(behaviour, stateEnable); return behaviour; } }