using LitJson; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using ZXKFramework; namespace FSM { public class FsmConfigReader { public Dictionary> map;//<状态名 ,<条件名,状态名>> public IEnumerator ReadConfigFile(string path, Action>> callBack) { map = new(); yield return Game.Instance.res.ILoad(path,text=> { if (text == null) return; List data = JsonMapper.ToObject>(text.text); for (int i = 0; i < data.Count; i++) { if (!map.ContainsKey(data[i]["state"].ToString())) { map.Add(data[i]["state"].ToString(), new Dictionary()); } if (!string.IsNullOrEmpty(data[i]["trigger"].ToString())) { string[] triggers = data[i]["trigger"].ToString().Replace("\n", "").Split('|'); for (int j = 0; j < triggers.Length; j++) { map[data[i]["state"].ToString()].Add(triggers[j].Split('>')[0], triggers[j].Split('>')[1]); } } } callBack?.Invoke(map); }); } public void EditorReadConfigFile(string path) { if (string.IsNullOrEmpty(path)) return; string str = Resources.Load(path).text; if (str == null) return; map = new(); List data = JsonMapper.ToObject>(str); for (int i = 0; i < data.Count; i++) { if (!map.ContainsKey(data[i]["state"].ToString())) { map.Add(data[i]["state"].ToString(), new Dictionary()); } string[] triggers = data[i]["trigger"].ToString().Replace("\n","").Split('|'); for (int j = 0; j < triggers.Length; j++) { if (!string.IsNullOrEmpty(triggers[j])) { map[data[i]["state"].ToString()].Add(triggers[j].Split('>')[0], triggers[j].Split('>')[1]); } } } } } }