Example #1
0
        public static void CreateGraph(string _wantedName, string _path)
        {
            NodeGraph curGraph = ScriptableObject.CreateInstance <NodeGraph>() as NodeGraph;

            if (curGraph != null)
            {
                curGraph.SetGraphName(_wantedName);
                curGraph.InitGraph();

                if (string.IsNullOrEmpty(_path))
                {
                    _path = "Assets/BTNodeEditor/Database";
                }

                AssetDatabase.CreateAsset(curGraph, _path + "/" + curGraph.GetGraphName() + ".asset");
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();

                NodeEditorWindow curWindow = EditorWindow.GetWindow <NodeEditorWindow>() as NodeEditorWindow;
                if (curWindow != null)
                {
                    curWindow.SetCurrentGraph(curGraph);
                    //CreateNode(curGraph, NodeType.ROOT_NODE, curWindow.GetMainView().GetViewRect().center);
                }
                else
                {
                    EditorUtility.DisplayDialog("Error Something Worng", "Wasnt able to the set current graph variable for the NodeEditorWindow", "Ok");
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Error Something Worng", "Wasnt able to create a new graph. See ur friendly programmer", "Ok");
            }
        }
Example #2
0
        public static void UnloadGraph()
        {
            NodeEditorWindow curWindow = EditorWindow.GetWindow <NodeEditorWindow>() as NodeEditorWindow;

            if (curWindow != null)
            {
                curWindow.SetCurrentGraph(null);
            }
            else
            {
                EditorUtility.DisplayDialog("Error Something Worng", "Something went wrong in getting the current window", "Ok");
            }
            curWindow.Repaint();
        }
Example #3
0
        public static void LoadGraph()
        {
            NodeGraph curGraph   = null;
            string    pathToLoad = EditorUtility.OpenFilePanel("Load BehaviourTree", "Asset/", "");

            int    appPathLen = Application.dataPath.Length;
            string fullPath   = pathToLoad.Substring(appPathLen - 6);

            curGraph = AssetDatabase.LoadAssetAtPath(fullPath, typeof(NodeGraph)) as NodeGraph;
            if (curGraph != null)
            {
                NodeEditorWindow curWindow = EditorWindow.GetWindow <NodeEditorWindow>() as NodeEditorWindow;
                if (curWindow != null)
                {
                    curWindow.SetCurrentGraph(curGraph);
                }
            }
        }