Esempio n. 1
0
        //This is called outside Begin/End Windows from GraphEditor.
        void ShowToolbar(Event e)
        {
            var owner = this.agent != null && agent is GraphOwner && (agent as GraphOwner).graph == this? (GraphOwner)agent : null;


            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            GUI.backgroundColor = new Color(1f, 1f, 1f, 0.5f);

            ///FILE
            if (GUILayout.Button("File", EditorStyles.toolbarDropDown, GUILayout.Width(50)))
            {
                var menu = new GenericMenu();

#if !UNITY_WEBPLAYER
                //Import JSON
                menu.AddItem(new GUIContent("Import JSON"), false, () =>
                {
                    if (allNodes.Count > 0 && !EditorUtility.DisplayDialog("Import Graph", "All current graph information will be lost. Are you sure?", "YES", "NO"))
                    {
                        return;
                    }

                    var path = EditorUtility.OpenFilePanel(string.Format("Import '{0}' Graph", this.GetType().Name), "Assets", exportFileExtension);
                    if (!string.IsNullOrEmpty(path))
                    {
                        if (this.Deserialize(System.IO.File.ReadAllText(path), true, null) == null)         //true: validate, null: this._objectReferences
                        {
                            EditorUtility.DisplayDialog("Import Failure", "Please read the logs for more information", "OK", "");
                        }
                    }
                });

                //Expot JSON
                menu.AddItem(new GUIContent("Export JSON"), false, () =>
                {
                    var path = EditorUtility.SaveFilePanelInProject(string.Format("Export '{0}' Graph", this.GetType().Name), "", exportFileExtension, "");
                    if (!string.IsNullOrEmpty(path))
                    {
                        System.IO.File.WriteAllText(path, this.Serialize(true, null));       //true: pretyJson, null: this._objectReferences
                        AssetDatabase.Refresh();
                    }
                });
#else
                menu.AddDisabledItem(new GUIContent("Import JSON (not possible with webplayer active platform)"));
                menu.AddDisabledItem(new GUIContent("Export JSON (not possible with webplayer active platform)"));
#endif
                menu.ShowAsContext();
            }

            ///EDIT
            if (GUILayout.Button("Edit", EditorStyles.toolbarDropDown, GUILayout.Width(50)))
            {
                var menu = new GenericMenu();

                //Bind
                if (!Application.isPlaying && owner != null && !owner.graphIsBound)
                {
                    menu.AddItem(new GUIContent("Bind To Owner"), false, () =>
                    {
                        if (EditorUtility.DisplayDialog("Bind Graph", "This will make a local copy of the graph, bound to the owner.\n\nThis allows you to make local changes and assign scene object references directly.\n\nNote that you can also use scene object references through the use of Blackboard Variables.\n\nBind Graph?", "YES", "NO"))
                        {
                            Undo.RecordObject(owner, "New Local Graph");
                            owner.SetBoundGraphReference(owner.graph);
                            EditorUtility.SetDirty(owner);
                        }
                    });
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Bind To Owner"));
                }

                //Save to asset
                if (owner != null && owner.graphIsBound)
                {
                    menu.AddItem(new GUIContent("Save To Asset"), false, () =>
                    {
                        var newGraph = (Graph)EditorUtils.CreateAsset(this.GetType(), true);
                        if (newGraph != null)
                        {
                            EditorUtility.CopySerialized(this, newGraph);
                            newGraph.Validate();
                            AssetDatabase.SaveAssets();
                        }
                    });
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Save To Asset"));
                }

                //Create defined vars
                if (blackboard != null)
                {
                    menu.AddItem(new GUIContent("Promote Defined Parameters To Variables"), false, () =>
                    {
                        if (EditorUtility.DisplayDialog("Promote Defined Parameters", "This will fill the current Blackboard with a Variable for each defined Parameter in the graph.\nContinue?", "YES", "NO"))
                        {
                            CreateDefinedParameterVariables(blackboard);
                        }
                    });
                }
                else
                {
                    menu.AddDisabledItem(new GUIContent("Create Defined Blackboard Variables"));
                }

                menu.ShowAsContext();
            }
            //////


            ///PREFS
            if (GUILayout.Button("Prefs", EditorStyles.toolbarDropDown, GUILayout.Width(50)))
            {
                var menu = new GenericMenu();
                menu.AddItem(new GUIContent("Use Node Browser"), NCPrefs.useBrowser, () => { NCPrefs.useBrowser = !NCPrefs.useBrowser; });
                menu.AddItem(new GUIContent("Show Icons"), NCPrefs.showIcons, () => { NCPrefs.showIcons = !NCPrefs.showIcons; });
                menu.AddItem(new GUIContent("Show Node Help"), NCPrefs.showNodeInfo, () => { NCPrefs.showNodeInfo = !NCPrefs.showNodeInfo; });
                menu.AddItem(new GUIContent("Show Comments"), NCPrefs.showComments, () => { NCPrefs.showComments = !NCPrefs.showComments; });
                menu.AddItem(new GUIContent("Show Summary Info"), NCPrefs.showTaskSummary, () => { NCPrefs.showTaskSummary = !NCPrefs.showTaskSummary; });
                menu.AddItem(new GUIContent("Log Events"), NCPrefs.logEvents, () => { NCPrefs.logEvents = !NCPrefs.logEvents; });
                menu.AddItem(new GUIContent("Grid Snap"), NCPrefs.doSnap, () => { NCPrefs.doSnap = !NCPrefs.doSnap; });
                menu.AddItem(new GUIContent("Breakpoints Pause Editor"), NCPrefs.breakpointPauseEditor, () => { NCPrefs.breakpointPauseEditor = !NCPrefs.breakpointPauseEditor; });
                if (autoSort)
                {
                    menu.AddItem(new GUIContent("Automatic Hierarchical Move"), NCPrefs.hierarchicalMove, () => { NCPrefs.hierarchicalMove = !NCPrefs.hierarchicalMove; });
                }
                menu.AddItem(new GUIContent("Connection Style/Smooth"), NCPrefs.connectionStyle == NCPrefs.ConnectionStyle.Smooth, () => { NCPrefs.connectionStyle = NCPrefs.ConnectionStyle.Smooth; });
                menu.AddItem(new GUIContent("Connection Style/Stepped"), NCPrefs.connectionStyle == NCPrefs.ConnectionStyle.Stepped, () => { NCPrefs.connectionStyle = NCPrefs.ConnectionStyle.Stepped; });
                menu.AddItem(new GUIContent("Connection Style/Straight"), NCPrefs.connectionStyle == NCPrefs.ConnectionStyle.Straight, () => { NCPrefs.connectionStyle = NCPrefs.ConnectionStyle.Straight; });
                //menu.AddItem (new GUIContent ("Use External Inspector"), NCPrefs.useExternalInspector, ()=> {NCPrefs.useExternalInspector = !NCPrefs.useExternalInspector;});
                menu.AddItem(new GUIContent("Open Preferred Types Editor..."), false, () => { PreferedTypesEditorWindow.ShowWindow(); });
                menu.ShowAsContext();
            }
            /////////

            GUILayout.Space(10);

            ////CLICK SELECT
            if (owner != null && GUILayout.Button("Select Owner", EditorStyles.toolbarButton, GUILayout.Width(80)))
            {
                Selection.activeObject = owner;
                EditorGUIUtility.PingObject(owner);
            }

            if (EditorUtility.IsPersistent(this) && GUILayout.Button("Select Graph", EditorStyles.toolbarButton, GUILayout.Width(80)))
            {
                Selection.activeObject = this;
                EditorGUIUtility.PingObject(this);
            }
            ////////////////

            GUILayout.Space(10);
            GUILayout.FlexibleSpace();

            //DROPDOWN GRAPHOWNER JUMP SELECTION
            if (owner != null && !NCPrefs.isLocked)
            {
                if (GUILayout.Button(string.Format("[{0}]", owner.gameObject.name), EditorStyles.toolbarDropDown, GUILayout.Width(120)))
                {
                    var menu = new GenericMenu();
                    foreach (var _o in FindObjectsOfType <GraphOwner>())
                    {
                        var o = _o;
                        menu.AddItem(new GUIContent(o.GetType().Name + "s/" + o.gameObject.name), false, () => { Selection.activeObject = o; Selection.selectionChanged(); });
                    }
                    menu.ShowAsContext();
                }
            }
            ////////////////////////////////////

            NCPrefs.isLocked = GUILayout.Toggle(NCPrefs.isLocked, "Lock", EditorStyles.toolbarButton);
            GUILayout.Space(2);

            GUI.backgroundColor = new Color(1, 0.8f, 0.8f, 1);
            if (GUILayout.Button("Clear", EditorStyles.toolbarButton, GUILayout.Width(50)))
            {
                if (EditorUtility.DisplayDialog("Clear Canvas", "This will delete all nodes of the currently viewing graph!\nAre you sure?", "YES", "NO!"))
                {
                    ClearGraph();
                    e.Use();
                    return;
                }
            }

            GUILayout.EndHorizontal();
            GUI.backgroundColor = Color.white;
        }
Esempio n. 2
0
 public static void ShowPrefTypes()
 {
     PreferedTypesEditorWindow.ShowWindow();
 }