//---------------------- json ---------------------------- public BehavTree LoadTree() { string filePath = UnityEditor.EditorUtility.OpenFilePanel("Load Behaviour tree", Application.dataPath, "json"); BehavTree tree = ReadTreeFromJson(filePath); return(tree); }
BehavTree ReadTreeFromJson(string path) { string jsonText = File.ReadAllText(path); JsonData json = JsonMapper.ToObject(jsonText); BNode root = ReadJsonNode(json); FileInfo file = new FileInfo(path); BehavTree tree = new BehavTree(file.Name); tree.SetRoot(root); return(tree); }
BehavTree LoadBehaviourTree() { string treePath = Application.dataPath + "/" + "Trees/test.json"; if (!File.Exists(treePath)) { Debug.LogError("behaviour tree file missed!"); return(null); } BehavTree tree = BehavTreeMagager.Instance.LoadTree(treePath); return(tree); }
public void SaveTree(BehavTree tree) { if (tree == null || tree.Root == null) { return; } string filePath = UnityEditor.EditorUtility.SaveFilePanel("Save Behaviour tree", Application.dataPath, "test", "json"); if (string.IsNullOrEmpty(filePath)) { return; } JsonData json = NodeToJson(tree.Root); string jsonStr = json.ToJson(); File.WriteAllText(filePath, jsonStr); UnityEditor.EditorUtility.DisplayDialog("Tip", "save succeed!", "OK"); }
//----------------- control ---------------------------- void DrawControls() { GUI.BeginGroup(new Rect(position.width - GUI_WIDTH, 0, 300, 1000)); currentX = 0; currentY = 0; if (m_curTree == null) { AddLabel(GUI_WIDTH, 20, "please Create or Load a tree."); NewLine(); } else { Instance.title = m_curTree.Name; if (m_curTree.Root == null) { AddLabel(GUI_WIDTH, 20, "try click the right mouse button."); NewLine(); } } AddButton(100, 40, "load tree", delegate(){ m_treeMap.Clear(); m_fieldValueCache.Clear(); m_curTree = BehavTreeMagager.Instance.LoadTree(); }); AddButton(100, 40, "create Tree", delegate(){ CreateTree(); }); NewLine(); AddButton(200, 40, "save Tree", delegate(){ BehavTreeMagager.Instance.SaveTree(m_curTree); }); NewLine(); if (m_treeMap.ContainsKey(m_selectRow)) { AddLabel(GUI_WIDTH, 20, "-------- Node info :---------"); NewLine(); DrawSelectNodeInfo(); } GUI.EndGroup(); }
// Use this for initialization void Start() { LoadSoldiers(); m_btree = LoadBehaviourTree(); }
public BehavTree LoadTree(string filePath) { BehavTree tree = ReadTreeFromJson(filePath); return(tree); }
// Use this for initialization void Start() { LoadMap(); LoadMonsters(); m_btree = LoadBehaviourTree(); }
void CreateTree() { m_treeMap.Clear(); m_fieldValueCache.Clear(); m_curTree = new BehavTree("untitled"); }