using Syntriax.Engine.Core.Abstract; using Syntriax.Engine.Core.Exceptions; namespace Syntriax.Engine.Core.Factory; public class HierarchyObjectFactory { public T Instantiate(params object?[]? args) where T : class, IHierarchyObject => Instantiate(behaviourController: null, stateEnable: null, args); public T Instantiate( IBehaviourController? behaviourController = null, IStateEnable? stateEnable = null, params object?[]? args ) where T : class, IHierarchyObject { T hierarchyObject = TypeFactory.Get(args); behaviourController ??= TypeFactory.Get(); stateEnable ??= TypeFactory.Get(); if (!behaviourController.Assign(hierarchyObject)) throw AssignException.From(behaviourController, hierarchyObject); if (!stateEnable.Assign(hierarchyObject)) throw AssignException.From(stateEnable, hierarchyObject); if (!hierarchyObject.Assign(behaviourController)) throw AssignException.From(hierarchyObject, behaviourController); if (!hierarchyObject.Assign(stateEnable)) throw AssignException.From(hierarchyObject, stateEnable); return hierarchyObject; } }