public static void LoadGraph()
        {
            AG_Graph nodeGraph = null;

            int    appPathLength         = Application.dataPath.Length;
            string dataPathWithoutAssets = Application.dataPath.Substring(0, appPathLength - 6);

//			Debug.Log (dataPathWithoutAssets + ConstantKeys.DataPath_GameFlow);

            string graphPath = EditorUtility.OpenFilePanel("Load Graph", dataPathWithoutAssets + ConstantKeys.DataPath_GameFlow,
                                                           "asset");

            string finalPath = graphPath.Substring(appPathLength - 6);

            nodeGraph = (AG_Graph)AssetDatabase.LoadAssetAtPath(finalPath, typeof(AG_Graph));

            if (nodeGraph == null)
            {
                EditorUtility.DisplayDialog("Node Message:", "Unable to load the graph", "OK");
            }

            var currentNodeEditorWindow = EditorWindow.GetWindow <AG_GameFlowMainWindow>();

            currentNodeEditorWindow.currentGraph = nodeGraph;
        }
        private void OnGUI()
        {
            GUILayout.Space(10);
            GUILayout.BeginHorizontal();
            GUILayout.Space(10);

            GUILayout.BeginVertical();

            EditorGUILayout.LabelField("Create New Graph", EditorStyles.boldLabel);

            wantedName = EditorGUILayout.TextField("Enter Name: ", wantedName);

            GUILayout.Space(10);

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("Create Graph", GUILayout.Height(40f)))
            {
                if (!string.IsNullOrEmpty(wantedName) && wantedName != "Enter a name...")
                {
//					NodeUtils.CreateNodeGraph(wantedName);
                    var currentWorkView = AG_GameFlowMainWindow.currentWindow = EditorWindow.GetWindow <AG_GameFlowMainWindow>();
                    if (currentWorkView != null)
                    {
                        currentWorkView.currentGraph = AG_Graph.CreateNodeGraph(wantedName);

                        if (currentWorkView.currentGraph != null)
                        {
                            AssetDatabase.CreateAsset(currentWorkView.currentGraph, ConstantKeys.DataPath_GameFlow + currentWorkView.currentGraph.graphName + ".asset");
                            AssetDatabase.SaveAssets();
                            AssetDatabase.Refresh();
                        }
                        else
                        {
                            EditorUtility.DisplayDialog("Node Message:", "Unable to create graph", "OK");
                        }
                    }
                    currentPopupWindow.Close();
                }
                else
                {
                    EditorUtility.DisplayDialog("Node Message: ", "Please enter a valid graph name!", "OK");
                }
            }

            if (GUILayout.Button("Cancel", GUILayout.Height(40f)))
            {
                currentPopupWindow.Close();
            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            GUILayout.Space(20);
            GUILayout.EndHorizontal();
            GUILayout.Space(20);
        }
 public static void DeleteNode(AG_Node currentNode, AG_Graph currentGraph)
 {
     if (currentGraph != null)
     {
         currentGraph.nodes.Remove(currentNode);
         GameObject.DestroyImmediate(currentNode, true);
         AssetDatabase.SaveAssets();
         AssetDatabase.Refresh();
     }
 }
Example #4
0
        public static AG_Node CreateNode(Vector2 mousePosition, AG_Graph parentGraph, AG_NodeType nodeType)
        {
            AG_Node currentNode = null;

            switch (nodeType)
            {
            case AG_NodeType.Dialogue:
                currentNode          = ScriptableObject.CreateInstance <AG_DialogueNode>();
                currentNode.nodeName = "Dialogue Node";
                break;

            case AG_NodeType.Begin:
                currentNode          = ScriptableObject.CreateInstance <AG_BeginNode>();
                currentNode.nodeName = "Starting Node";
                break;

            case AG_NodeType.Test:
                currentNode = ScriptableObject.CreateInstance <AG_TestNode>();
                break;
                //			case AG_NodeType.Add:
                //				currentNode = ScriptableObject.CreateInstance<AddNode>();
                //				currentNode.NodeName = "Add Node";
                //				break;
            }


            if (currentNode != null)
            {
                currentNode.InitNode();

                Rect nodeRect = new Rect(mousePosition.x - currentNode.nodeSize.x / 2, mousePosition.y, currentNode.nodeSize.x, currentNode.nodeSize.y);

                currentNode.nodeRect    = nodeRect;
                currentNode.parentGraph = parentGraph;
            }

            return(currentNode);
        }