void ShowCommandMenu(int index, Sequence sequence)
        {
            GenericMenu commandMenu = new GenericMenu();

            // Build menu list
            List <System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();

            foreach (System.Type type in menuTypes)
            {
                object[] attributes = type.GetCustomAttributes(false);
                foreach (object obj in attributes)
                {
                    CommandInfoAttribute infoAttr = obj as CommandInfoAttribute;
                    if (infoAttr != null)
                    {
                        SetCommandOperation commandOperation = new SetCommandOperation();

                        commandOperation.sequence    = sequence;
                        commandOperation.commandType = type;
                        commandOperation.index       = index;

                        commandMenu.AddItem(new GUIContent(infoAttr.Category + "/" + infoAttr.CommandName),
                                            false, Callback, commandOperation);
                    }
                }
            }

            commandMenu.ShowAsContext();
        }
Example #2
0
        protected virtual void ShowCommandMenu()
        {
            Block block = target as Block;

            Flowchart flowchart = block.GetFlowchart();

            // Use index of last selected command in list, or end of list if nothing selected.
            int index = -1;

            foreach (Command command in flowchart.selectedCommands)
            {
                if (command.commandIndex + 1 > index)
                {
                    index = command.commandIndex + 1;
                }
            }
            if (index == -1)
            {
                index = block.commandList.Count;
            }

            GenericMenu commandMenu = new GenericMenu();

            // Build menu list
            List <System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
            List <KeyValuePair <System.Type, CommandInfoAttribute> > filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes);

            filteredAttributes.Sort(CompareCommandAttributes);

            foreach (var keyPair in filteredAttributes)
            {
                // Skip command type if the Flowchart doesn't support it
                if (!flowchart.IsCommandSupported(keyPair.Value))
                {
                    continue;
                }

                AddCommandOperation commandOperation = new AddCommandOperation();

                commandOperation.block       = block;
                commandOperation.commandType = keyPair.Key;
                commandOperation.index       = index;

                GUIContent menuItem;
                if (keyPair.Value.Category == "")
                {
                    menuItem = new GUIContent(keyPair.Value.CommandName);
                }
                else
                {
                    menuItem = new GUIContent(keyPair.Value.Category + "/" + keyPair.Value.CommandName);
                }

                commandMenu.AddItem(menuItem, false, AddCommandCallback, commandOperation);
            }

            commandMenu.ShowAsContext();
        }
Example #3
0
        protected static void ExportCommandInfo(string path)
        {
            // Dump command info
            List <System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
            List <KeyValuePair <System.Type, CommandInfoAttribute> > filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes);

            filteredAttributes.Sort(CompareCommandAttributes);

            // Build list of command categories
            List <string> commandCategories = new List <string>();

            foreach (var keyPair in filteredAttributes)
            {
                CommandInfoAttribute info = keyPair.Value;
                if (info.Category != "" &&
                    !commandCategories.Contains(info.Category))
                {
                    commandCategories.Add(info.Category);
                }
            }
            commandCategories.Sort();

            // Output the commands in each category
            foreach (string category in commandCategories)
            {
                string markdown = "";
                foreach (var keyPair in filteredAttributes)
                {
                    CommandInfoAttribute info = keyPair.Value;

                    if (info.Category == category ||
                        info.Category == "" && category == "Scripting")
                    {
                        markdown += "## " + info.CommandName + "\n";
                        markdown += info.HelpText + "\n";
                        markdown += GetPropertyInfo(keyPair.Key);
                    }
                }

                string filePath = path + "/commands/" + category.ToLower() + "_commands.md";

                Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                File.WriteAllText(filePath, markdown);
            }
        }
Example #4
0
        protected static void ExportEventHandlerInfo(string path)
        {
            List <System.Type> eventHandlerTypes      = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).ToList();
            List <string>      eventHandlerCategories = new List <string>();

            eventHandlerCategories.Add("Core");
            foreach (System.Type type in eventHandlerTypes)
            {
                EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);
                if (info != null &&
                    info.Category != "" &&
                    !eventHandlerCategories.Contains(info.Category))
                {
                    eventHandlerCategories.Add(info.Category);
                }
            }
            eventHandlerCategories.Sort();

            // Output the commands in each category
            foreach (string category in eventHandlerCategories)
            {
                string markdown = "";

                foreach (System.Type type in eventHandlerTypes)
                {
                    EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);

                    if (info != null &&
                        info.Category == category ||
                        info.Category == "" && category == "Core")
                    {
                        markdown += "## " + info.EventHandlerName + "\n";
                        markdown += info.HelpText + "\n";
                        markdown += GetPropertyInfo(type);
                    }
                }

                string filePath = path + "/event_handlers/" + category.ToLower() + "_events.md";

                Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                File.WriteAllText(filePath, markdown);
            }
        }
Example #5
0
        void ShowCommandMenu()
        {
            Sequence sequence = target as Sequence;
            int      index    = sequence.commandList.Count;

            GenericMenu commandMenu = new GenericMenu();

            // Build menu list
            List <System.Type> menuTypes = EditorExtensions.FindDerivedTypes(typeof(Command)).ToList();
            List <KeyValuePair <System.Type, CommandInfoAttribute> > filteredAttributes = GetFilteredCommandInfoAttribute(menuTypes);

            filteredAttributes.Sort(CompareCommandAttributes);

            foreach (var keyPair in filteredAttributes)
            {
                AddCommandOperation commandOperation = new AddCommandOperation();

                commandOperation.sequence    = sequence;
                commandOperation.commandType = keyPair.Key;
                commandOperation.index       = index;

                GUIContent menuItem;
                if (keyPair.Value.Category == "")
                {
                    menuItem = new GUIContent(keyPair.Value.CommandName);
                }
                else
                {
                    menuItem = new GUIContent(keyPair.Value.Category + "/" + keyPair.Value.CommandName);
                }

                commandMenu.AddItem(menuItem, false, AddCommandCallback, commandOperation);
            }

            commandMenu.ShowAsContext();
        }
Example #6
0
        protected virtual void DrawEventHandlerGUI(Flowchart flowchart)
        {
            // Show available Event Handlers in a drop down list with type of current
            // event handler selected.
            List <System.Type> eventHandlerTypes = EditorExtensions.FindDerivedTypes(typeof(EventHandler)).ToList();

            Block block = target as Block;

            System.Type currentType = null;
            if (block.eventHandler != null)
            {
                currentType = block.eventHandler.GetType();
            }

            string currentHandlerName = "<None>";

            if (currentType != null)
            {
                EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(currentType);
                if (info != null)
                {
                    currentHandlerName = info.EventHandlerName;
                }
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(new GUIContent("Execute On Event"));
            if (GUILayout.Button(new GUIContent(currentHandlerName), EditorStyles.popup))
            {
                SetEventHandlerOperation noneOperation = new SetEventHandlerOperation();
                noneOperation.block            = block;
                noneOperation.eventHandlerType = null;

                GenericMenu eventHandlerMenu = new GenericMenu();
                eventHandlerMenu.AddItem(new GUIContent("None"), false, OnSelectEventHandler, noneOperation);

                // Add event handlers with no category first
                foreach (System.Type type in eventHandlerTypes)
                {
                    EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);
                    if (info.Category.Length == 0)
                    {
                        SetEventHandlerOperation operation = new SetEventHandlerOperation();
                        operation.block            = block;
                        operation.eventHandlerType = type;

                        eventHandlerMenu.AddItem(new GUIContent(info.EventHandlerName), false, OnSelectEventHandler, operation);
                    }
                }

                // Add event handlers with a category afterwards
                foreach (System.Type type in eventHandlerTypes)
                {
                    EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(type);
                    if (info.Category.Length > 0)
                    {
                        SetEventHandlerOperation operation = new SetEventHandlerOperation();
                        operation.block            = block;
                        operation.eventHandlerType = type;
                        string typeName = info.Category + "/" + info.EventHandlerName;
                        eventHandlerMenu.AddItem(new GUIContent(typeName), false, OnSelectEventHandler, operation);
                    }
                }


                eventHandlerMenu.ShowAsContext();
            }
            EditorGUILayout.EndHorizontal();

            if (block.eventHandler != null)
            {
                EventHandlerEditor eventHandlerEditor = Editor.CreateEditor(block.eventHandler) as EventHandlerEditor;
                if (eventHandlerEditor != null)
                {
                    eventHandlerEditor.DrawInspectorGUI();
                    DestroyImmediate(eventHandlerEditor);
                }
            }
        }