using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.SceneManagement; namespace Stary.Evo.FiniteStateMachine { public static class FSMExtension { private static Dictionary _fsmControllers = new Dictionary(); /// /// 创建FSMController /// /// 返回创建的FSMController的识别Int值 public static void CreateFSMController(Transform parent) where T : AbstractFSMController { if (_fsmControllers.ContainsKey(typeof(T).Name)) { Debug.LogError($"FSM控制器已存在!!!_key:{typeof(T).Name}"); } else { GameObject newController = new GameObject($"{typeof(T).Name}"); newController.transform.SetParent(parent); var controller = newController.AddComponent(); _fsmControllers.Add(typeof(T).Name, controller); } } /// /// 销毁指定FSMController /// /// public static void DestroyFSMController() where T : AbstractFSMController { if (_fsmControllers.TryGetValue(typeof(T).Name, out var controller)) { GameObject.Destroy(controller.gameObject); _fsmControllers.Remove(typeof(T).Name); } else { Debug.LogError("该Id的FSMController不存在或已被销毁!!!"); } } } }