//创建行为树 private void CreateBev(BevTrees BevTrees) { //实体 foreach (string key in BevTrees.EntityTrees.Keys) { EntityReqId reqId = (EntityReqId)Enum.Parse(typeof(EntityReqId), key); //创建树 NodeDataJson nodeJson = BevTrees.EntityTrees[key]; Node rootNode = Node.CreateNodeInstance(nodeJson); Node.CreateNodeRelation(rootNode, nodeJson.ChildNodes); BaseEntityBehavior request = new BaseEntityBehavior(rootNode); EntityBevDict.Add((int)reqId, request); } //世界 foreach (string key in BevTrees.WorldTrees.Keys) { WorldReqId reqId = (WorldReqId)Enum.Parse(typeof(WorldReqId), key); //创建树 NodeDataJson nodeJson = BevTrees.WorldTrees[key]; Node rootNode = Node.CreateNodeInstance(nodeJson); Node.CreateNodeRelation(rootNode, nodeJson.ChildNodes); BaseWorldBehavior request = new BaseWorldBehavior(rootNode); WorldBevDict.Add((int)reqId, request); } }
public void Init() { TextAsset jsonData = ECSLocate.Factory.GetProduct <TextAsset>(FactoryType.Asset, null, ECSDefinitionPath.BevTreePath); BevTrees bevTrees = LitJson.JsonMapper.ToObject <BevTrees>(jsonData.text); SetBevTrees(bevTrees); }
private static void OpenWindow() { if (EDTool.CheckFileInPath(Application.dataPath + DecPath)) { string dataJson = EDTool.ReadText(Application.dataPath + DecPath); MDecTrees = LitJson.JsonMapper.ToObject <DecTrees>(dataJson); } else { MDecTrees = new DecTrees(); } if (EDTool.CheckFileInPath(Application.dataPath + BevPath)) { string dataJson = EDTool.ReadText(Application.dataPath + BevPath); MBevTrees = LitJson.JsonMapper.ToObject <BevTrees>(dataJson); } else { MBevTrees = new BevTrees(); } InitJson(); NodeEditorWindow window = GetWindow <NodeEditorWindow>(); window.titleContent = new GUIContent("决策及行为树编辑"); if (EditorApplication.isPlaying == true) { Timer = Time.realtimeSinceStartup; } }
private void OnDestroy() { SaveJson(); MDecTrees = null; MBevTrees = null; curConnectNode = null; ShowDec = true; }
//设置行为树 private void SetBevTrees(BevTrees trees) { if (trees == null) { return; } CreateBev(trees); }
private static void InitJson() { //决策 DecTrees TempDecTrees = new DecTrees(); TempDecTrees.NodeId = MDecTrees.NodeId; foreach (int group in Enum.GetValues(typeof(EntityDecGroup))) { string strName = Enum.GetName(typeof(EntityDecGroup), group); NodeDataJson oldJson = null; if (MDecTrees.EntityTrees.ContainsKey(strName)) { oldJson = MDecTrees.EntityTrees[strName]; } if (oldJson == null) { oldJson = CreateNodeJson(NodeType.Root, typeof(NodeRoot).FullName, "根节点"); } TempDecTrees.EntityTrees.Add(strName, oldJson); } foreach (int group in Enum.GetValues(typeof(WorldDecGroup))) { string strName = Enum.GetName(typeof(WorldDecGroup), group); NodeDataJson oldJson = null; if (MDecTrees.WorldTrees.ContainsKey(strName)) { oldJson = MDecTrees.WorldTrees[strName]; } if (oldJson == null) { oldJson = CreateNodeJson(NodeType.Root, typeof(NodeRoot).FullName, "根节点"); } TempDecTrees.WorldTrees.Add(strName, oldJson); } MDecTrees = TempDecTrees; //行为 BevTrees TempBevTrees = new BevTrees(); TempBevTrees.NodeId = MBevTrees.NodeId; foreach (int group in Enum.GetValues(typeof(EntityReqId))) { string strName = Enum.GetName(typeof(EntityReqId), group); NodeDataJson oldJson = null; if (MBevTrees.EntityTrees.ContainsKey(strName)) { oldJson = MBevTrees.EntityTrees[strName]; } if (oldJson == null) { oldJson = CreateNodeJson(NodeType.Root, typeof(NodeRoot).FullName, "根节点"); } TempBevTrees.EntityTrees.Add(strName, oldJson); } foreach (int group in Enum.GetValues(typeof(WorldReqId))) { string strName = Enum.GetName(typeof(WorldReqId), group); NodeDataJson oldJson = null; if (MBevTrees.WorldTrees.ContainsKey(strName)) { oldJson = MBevTrees.WorldTrees[strName]; } if (oldJson == null) { oldJson = CreateNodeJson(NodeType.Root, typeof(NodeRoot).FullName, "根节点"); } TempBevTrees.WorldTrees.Add(strName, oldJson); } MBevTrees = TempBevTrees; }