using System; using System.Collections.Generic; using UnityEngine; namespace HK { public interface IProcedureManager { // void StartProcedure() where T : IProcedure; void StartProcedure(string procedureName); // void ChangeProcedure(); void ChangeProcedure(string procedureName); IProcedure GetProcedure(string procedureName); } internal class ProcedureManager : ManagerBase, IProcedureManager, IReference { private Dictionary _procedures = new Dictionary(); private IProcedure currentProcedure; public void AddProcedure(string procedureName, ProcedureBase procedureBase) { procedureBase.Init(); Debug.Log($"add procedure : {procedureBase.procedureType}"); this._procedures.Add(procedureName, procedureBase); } // public override void OnUpdate(float time,params object[] data) // { // base.OnUpdate(time,data); // this.currentProcedure?.OnUpdate(time); // } public void StartProcedure(string procedureName) { if (this.currentProcedure != null) this.currentProcedure.OnLeave(); if (this._procedures.TryGetValue(procedureName, out var procedure)) { this.currentProcedure = procedure; this.currentProcedure.OnEnter(); } } public void ChangeProcedure(string procedureName) { if (this.currentProcedure != null) this.currentProcedure.OnLeave(); if (this._procedures.TryGetValue(procedureName, out var procedure)) { this.currentProcedure = procedure; this.currentProcedure.OnEnter(); } } public IProcedure GetProcedure(string procedureName) { if (this._procedures.TryGetValue(procedureName, out var procedure)) { return procedure; } return null; } public void ClearProcedures() { this._procedures.Clear(); } public void Initialize() { // var types = new List<(Type, ProcedureAttribute)>(); // AssemblyManager.GetTypesInhertType(typeof(ProcedureBase), types); // foreach (var (type, procedureAttribute) in types) // { // var procedureType = procedureAttribute.ProcedureType; // _procedures.Add(procedureType, (IProcedure)Activator.CreateInstance(type, false)); // } // // foreach (var procedureBase in _procedures.Values) // { // procedureBase.Init(); // Debug.Log($"add procedure : {procedureBase.procedureType}"); // } } public void Dispose() { } } }