Inheritance: Fungus.Node
Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
    public override bool AddOption(string text, bool interactable, bool hideOption, Fungus.Block targetBlock)
    {
        var result = base.AddOption(text, interactable, hideOption, targetBlock);

        ShowDividers();
        return(result);
    }
Ejemplo n.º 5
0
 void OnBlockEnd(Fungus.Block block)
 {
     if (block.BlockName.Equals("End"))
     {
         Fungus.BlockSignals.OnBlockEnd -= OnBlockEnd;
         dialogInProgress = false;
     }
 }
Ejemplo n.º 6
0
 public override void OnCommandAdded(Block parentBlock)
 {
     // Add an empty slot by default. Saves an unnecessary user click.
     if (targetObjects.Count == 0)
     {
         targetObjects.Add(null);
     }
 }
Ejemplo n.º 7
0
    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;
                }
            }
        }
    }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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];
        }
Ejemplo n.º 10
0
        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;
        }
Ejemplo n.º 11
0
 private void ResetFastForwardingFlag(Fungus.Block block)
 {
     dialogInput.ResetFastForwardingFlag();
     dialogInput2.ResetFastForwardingFlag();
 }
Ejemplo n.º 12
0
		public override void OnCommandAdded(Block parentBlock)
		{
			targetObjects.Add(null);
		}
Ejemplo n.º 13
0
		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();
 }
Ejemplo n.º 16
0
        void OnBlockStart(Block block)
        {
            IntegrationTest.Assert(block.BlockName == "Start");

            started = true;
        }
Ejemplo n.º 17
0
 /**
  * Called when the command is deleted from a block in the editor.
  */
 public virtual void OnCommandRemoved(Block parentBlock)
 {
 }
Ejemplo n.º 18
0
 /**
  * Called when the new command is added to a block in the editor.
  */
 public virtual void OnCommandAdded(Block parentBlock)
 {
 }
Ejemplo n.º 19
0
 protected virtual void DeleteBlock(Flowchart flowchart, Block block)
 {
     foreach (Command command in block.commandList)
     {
         Undo.DestroyObjectImmediate(command);
     }
     
     Undo.DestroyObjectImmediate(block);
     flowchart.ClearSelectedCommands();
 }
Ejemplo n.º 20
0
        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;
        }
Ejemplo n.º 21
0
        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++;
                }
            }
        }
Ejemplo n.º 22
0
		public virtual void ShowTimer(float duration, Block targetBlock)
		{

			if (cachedSlider != null)
			{
				cachedSlider.gameObject.SetActive(true);
				StopAllCoroutines();
				StartCoroutine(WaitForTimeout(duration, targetBlock));
			}
		}
Ejemplo n.º 23
0
 protected IEnumerator RunBlock(Flowchart flowchart, Block targetBlock, int commandIndex, float delay)
 {
     yield return new WaitForSeconds(delay);
     flowchart.ExecuteBlock(targetBlock, commandIndex);
 }
Ejemplo n.º 24
0
 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);
     }
 }
Ejemplo n.º 25
0
		public override void OnCommandAdded(Block parentBlock)
		{
			// Add a default empty entry
			targetSprites.Add(null);
		}
Ejemplo n.º 26
0
        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);
                }
            }
        }
Ejemplo n.º 27
0
        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;
        }