示例#1
0
        protected void SelectNext()
        {
            Sequence     sequence     = target as Sequence;
            FungusScript fungusScript = sequence.GetFungusScript();

            int lastSelectedIndex = -1;

            if (fungusScript.selectedCommands.Count > 0)
            {
                for (int i = 0; i < fungusScript.selectedSequence.commandList.Count; i++)
                {
                    Command commandInSequence = fungusScript.selectedSequence.commandList[i];

                    foreach (Command selectedCommand in fungusScript.selectedCommands)
                    {
                        if (commandInSequence == selectedCommand)
                        {
                            lastSelectedIndex = i;
                        }
                    }
                }
            }
            if (lastSelectedIndex < fungusScript.selectedSequence.commandList.Count - 1)
            {
                fungusScript.ClearSelectedCommands();
                fungusScript.AddSelectedCommand(fungusScript.selectedSequence.commandList[lastSelectedIndex + 1]);
            }

            Repaint();
        }
 protected virtual void SelectSequence(FungusScript fungusScript, Sequence sequence)
 {
     // Select the sequence and also select currently executing command
     ShowSequenceInspector(fungusScript);
     fungusScript.selectedSequence = sequence;
     fungusScript.ClearSelectedCommands();
     if (sequence.activeCommand != null)
     {
         fungusScript.AddSelectedCommand(sequence.activeCommand);
     }
 }
示例#3
0
        protected void SelectAll()
        {
            Sequence     sequence     = target as Sequence;
            FungusScript fungusScript = sequence.GetFungusScript();

            if (fungusScript == null ||
                fungusScript.selectedSequence == null)
            {
                return;
            }

            fungusScript.ClearSelectedCommands();
            Undo.RecordObject(fungusScript, "Select All");
            foreach (Command command in fungusScript.selectedSequence.commandList)
            {
                fungusScript.AddSelectedCommand(command);
            }

            Repaint();
        }
示例#4
0
        protected void SelectPrevious()
        {
            Sequence     sequence     = target as Sequence;
            FungusScript fungusScript = sequence.GetFungusScript();

            int  firstSelectedIndex        = fungusScript.selectedSequence.commandList.Count;
            bool firstSelectedCommandFound = false;

            if (fungusScript.selectedCommands.Count > 0)
            {
                for (int i = 0; i < fungusScript.selectedSequence.commandList.Count; i++)
                {
                    Command commandInSequence = fungusScript.selectedSequence.commandList[i];

                    foreach (Command selectedCommand in fungusScript.selectedCommands)
                    {
                        if (commandInSequence == selectedCommand)
                        {
                            if (!firstSelectedCommandFound)
                            {
                                firstSelectedIndex        = i;
                                firstSelectedCommandFound = true;
                                break;
                            }
                        }
                    }
                    if (firstSelectedCommandFound)
                    {
                        break;
                    }
                }
            }
            if (firstSelectedIndex > 0)
            {
                fungusScript.ClearSelectedCommands();
                fungusScript.AddSelectedCommand(fungusScript.selectedSequence.commandList[firstSelectedIndex - 1]);
            }

            Repaint();
        }
示例#5
0
        Command AddNewCommand()
        {
            FungusScript fungusScript = FungusScriptWindow.GetFungusScript();

            if (fungusScript == null)
            {
                return(null);
            }

            Sequence sequence = fungusScript.selectedSequence;

            if (sequence == null)
            {
                return(null);
            }

            Command newCommand = Undo.AddComponent <Comment>(sequence.gameObject) as Command;

            fungusScript.ClearSelectedCommands();
            fungusScript.AddSelectedCommand(newCommand);

            return(newCommand);
        }
示例#6
0
        public void DrawItem(Rect position, int index)
        {
            Command command = this[index].objectReferenceValue as Command;

            if (command == null)
            {
                return;
            }

            CommandInfoAttribute commandInfoAttr = CommandEditor.GetCommandInfo(command.GetType());

            if (commandInfoAttr == null)
            {
                return;
            }

            FungusScript fungusScript = command.GetFungusScript();

            if (fungusScript == null)
            {
                return;
            }

            bool isComment = (command.GetType() == typeof(Comment));
            bool isLabel   = (command.GetType() == typeof(Label));

            bool   error   = false;
            string summary = command.GetSummary();

            if (summary == null)
            {
                summary = "";
            }
            else
            {
                summary = summary.Replace("\n", "").Replace("\r", "");
            }
            if (summary.StartsWith("Error:"))
            {
                error = true;
            }

            if (isComment || isLabel)
            {
                summary = "<b> " + summary + "</b>";
            }
            else
            {
                summary = "<i>" + summary + "</i>";
            }

            bool commandIsSelected = false;

            foreach (Command selectedCommand in fungusScript.selectedCommands)
            {
                if (selectedCommand == command)
                {
                    commandIsSelected = true;
                    break;
                }
            }

            string commandName = commandInfoAttr.CommandName;

            GUIStyle commandLabelStyle = new GUIStyle(GUI.skin.box);

            commandLabelStyle.normal.background = FungusEditorResources.texCommandBackground;
            commandLabelStyle.border.top        = 1;
            commandLabelStyle.border.bottom     = 1;
            commandLabelStyle.border.left       = 1;
            commandLabelStyle.border.right      = 1;
            commandLabelStyle.alignment         = TextAnchor.MiddleLeft;
            commandLabelStyle.richText          = true;
            commandLabelStyle.fontSize          = 11;
            commandLabelStyle.padding.top      -= 1;

            float indentSize = 20;

            for (int i = 0; i < command.indentLevel; ++i)
            {
                Rect indentRect = position;
                indentRect.x       += i * indentSize - 21;
                indentRect.width    = indentSize + 1;
                indentRect.y       -= 2;
                indentRect.height  += 5;
                GUI.backgroundColor = new Color(0.5f, 0.5f, 0.5f, 1f);
                GUI.Box(indentRect, "", commandLabelStyle);
            }

            float commandNameWidth = Mathf.Max(commandLabelStyle.CalcSize(new GUIContent(commandName)).x, 90f);
            float indentWidth      = command.indentLevel * indentSize;

            Rect commandLabelRect = position;

            commandLabelRect.x      += indentWidth - 21;
            commandLabelRect.y      -= 2;
            commandLabelRect.width  -= (indentSize * command.indentLevel - 22);
            commandLabelRect.height += 5;

            // Select command via left click
            if (Event.current.type == EventType.MouseDown &&
                Event.current.button == 0 &&
                position.Contains(Event.current.mousePosition))
            {
                if (fungusScript.selectedCommands.Contains(command) && Event.current.button == 0)
                {
                    // Left click on an already selected command
                    fungusScript.selectedCommands.Remove(command);
                }
                else
                {
                    // Left click and no command key
                    if (!EditorGUI.actionKey && Event.current.button == 0)
                    {
                        fungusScript.ClearSelectedCommands();
                    }

                    fungusScript.AddSelectedCommand(command);
                }
                GUIUtility.keyboardControl = 0;                 // Fix for textarea not refeshing (change focus)
            }

            Color commandLabelColor = Color.white;

            if (fungusScript.colorCommands)
            {
                commandLabelColor = command.GetButtonColor();
            }

            if (commandIsSelected)
            {
                commandLabelColor = Color.green;
            }
            else if (!command.enabled)
            {
                commandLabelColor = Color.grey;
            }
            else if (error)
            {
                // TODO: Show warning icon
            }

            GUI.backgroundColor = commandLabelColor;

            if (isComment || isLabel)
            {
                GUI.Label(commandLabelRect, "", commandLabelStyle);
            }
            else
            {
                GUI.Label(commandLabelRect, commandName, commandLabelStyle);
            }

            if (command.IsExecuting())
            {
                Rect iconRect = new Rect(commandLabelRect);
                iconRect.x     += iconRect.width - commandLabelRect.width - 20;
                iconRect.width  = 20;
                iconRect.height = 20;
                GUI.Label(iconRect, FungusEditorResources.texPlaySmall, new GUIStyle());
            }

            Rect summaryRect = new Rect(commandLabelRect);

            if (!isComment && !isLabel)
            {
                summaryRect.x     += commandNameWidth;
                summaryRect.width -= commandNameWidth;
                summaryRect.width -= 5;
            }

            GUIStyle summaryStyle = new GUIStyle();

            summaryStyle.fontSize     = 10;
            summaryStyle.padding.top += 5;
            summaryStyle.richText     = true;
            summaryStyle.wordWrap     = false;
            summaryStyle.clipping     = TextClipping.Clip;
            GUI.Label(summaryRect, summary, summaryStyle);

            if (error)
            {
                GUISkin editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
                Rect    errorRect  = new Rect(summaryRect);
                errorRect.x    += errorRect.width - 20;
                errorRect.y    += 2;
                errorRect.width = 20;
                GUI.Label(errorRect, editorSkin.GetStyle("CN EntryError").normal.background);
                summaryRect.width -= 20;
            }

            GUI.backgroundColor = Color.white;
        }
示例#7
0
        public virtual void ExecuteCommand(int commandIndex)
        {
            if (activeCommand == null)
            {
                previousActiveCommandIndex = -1;
            }
            else
            {
                previousActiveCommandIndex = activeCommand.commandIndex;
            }

            if (commandIndex >= commandList.Count)
            {
                Stop();
                return;
            }

            if (commandIndex == 0)
            {
                executionCount++;
            }

            FungusScript fungusScript = GetFungusScript();

            // Skip disabled commands, comments and labels
            while (commandIndex < commandList.Count &&
                   (!commandList[commandIndex].enabled ||
                    commandList[commandIndex].GetType() == typeof(Comment) ||
                    commandList[commandIndex].GetType() == typeof(Label)))
            {
                commandIndex = commandList[commandIndex].commandIndex + 1;
            }

            if (commandIndex >= commandList.Count)
            {
                Stop();
                return;
            }

            Command nextCommand = commandList[commandIndex];

            activeCommand      = null;
            executingIconTimer = 0.5f;

            if (nextCommand == null)
            {
                Stop();
            }
            else
            {
                if (fungusScript.gameObject.activeInHierarchy)
                {
                    // Auto select a command in some situations
                    if ((fungusScript.selectedCommands.Count == 0 && commandIndex == 0) ||
                        (fungusScript.selectedCommands.Count == 1 && fungusScript.selectedCommands[0].commandIndex == previousActiveCommandIndex))
                    {
                        fungusScript.ClearSelectedCommands();
                        fungusScript.AddSelectedCommand(nextCommand);
                    }

                    if (runSlowInEditor &&
                        nextCommand.RunSlowInEditor())
                    {
                        StartCoroutine(ExecuteAfterDelay(nextCommand, fungusScript.runSlowDuration));
                    }
                    else
                    {
                        activeCommand = nextCommand;
                        nextCommand.Execute();
                    }
                }
            }
        }