void OnBlockEnd(Block block) { IntegrationTest.Assert(started); IntegrationTest.Assert(commandExecuted); IntegrationTest.Pass(); }
protected virtual IEnumerator WaitForTimeout(float timeoutDuration, Block targetBlock) { float elapsedTime = 0; Slider timeoutSlider = GetComponentInChildren<Slider>(); while (elapsedTime < timeoutDuration) { if (timeoutSlider != null) { float t = 1f - elapsedTime / timeoutDuration; timeoutSlider.value = t; } elapsedTime += Time.deltaTime; yield return null; } Clear(); gameObject.SetActive(false); HideSayDialog(); if (targetBlock != null) { targetBlock.StartExecution(); } }
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 override bool AddOption(string text, bool interactable, bool hideOption, Fungus.Block targetBlock) { var result = base.AddOption(text, interactable, hideOption, targetBlock); ShowDividers(); return(result); }
void OnBlockEnd(Fungus.Block block) { if (block.BlockName.Equals("End")) { Fungus.BlockSignals.OnBlockEnd -= OnBlockEnd; dialogInProgress = false; } }
public override void OnCommandAdded(Block parentBlock) { // Add an empty slot by default. Saves an unnecessary user click. if (targetObjects.Count == 0) { targetObjects.Add(null); } }
public static void AutoLinkCSVLine(Fungus.FlowchartExtend sourceObject) { if (sourceObject == null) { return; } List <AdvCSVLine> csvLineData = sourceObject.csvLines; List <AdvCSVLine> csvLineBlocks = new List <AdvCSVLine>(); //Get base CSV info foreach (var item in csvLineData) { if (item.Command.StartsWith("*")) { csvLineBlocks.Add(item); } } //Start auto link List <Fungus.Command> comps = new List <Fungus.Command>(sourceObject.GetComponents <Fungus.Command>()); for (int i = 0; i < csvLineData.Count; i++) { for (int j = comps.Count - 1; j >= 0; j--) { ICommand icmd = comps[j] as ICommand; if (icmd != null && csvLineData[i].keys == icmd.CSVCommandKey) { //if(csvLineData[i].generatedCommand == null) Debug.Log($"Find unlink CSVLine ,will be linked :{csvLineData[i].keys}"); csvLineData[i].generatedCommand = comps[j]; comps.RemoveAt(j); break; } } } foreach (var item in csvLineBlocks) { if (item.generateBlock == null) { Fungus.Block _block = sourceObject.FindBlock(item.Command); if (_block != null) { item.generateBlock = _block; } } } }
public virtual bool AddOption(string text, Block targetBlock) { bool addedOption = false; foreach (Button button in cachedButtons) { if (!button.gameObject.activeSelf) { button.gameObject.SetActive(true); Text textComponent = button.GetComponentInChildren<Text>(); if (textComponent != null) { textComponent.text = text; } Block block = targetBlock; button.onClick.AddListener(delegate { StopAllCoroutines(); // Stop timeout Clear(); HideSayDialog(); if (block != null) { #if UNITY_EDITOR // Select the new target block in the Flowchart window Flowchart flowchart = block.GetFlowchart(); flowchart.selectedBlock = block; #endif gameObject.SetActive(false); block.Execute(); } }); addedOption = true; break; } } return addedOption; }
static public void LabelField(SerializedProperty property, GUIContent labelText, Block block) { List<string> labelKeys = new List<string>(); List<Label> labelObjects = new List<Label>(); labelKeys.Add("<None>"); labelObjects.Add(null); Label selectedLabel = property.objectReferenceValue as Label; int index = 0; int selectedIndex = 0; foreach (Command command in block.commandList) { Label label = command as Label; if (label == null) { continue; } labelKeys.Add(label.key); labelObjects.Add(label); index++; if (label == selectedLabel) { selectedIndex = index; } } selectedIndex = EditorGUILayout.Popup(labelText.text, selectedIndex, labelKeys.ToArray()); property.objectReferenceValue = labelObjects[selectedIndex]; }
public static Block BlockField(Rect position, GUIContent nullLabel, Flowchart flowchart, Block block) { if (flowchart == null) { return null; } Block result = block; // Build dictionary of child blocks List<GUIContent> blockNames = new List<GUIContent>(); int selectedIndex = 0; blockNames.Add(nullLabel); Block[] blocks = flowchart.GetComponentsInChildren<Block>(); for (int i = 0; i < blocks.Length; ++i) { blockNames.Add(new GUIContent(blocks[i].name)); if (block == blocks[i]) { selectedIndex = i + 1; } } selectedIndex = EditorGUI.Popup(position, selectedIndex, blockNames.ToArray()); if (selectedIndex == 0) { result = null; // Option 'None' } else { result = blocks[selectedIndex - 1]; } return result; }
private void ResetFastForwardingFlag(Fungus.Block block) { dialogInput.ResetFastForwardingFlag(); dialogInput2.ResetFastForwardingFlag(); }
public override void OnCommandAdded(Block parentBlock) { targetObjects.Add(null); }
public override void OnCommandAdded(Block parentBlock) { //Default to display type: show display = DisplayType.Show; }
/// <summary> /// Adds the option to the list of displayed options. Calls a Block when selected. /// Will cause the Menu dialog to become visible if it is not already visible. /// </summary> /// <returns><c>true</c>, if the option was added successfully.</returns> /// <param name="text">The option text to display on the button.</param> /// <param name="interactable">If false, the option is displayed but is not selectable.</param> /// <param name="targetBlock">Block to execute when the option is selected.</param> public virtual bool AddOption(string text, bool interactable, Block targetBlock) { bool addedOption = false; for (int i = 0; i < cachedButtons.Length; i++) { var button = cachedButtons[i]; if (!button.gameObject.activeSelf) { button.gameObject.SetActive(true); button.interactable = interactable; if (interactable && autoSelectFirstButton && !cachedButtons.Select(x => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject)) { EventSystem.current.SetSelectedGameObject(button.gameObject); } Text textComponent = button.GetComponentInChildren<Text>(); if (textComponent != null) { textComponent.text = text; } var block = targetBlock; button.onClick.AddListener(delegate { EventSystem.current.SetSelectedGameObject(null); StopAllCoroutines(); // Stop timeout Clear(); HideSayDialog(); if (block != null) { var flowchart = block.GetFlowchart(); #if UNITY_EDITOR // Select the new target block in the Flowchart window flowchart.SelectedBlock = block; #endif gameObject.SetActive(false); // Use a coroutine to call the block on the next frame // Have to use the Flowchart gameobject as the MenuDialog is now inactive flowchart.StartCoroutine(CallBlock(block)); } }); addedOption = true; break; } } return addedOption; }
protected IEnumerator CallBlock(Block block) { yield return new WaitForEndOfFrame(); block.StartExecution(); }
void OnBlockStart(Block block) { IntegrationTest.Assert(block.BlockName == "Start"); started = true; }
/** * Called when the command is deleted from a block in the editor. */ public virtual void OnCommandRemoved(Block parentBlock) { }
/** * Called when the new command is added to a block in the editor. */ public virtual void OnCommandAdded(Block parentBlock) { }
protected virtual void DeleteBlock(Flowchart flowchart, Block block) { foreach (Command command in block.commandList) { Undo.DestroyObjectImmediate(command); } Undo.DestroyObjectImmediate(block); flowchart.ClearSelectedCommands(); }
public virtual void CalcFlowchartCenter(Flowchart flowchart, Block[] blocks) { if (flowchart == null || blocks.Count() == 0) { return; } Vector2 min = blocks[0].nodeRect.min; Vector2 max = blocks[0].nodeRect.max; foreach (Block block in blocks) { min.x = Mathf.Min(min.x, block.nodeRect.center.x); min.y = Mathf.Min(min.y, block.nodeRect.center.y); max.x = Mathf.Max(max.x, block.nodeRect.center.x); max.y = Mathf.Max(max.y, block.nodeRect.center.y); } Vector2 center = (min + max) * -0.5f; center.x += position.width * 0.5f; center.y += position.height * 0.5f; flowchart.centerPosition = center; }
protected virtual void UpdateIndentLevels(Block block) { int indentLevel = 0; foreach(Command command in block.commandList) { if (command == null) { continue; } if (command.CloseBlock()) { indentLevel--; } command.indentLevel = Math.Max(indentLevel, 0); if (command.OpenBlock()) { indentLevel++; } } }
public virtual void ShowTimer(float duration, Block targetBlock) { if (cachedSlider != null) { cachedSlider.gameObject.SetActive(true); StopAllCoroutines(); StartCoroutine(WaitForTimeout(duration, targetBlock)); } }
protected IEnumerator RunBlock(Flowchart flowchart, Block targetBlock, int commandIndex, float delay) { yield return new WaitForSeconds(delay); flowchart.ExecuteBlock(targetBlock, commandIndex); }
protected virtual void SelectBlock(Flowchart flowchart, Block block) { // Select the block and also select currently executing command ShowBlockInspector(flowchart); flowchart.selectedBlock = block; flowchart.ClearSelectedCommands(); if (block.activeCommand != null) { flowchart.AddSelectedCommand(block.activeCommand); } }
public override void OnCommandAdded(Block parentBlock) { // Add a default empty entry targetSprites.Add(null); }
protected virtual void DrawConnections(Flowchart flowchart, Block block, bool highlightedOnly) { if (block == null) { return; } List<Block> connectedBlocks = new List<Block>(); bool blockIsSelected = (flowchart.selectedBlock == block); foreach (Command command in block.commandList) { if (command == null) { continue; } bool commandIsSelected = false; foreach (Command selectedCommand in flowchart.selectedCommands) { if (selectedCommand == command) { commandIsSelected = true; break; } } bool highlight = command.isExecuting || (blockIsSelected && commandIsSelected); if (highlightedOnly && !highlight || !highlightedOnly && highlight) { continue; } connectedBlocks.Clear(); command.GetConnectedBlocks(ref connectedBlocks); foreach (Block blockB in connectedBlocks) { if (blockB == null || block == blockB || blockB.GetFlowchart() != flowchart) { continue; } Rect startRect = new Rect(block.nodeRect); startRect.x += flowchart.scrollPos.x; startRect.y += flowchart.scrollPos.y; Rect endRect = new Rect(blockB.nodeRect); endRect.x += flowchart.scrollPos.x; endRect.y += flowchart.scrollPos.y; DrawRectConnection(startRect, endRect, highlight); } } }
public virtual bool AddOption(string text, bool interactable, Block targetBlock) { bool addedOption = false; foreach (Button button in cachedButtons) { if (!button.gameObject.activeSelf) { button.gameObject.SetActive(true); button.interactable = interactable; if (interactable && autoSelectFirstButton && !cachedButtons.Select((x) => x.gameObject).Contains(EventSystem.current.currentSelectedGameObject)) { EventSystem.current.SetSelectedGameObject(button.gameObject); } Text textComponent = button.GetComponentInChildren<Text>(); if (textComponent != null) { textComponent.text = text; } Block block = targetBlock; button.onClick.AddListener(delegate { EventSystem.current.SetSelectedGameObject(null); StopAllCoroutines(); // Stop timeout Clear(); HideSayDialog(); if (block != null) { #if UNITY_EDITOR // Select the new target block in the Flowchart window Flowchart flowchart = block.GetFlowchart(); flowchart.selectedBlock = block; #endif gameObject.SetActive(false); block.StartExecution(); } }); addedOption = true; break; } } return addedOption; }