/// <summary>
        /// A static method to load existing graph into Chain Editor
        /// </summary>
        public static void LoadGraph()
        {
            string graphPath = EditorUtility.OpenFilePanel("Load Graph", cachedPath, "asset");

            if (string.IsNullOrWhiteSpace(graphPath))
            {
                return;
            }

            int    appPathLen = Application.dataPath.Length;
            string finalPath  = graphPath.Substring(appPathLen - 6);

            ChainGraph graph = AssetDatabase.LoadAssetAtPath(finalPath, typeof(ChainGraph)) as ChainGraph;

            if (graph != null)
            {
                ChainEditorWindow win = EditorWindow.GetWindow <ChainEditorWindow>();
                if (win != null)
                {
                    win.graph = graph;
                }
            }
            else
            {
                EditorUtility.DisplayDialog("Node Message", "Unable to load selected graph!", "OK");
            }
        }
        /// <summary>
        /// Open the ChainEditor window
        /// </summary>
        public static void Open()
        {
            ChainEditorWindow winTemp = GetWindow <ChainEditorWindow>("Behavior-Tree Editor");

            _win = winTemp;
            CreateViews();
        }
        /// <summary>
        ///  A static method to remove the graph in the Chain Editor
        /// </summary>
        public static void UnloadGraph()
        {
            ChainEditorWindow win = EditorWindow.GetWindow <ChainEditorWindow>();

            if (win != null)
            {
                win.graph = null;
            }
        }
 /// <summary>
 /// A static method to create the eidtor window's view spaces.
 /// </summary>
 static void CreateViews()
 {
     if (_win != null)
     {
         _win._workView     = new View_NodeWorkspace();
         _win._propertyView = new View_Property();
         _win._menubarView  = new View_MenuBar();
     }
     else
     {
         _win = GetWindow <ChainEditorWindow>(true, "Behavior-Tree Editor");
     }
 }
        /// <summary>
        /// A static method to create a new graph into Chain Editor based on a ActorModel
        /// </summary>
        /// <param name="model"></param>
        public static void CreateNewGraph(ActorModel model)
        {
            cachedPath = cachedPath == null ?  Application.dataPath: cachedPath;
            string graphPath = EditorUtility.SaveFilePanelInProject("Create Graph", "NewGraph", "", "Please enter a file name to save", cachedPath);

            if (string.IsNullOrWhiteSpace(graphPath))
            {
                return;
            }
            cachedPath = PathUtilities.GetLeafDirectories(graphPath).ToString();

            ChainGraph graph = ScriptableObject.CreateInstance <ChainGraph>();    // create a scriptableObject

            if (graph == null)
            {
                EditorUtility.DisplayDialog("Node Message", "Unable to create a new graph", "Ok");
            }

            if (!graphPath.Contains(".asset"))
            {
                graphPath += ".asset";
            }

            graph.InitGraph(model);

            AssetDatabase.CreateAsset(graph, graphPath); // create the asset
            AssetDatabase.SaveAssets();                  // save the asset
            AssetDatabase.Refresh();                     // after saving refresh to update

            ChainEditorWindow win = EditorWindow.GetWindow <ChainEditorWindow>();

            if (win != null)
            {
                win.graph = graph;
            }

            Vector2 rootNodePos = new Vector2(win._workView.viewRect.width / 2 - 50, win._workView.viewRect.height / 2 + 50);

            CreateNode(graph, NodeType.RootBehaviorNode, rootNodePos);
        }
Esempio n. 6
0
 public static void InitNodeEditor()
 {
     ChainEditorWindow.Open();
 }