修改fsm

This commit is contained in:
2025-04-10 11:20:22 +08:00
parent 12f86c6eac
commit e3afd4acac
16 changed files with 229 additions and 403 deletions

View File

@@ -0,0 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Stary.Evo.FiniteStateMachine
{
public static class FSMInitialize
{
private static Dictionary<string, FSMController> _fsmControllers =
new Dictionary<string, FSMController>();
/// <summary>
/// 创建FSMController
/// </summary>
/// <returns>返回创建的FSMController的识别Int值</returns>
public static void CreateFSMController<T>(Transform parent) where T : FSMController
{
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<T>();
_fsmControllers.Add(typeof(T).Name, controller);
}
}
/// <summary>
/// 销毁指定FSMController
/// </summary>
/// <param name="controllerId"></param>
public static void DestroyFSMController<T>() where T : FSMController
{
if (_fsmControllers.TryGetValue(typeof(T).Name, out var controller))
{
GameObject.Destroy(controller.gameObject);
_fsmControllers.Remove(typeof(T).Name);
}
else
{
Debug.LogError("该Id的FSMController不存在或已被销毁");
}
}
}
}