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 void Delete() { Sequence sequence = target as Sequence; FungusScript fungusScript = sequence.GetFungusScript(); if (fungusScript == null || fungusScript.selectedSequence == null) { return; } for (int i = fungusScript.selectedSequence.commandList.Count - 1; i >= 0; --i) { Command command = fungusScript.selectedSequence.commandList[i]; foreach (Command selectedCommand in fungusScript.selectedCommands) { if (command == selectedCommand) { command.OnCommandRemoved(sequence); Undo.RecordObject(fungusScript.selectedSequence, "Delete"); fungusScript.selectedSequence.commandList.RemoveAt(i); Undo.DestroyObjectImmediate(command); break; } } } Undo.RecordObject(fungusScript, "Delete"); fungusScript.ClearSelectedCommands(); Repaint(); }
protected virtual void DeleteSequence(FungusScript fungusScript, Sequence sequence) { foreach (Command command in sequence.commandList) { Undo.DestroyObjectImmediate(command); } Undo.DestroyObjectImmediate(sequence); fungusScript.ClearSelectedCommands(); }
public static Sequence CreateSequence(FungusScript fungusScript, Vector2 position) { Sequence newSequence = fungusScript.CreateSequence(position); Undo.RegisterCreatedObjectUndo(newSequence, "New Sequence"); ShowSequenceInspector(fungusScript); fungusScript.selectedSequence = newSequence; fungusScript.ClearSelectedCommands(); return(newSequence); }
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); } }
public virtual void Stop() { FungusScript fungusScript = GetFungusScript(); if (fungusScript == null) { return; } activeCommand = null; fungusScript.ClearSelectedCommands(); }
protected void SelectNone() { Sequence sequence = target as Sequence; FungusScript fungusScript = sequence.GetFungusScript(); if (fungusScript == null || fungusScript.selectedSequence == null) { return; } Undo.RecordObject(fungusScript, "Select None"); fungusScript.ClearSelectedCommands(); Repaint(); }
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(); }
protected virtual void OnGUI() { FungusScript fungusScript = GetFungusScript(); if (fungusScript == null) { GUILayout.Label("No Fungus Script scene object selected"); return; } // Delete any scheduled objects foreach (Sequence deleteSequence in deleteList) { bool isSelected = (fungusScript.selectedSequence == deleteSequence); foreach (Command command in deleteSequence.commandList) { Undo.DestroyObjectImmediate(command); } Undo.DestroyObjectImmediate(deleteSequence); fungusScript.ClearSelectedCommands(); if (isSelected) { // Revert to showing properties for the Fungus Script Selection.activeGameObject = fungusScript.gameObject; } } deleteList.Clear(); DrawScriptView(fungusScript); DrawOverlay(fungusScript); if (forceRepaintCount > 0) { // Redraw on next frame to get crisp refresh rate Repaint(); } }
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(); }
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); }
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; }
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(); } } } }
protected virtual void DrawScriptView(FungusScript fungusScript) { Sequence[] sequences = fungusScript.GetComponentsInChildren <Sequence>(true); foreach (Sequence s in sequences) { fungusScript.scrollViewRect.xMin = Mathf.Min(fungusScript.scrollViewRect.xMin, s.nodeRect.xMin - 400); fungusScript.scrollViewRect.xMax = Mathf.Max(fungusScript.scrollViewRect.xMax, s.nodeRect.xMax + 400); fungusScript.scrollViewRect.yMin = Mathf.Min(fungusScript.scrollViewRect.yMin, s.nodeRect.yMin - 400); fungusScript.scrollViewRect.yMax = Mathf.Max(fungusScript.scrollViewRect.yMax, s.nodeRect.yMax + 400); } // Calc rect for script view Rect scriptViewRect = new Rect(0, 0, this.position.width / fungusScript.zoom, this.position.height / fungusScript.zoom); EditorZoomArea.Begin(fungusScript.zoom, scriptViewRect); DrawGrid(fungusScript); GLDraw.BeginGroup(scriptViewRect); if (Event.current.button == 0 && Event.current.type == EventType.MouseDown && !mouseOverVariables) { fungusScript.selectedSequence = null; if (!EditorGUI.actionKey) { fungusScript.ClearSelectedCommands(); } Selection.activeGameObject = fungusScript.gameObject; } // Draw connections foreach (Sequence s in sequences) { DrawConnections(fungusScript, s, false); } foreach (Sequence s in sequences) { DrawConnections(fungusScript, s, true); } GUIStyle windowStyle = new GUIStyle(); windowStyle.stretchHeight = true; BeginWindows(); windowSequenceMap.Clear(); for (int i = 0; i < sequences.Length; ++i) { Sequence sequence = sequences[i]; float nodeWidthA = nodeStyle.CalcSize(new GUIContent(sequence.sequenceName)).x + 10; float nodeWidthB = 0f; if (sequence.eventHandler != null) { nodeWidthB = nodeStyle.CalcSize(new GUIContent(sequence.eventHandler.GetSummary())).x + 10; } sequence.nodeRect.width = Mathf.Max(Mathf.Max(nodeWidthA, nodeWidthB), 120); sequence.nodeRect.height = 40; if (Event.current.button == 0) { if (Event.current.type == EventType.MouseDrag && dragWindowId == i) { sequence.nodeRect.x += Event.current.delta.x; sequence.nodeRect.y += Event.current.delta.y; forceRepaintCount = 6; } else if (Event.current.type == EventType.MouseUp && dragWindowId == i) { Vector2 newPos = new Vector2(sequence.nodeRect.x, sequence.nodeRect.y); sequence.nodeRect.x = startDragPosition.x; sequence.nodeRect.y = startDragPosition.y; Undo.RecordObject(sequence, "Node Position"); sequence.nodeRect.x = newPos.x; sequence.nodeRect.y = newPos.y; dragWindowId = -1; forceRepaintCount = 6; } } Rect windowRect = new Rect(sequence.nodeRect); windowRect.x += fungusScript.scrollPos.x; windowRect.y += fungusScript.scrollPos.y; GUILayout.Window(i, windowRect, DrawWindow, "", windowStyle); GUI.backgroundColor = Color.white; windowSequenceMap.Add(sequence); } EndWindows(); // Draw play icons beside all executing sequences if (Application.isPlaying) { foreach (Sequence s in sequences) { if (s.IsExecuting()) { s.executingIconTimer = playIconFadeTime; forceRepaintCount = 6; } if (s.executingIconTimer > 0f) { s.executingIconTimer = Mathf.Max(s.executingIconTimer - Time.deltaTime, 0f); Rect rect = new Rect(s.nodeRect); rect.x += fungusScript.scrollPos.x - 37; rect.y += fungusScript.scrollPos.y + 3; rect.width = 34; rect.height = 34; if (!s.IsExecuting() && s.executingIconTimer < playIconFadeTime) { float alpha = s.executingIconTimer / playIconFadeTime; GUI.color = new Color(1f, 1f, 1f, alpha); } if (GUI.Button(rect, FungusEditorResources.texPlayBig as Texture, new GUIStyle())) { SelectSequence(fungusScript, s); } GUI.color = Color.white; } } } // Right click to drag view if (Event.current.button == 1 && Event.current.type == EventType.MouseDrag) { fungusScript.scrollPos += Event.current.delta; forceRepaintCount = 6; } else if (Event.current.type == EventType.ScrollWheel) { fungusScript.zoom -= Event.current.delta.y * 0.01f; fungusScript.zoom = Mathf.Clamp(fungusScript.zoom, minZoomValue, maxZoomValue); forceRepaintCount = 6; } GLDraw.EndGroup(); EditorZoomArea.End(); }