void OnCommandExecute(Block block, Command command, int commandIndex, int maxCommandIndex) { IntegrationTest.Assert(commandIndex == 0); IntegrationTest.Assert(maxCommandIndex == 1); IntegrationTest.Assert(command.GetType() == typeof(Wait)); commandExecuted = true; }
public virtual void Continue(Command currentCommand) { OnExit(); Sequence sequence = GetSequence(); if (sequence != null) { sequence.ExecuteNextCommand(currentCommand); } }
public void DrawCommandUI(Flowchart flowchart, Command inspectCommand) { ResizeScrollView(flowchart); GUILayout.Space(7); activeBlockEditor.DrawButtonToolbar(); commandScrollPos = GUILayout.BeginScrollView(commandScrollPos); if (inspectCommand != null) { if (activeCommandEditor == null || inspectCommand != activeCommandEditor.target) { // See if we have a cached version of the command editor already, var editors = (from e in cachedCommandEditors where (e != null && e.target == inspectCommand) select e); if (editors.Count() > 0) { // Use cached editor activeCommandEditor = editors.First(); } else { // No cached editor, so create a new one. activeCommandEditor = Editor.CreateEditor(inspectCommand) as CommandEditor; cachedCommandEditors.Add(activeCommandEditor); } } if (activeCommandEditor != null) { activeCommandEditor.DrawCommandInspectorGUI(); } } GUILayout.EndScrollView(); GUILayout.EndArea(); // Draw the resize bar after everything else has finished drawing // This is mainly to avoid incorrect indenting. Rect resizeRect = new Rect(0, topPanelHeight + flowchart.blockViewHeight + 1, Screen.width, 4f); GUI.color = new Color(0.64f, 0.64f, 0.64f); GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); resizeRect.height = 1; GUI.color = new Color32(132, 132, 132, 255); GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); resizeRect.y += 3; GUI.DrawTexture(resizeRect, EditorGUIUtility.whiteTexture); GUI.color = Color.white; Repaint(); }
public static string ParseClassToCSVCMD(Fungus.Command cmd) { if (cmd.GetType().Name == "Say") { return(""); } for (int i = 0; i < AdvUtility.CSVCommandMapping.GetLength(0); i++) { if (System.String.Equals(cmd.GetType().Name, AdvUtility.CSVCommandMapping[i, 1], System.StringComparison.OrdinalIgnoreCase)) { return(AdvUtility.CSVCommandMapping[i, 0]); } } return(""); }
public void StartRemove() { foreach (var item in willRemove) { sourceObject.csvLines.Remove(item); Fungus.Command cmd = item.generatedCommand; if (cmd != null) { string msg = string.Format("Remove deleted cmd : {0} -> {1} -> {2} & {3}", cmd.gameObject.name, AdvUtility.FindParentBlock(cmd).BlockName, cmd.ItemId, item.keys); Debug.Log(msg); AdvUtility.FindParentBlock(cmd).CommandList.Remove(cmd); Object.DestroyImmediate(cmd, true); } } willRemove.Clear(); }
public void ExecuteNextCommand(Command currentCommand = null) { if (currentCommand == null) { executionCount++; } activeCommand = null; Command nextCommand = null; bool executeNext = (currentCommand == null); foreach (Command command in commandList) { if (command == currentCommand) { executeNext = true; } else if (executeNext) { if (command.enabled) { nextCommand = command; break; } } } if (nextCommand == null) { Stop(); } else { FungusScript fungusScript = GetFungusScript(); if (fungusScript.stepTime == 0f) { activeCommand = nextCommand; nextCommand.Execute(); } else { StartCoroutine(ExecuteAfterDelay(nextCommand, fungusScript.stepTime)); } } }
void UpdateData(string Result) { string sourceCSV = Result; Fungus.FlowchartExtend sourceObject = pageRef.prefab; sourceObject.GoogleSheetID = spreadsheetId; sourceObject.GooglePageID = sheet_gid; List <AdvCSVLine> outdate = AdvUtility.UpdateBlockByCSV(sourceObject, sourceCSV, option, true); List <AdvCSVLine> willRemove = outdate; UnityEditor.EditorUtility.SetDirty(sourceObject.gameObject); PrefabUtility.SavePrefabAsset(sourceObject.gameObject); if (willRemove == null) { return; } if (popupDetal) { AdvPrefabUpdateResult.OpenWindow(sourceObject, willRemove); return; } if (!autoRemove) { return; } foreach (var item in willRemove) { sourceObject.csvLines.Remove(item); Fungus.Command cmd = item.generatedCommand; if (cmd != null) { string msg = string.Format("Auto remove update lost cmd ... {0} -> {1} -> {2}&cmd{3}", cmd.gameObject.name, AdvUtility.FindParentBlock(cmd).BlockName, cmd.ItemId, item.keys); Debug.Log(msg); AdvUtility.FindParentBlock(cmd).CommandList.Remove(cmd); Object.DestroyImmediate(cmd); } } willRemove.Clear(); }
public override void OnInspectorGUI () { BlockInspector blockInspector = target as BlockInspector; Block block = blockInspector.block; if (block == null) { return; } Flowchart flowchart = block.GetFlowchart(); if (activeBlockEditor == null || block != activeBlockEditor.target) { DestroyImmediate(activeBlockEditor); activeBlockEditor = Editor.CreateEditor(block) as BlockEditor; } activeBlockEditor.DrawBlockName(flowchart); // Using a custom rect area to get the correct 5px indent for the scroll views Rect blockRect = new Rect(5, topPanelHeight, Screen.width - 6, Screen.height - 70); GUILayout.BeginArea(blockRect); blockScrollPos = GUILayout.BeginScrollView(blockScrollPos, GUILayout.Height(flowchart.blockViewHeight)); activeBlockEditor.DrawBlockGUI(flowchart); GUILayout.EndScrollView(); Command inspectCommand = null; if (flowchart.selectedCommands.Count == 1) { inspectCommand = flowchart.selectedCommands[0]; } if (Application.isPlaying && inspectCommand != null && inspectCommand.parentBlock != block) { GUILayout.EndArea(); Repaint(); return; } // Only change the activeCommand at the start of the GUI call sequence if (Event.current.type == EventType.Layout) { activeCommand = inspectCommand; } DrawCommandUI(flowchart, inspectCommand); }
public void AddCommand(Command command) { commandList.Add(command); }
/// <summary> /// A coroutine method that executes all commands in the Block. Only one running instance of each Block is permitted. /// </summary> /// <param name="commandIndex">Index of command to start execution at</param> /// <param name="onComplete">Delegate function to call when execution completes</param> public virtual IEnumerator Execute(int commandIndex = 0, Action onComplete = null) { if (executionState != ExecutionState.Idle) { yield break; } if (!executionInfoSet) { SetExecutionInfo(); } executionCount++; var flowchart = GetFlowchart(); executionState = ExecutionState.Executing; BlockSignals.DoBlockStart(this); #if UNITY_EDITOR // Select the executing block & the first command flowchart.SelectedBlock = this; if (commandList.Count > 0) { flowchart.ClearSelectedCommands(); flowchart.AddSelectedCommand(commandList[0]); } #endif jumpToCommandIndex = commandIndex; int i = 0; while (true) { // Executing commands specify the next command to skip to by setting jumpToCommandIndex using Command.Continue() if (jumpToCommandIndex > -1) { i = jumpToCommandIndex; jumpToCommandIndex = -1; } // Skip disabled commands, comments and labels while (i < commandList.Count && (!commandList[i].enabled || commandList[i].GetType() == typeof(Comment) || commandList[i].GetType() == typeof(Label))) { i = commandList[i].CommandIndex + 1; } if (i >= commandList.Count) { break; } // The previous active command is needed for if / else / else if commands if (activeCommand == null) { previousActiveCommandIndex = -1; } else { previousActiveCommandIndex = activeCommand.CommandIndex; } var command = commandList[i]; activeCommand = command; if (flowchart.IsActive()) { // Auto select a command in some situations if ((flowchart.SelectedCommands.Count == 0 && i == 0) || (flowchart.SelectedCommands.Count == 1 && flowchart.SelectedCommands[0].CommandIndex == previousActiveCommandIndex)) { flowchart.ClearSelectedCommands(); flowchart.AddSelectedCommand(commandList[i]); } } command.IsExecuting = true; // This icon timer is managed by the FlowchartWindow class, but we also need to // set it here in case a command starts and finishes execution before the next window update. command.ExecutingIconTimer = Time.realtimeSinceStartup + FungusConstants.ExecutingIconFadeTime; BlockSignals.DoCommandExecute(this, command, i, commandList.Count); command.Execute(); // Wait until the executing command sets another command to jump to via Command.Continue() while (jumpToCommandIndex == -1) { yield return null; } #if UNITY_EDITOR if (flowchart.StepPause > 0f) { yield return new WaitForSeconds(flowchart.StepPause); } #endif command.IsExecuting = false; } executionState = ExecutionState.Idle; activeCommand = null; BlockSignals.DoBlockEnd(this); if (onComplete != null) { onComplete(); } }
public void Stop() { FungusScript fungusScript = GetFungusScript(); if (fungusScript == null) { return; } activeCommand = null; fungusScript.executingSequence = null; fungusScript.selectedSequence = null; fungusScript.selectedCommand = null; }
IEnumerator ExecuteAfterDelay(Command command, float delay) { activeCommand = command; yield return new WaitForSeconds(delay); command.Execute(); }
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(); } } } }
public virtual void Stop() { FungusScript fungusScript = GetFungusScript(); if (fungusScript == null) { return; } activeCommand = null; fungusScript.ClearSelectedCommands(); }