You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
136 lines
4.5 KiB
136 lines
4.5 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
10 years ago
|
using UnityEngine;
|
||
10 years ago
|
using UnityEngine.Serialization;
|
||
10 years ago
|
using System.Collections.Generic;
|
||
10 years ago
|
using System;
|
||
10 years ago
|
|
||
10 years ago
|
namespace Fungus
|
||
10 years ago
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Execute another block in the same Flowchart as the command, or in a different Flowchart.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Flow",
|
||
|
"Call",
|
||
|
"Execute another block in the same Flowchart as the command, or in a different Flowchart.")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class Call : Command
|
||
|
{
|
||
|
[Tooltip("Flowchart which contains the block to execute. If none is specified then the current Flowchart is used.")]
|
||
8 years ago
|
[SerializeField] protected Flowchart targetFlowchart;
|
||
8 years ago
|
|
||
|
[FormerlySerializedAs("targetSequence")]
|
||
|
[Tooltip("Block to start executing")]
|
||
8 years ago
|
[SerializeField] protected Block targetBlock;
|
||
8 years ago
|
|
||
|
[Tooltip("Command index to start executing")]
|
||
9 years ago
|
[FormerlySerializedAs("commandIndex")]
|
||
8 years ago
|
[SerializeField] protected int startIndex;
|
||
8 years ago
|
|
||
|
public enum CallMode
|
||
|
{
|
||
|
Stop, // Stop executing the current block after calling
|
||
|
Continue, // Continue executing the current block after calling
|
||
|
WaitUntilFinished // Wait until the called block finishes executing, then continue executing current block
|
||
|
}
|
||
|
|
||
|
[Tooltip("Select if the calling block should stop or continue executing commands, or wait until the called block finishes.")]
|
||
8 years ago
|
[SerializeField] protected CallMode callMode;
|
||
8 years ago
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
|
Flowchart flowchart = GetFlowchart();
|
||
|
|
||
|
if (targetBlock != null)
|
||
|
{
|
||
|
// Check if calling your own parent block
|
||
8 years ago
|
if (targetBlock == ParentBlock)
|
||
8 years ago
|
{
|
||
|
// Just ignore the callmode in this case, and jump to first command in list
|
||
|
Continue(0);
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
// Callback action for Wait Until Finished mode
|
||
|
Action onComplete = null;
|
||
|
if (callMode == CallMode.WaitUntilFinished)
|
||
|
{
|
||
|
onComplete = delegate {
|
||
8 years ago
|
flowchart.SelectedBlock = ParentBlock;
|
||
8 years ago
|
Continue();
|
||
|
};
|
||
|
}
|
||
|
|
||
|
if (targetFlowchart == null ||
|
||
|
targetFlowchart == GetFlowchart())
|
||
|
{
|
||
|
// If the executing block is currently selected then follow the execution
|
||
|
// onto the next block in the inspector.
|
||
8 years ago
|
if (flowchart.SelectedBlock == ParentBlock)
|
||
8 years ago
|
{
|
||
8 years ago
|
flowchart.SelectedBlock = targetBlock;
|
||
8 years ago
|
}
|
||
10 years ago
|
|
||
9 years ago
|
StartCoroutine(targetBlock.Execute(startIndex, onComplete));
|
||
8 years ago
|
}
|
||
|
else
|
||
|
{
|
||
|
// Execute block in another Flowchart
|
||
9 years ago
|
targetFlowchart.ExecuteBlock(targetBlock, startIndex, onComplete);
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
|
if (callMode == CallMode.Stop)
|
||
|
{
|
||
|
StopParentBlock();
|
||
|
}
|
||
|
else if (callMode == CallMode.Continue)
|
||
|
{
|
||
|
Continue();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override void GetConnectedBlocks(ref List<Block> connectedBlocks)
|
||
|
{
|
||
|
if (targetBlock != null)
|
||
|
{
|
||
|
connectedBlocks.Add(targetBlock);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
string summary = "";
|
||
|
|
||
|
if (targetBlock == null)
|
||
|
{
|
||
|
summary = "<None>";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
8 years ago
|
summary = targetBlock.BlockName;
|
||
8 years ago
|
}
|
||
|
|
||
|
switch (callMode)
|
||
|
{
|
||
|
case CallMode.Stop:
|
||
|
summary += " : Stop";
|
||
|
break;
|
||
|
case CallMode.Continue:
|
||
|
summary += " : Continue";
|
||
|
break;
|
||
|
case CallMode.WaitUntilFinished:
|
||
|
summary += " : Wait";
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
return summary;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(235, 191, 217, 255);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|