// -------------------------------------------------------------------------------

        void OnGUI()
        {
            if (mCurrentAction != null)
            {
                ShowActionInspector();
            }
            else if (mCurrentConnection != null)
            {
                ShowConnectionInspector(mCurrentConnection);

                // Do we have a two-way connection between these two nodes?
                var otherConnection = mCurrentConnection.EndNode.GetOutgoingConnectionToNode(mCurrentConnection.StartNode);
                if (otherConnection != null)
                {
                    // If so, draw the *other* conneciton as well
                    EditorGUILayout.Space();
                    EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
                    EditorGUILayout.Space();

                    ShowConnectionInspector(otherConnection);
                }
            }
            else
            {
                EditorGUILayout.Space();
                EditorGUILayout.LabelField("No Action or Connection selected from the ActionGraph Editor!");
                EditorGUILayout.Space();
            }

            // Make sure the main editor window shows up-to-date changes we make
            ActionGraphEditor.MarkAsDirty(true);
        }
Esempio n. 2
0
        public override void OnInspectorGUI()
        {
            Graph graph = (Graph)target;

            if (GUILayout.Button("Open Editor"))
            {
                ActionGraphEditor.CurrentGraph = graph;
                ActionGraphEditor.ShowEditor();
            }

            DrawDefaultInspector();
        }
Esempio n. 3
0
 public static void ShowEditor()
 {
     mInstance = EditorWindow.GetWindow <ActionGraphEditor>();
     mInstance.Init();
 }
Esempio n. 4
0
        // -------------------------------------------------------------------------------

        public static void OnGUI(this Node node)
        {
            node.Name = EditorGUILayout.TextField("Name", node.Name);
            node.MustFinishAllActions = EditorGUILayout.Toggle("Must Finish All Actions?", node.MustFinishAllActions);

            EditorGUILayout.LabelField("ACTIONS", EditorStyles.boldLabel);

            if (GUILayout.Button("Add New Action"))
            {
                // Get a list of all possible Actions via reflection
                Type        baseActionType = typeof(Action);
                Assembly    assembly       = Assembly.GetAssembly(baseActionType);
                List <Type> allActionTypes = assembly.GetTypes().Where(type => type != baseActionType && baseActionType.IsAssignableFrom(type)).ToList();

                // Create a menu item for each type so we can create new instances from the GUI
                var menu = new GenericMenu();

                // Also, if we have an action copied to the clipboard, add an option to paste that in instead
                if (ActionGraphEditor.CopiedAction != null)
                {
                    menu.AddItem(new GUIContent("PASTE COPIED ACTION"), false, () =>
                    {
                        var newAction = ActionGraphEditor.CopiedAction.Clone();
                        node.Actions.Add(newAction);
                        ShowActionGraphInspector(newAction);
                    });
                }

                foreach (var actionType in allActionTypes)
                {
                    menu.AddItem(new GUIContent(actionType.Name), false, () =>
                    {
                        var newAction = Activator.CreateInstance(actionType) as Action;
                        node.Actions.Add(newAction);
                        ShowActionGraphInspector(newAction);
                    });
                }
                menu.ShowAsContext();
            }

            Action actionToMoveUp   = null;
            Action actionToMoveDown = null;

            foreach (var action in node.Actions)
            {
                var labelStyle = EditorStyles.label;

                // Highlight the currently executing action, if applicable
                if ((ActionGraphEditor.CurrentGraph.CurrentNode != null &&
                     ActionGraphEditor.CurrentGraph.CurrentNode.CurrentAction == action))
                {
                    labelStyle = EditorStyles.boldLabel;
                }

                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField(action.DisplayName, labelStyle);

                if (GUILayout.Button("↑"))
                {
                    actionToMoveUp = action;
                }

                if (GUILayout.Button("↓"))
                {
                    actionToMoveDown = action;
                }

                if (GUILayout.Button("Edit"))
                {
                    ActionGraphEditor.MarkAsDirty();
                    ShowActionGraphInspector(action);
                }

                if (GUILayout.Button("Delete"))
                {
                    node.Actions.Remove(action);
                    ActionGraphInspector.Clear();
                    break;
                }

                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }

            // Re-order actions list if requested!
            if (actionToMoveUp != null)
            {
                var actionIndex = node.Actions.IndexOf(actionToMoveUp);
                if (actionIndex > 0)
                {
                    node.Actions.Swap(actionIndex, actionIndex - 1);
                }
            }
            else if (actionToMoveDown != null)
            {
                var actionIndex = node.Actions.IndexOf(actionToMoveDown);
                if (actionIndex < node.Actions.Count - 1)
                {
                    node.Actions.Swap(actionIndex, actionIndex + 1);
                }
            }

            EditorGUILayout.Space();
        }