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.
76 lines
2.1 KiB
76 lines
2.1 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;
|
||
9 years ago
|
using UnityEngine.Serialization;
|
||
10 years ago
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Move execution to a specific Label command in the same block.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Flow",
|
||
|
"Jump",
|
||
|
"Move execution to a specific Label command in the same block")]
|
||
|
[AddComponentMenu("")]
|
||
9 years ago
|
[ExecuteInEditMode]
|
||
8 years ago
|
public class Jump : Command
|
||
|
{
|
||
9 years ago
|
[Tooltip("Name of a label in this block to jump to")]
|
||
8 years ago
|
[SerializeField] protected StringData _targetLabel = new StringData("");
|
||
10 years ago
|
|
||
8 years ago
|
public override void OnEnter()
|
||
|
{
|
||
|
if (_targetLabel.Value == "")
|
||
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
foreach (Command command in ParentBlock.CommandList)
|
||
8 years ago
|
{
|
||
|
Label label = command as Label;
|
||
|
if (label != null &&
|
||
8 years ago
|
label.Key == _targetLabel.Value)
|
||
8 years ago
|
{
|
||
8 years ago
|
Continue(label.CommandIndex + 1);
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
|
// Label not found
|
||
|
Debug.LogWarning("Label not found: " + _targetLabel.Value);
|
||
|
Continue();
|
||
8 years ago
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override string GetSummary()
|
||
|
{
|
||
|
if (_targetLabel.Value == "")
|
||
|
{
|
||
|
return "Error: No label selected";
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
return _targetLabel.Value;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(253, 253, 150, 255);
|
||
|
}
|
||
9 years ago
|
|
||
|
#region Backwards compatibility
|
||
|
|
||
|
[HideInInspector] [FormerlySerializedAs("targetLabel")] public Label targetLabelOLD;
|
||
|
|
||
|
protected virtual void OnEnable()
|
||
|
{
|
||
|
if (targetLabelOLD != null)
|
||
|
{
|
||
8 years ago
|
_targetLabel.Value = targetLabelOLD.Key;
|
||
9 years ago
|
targetLabelOLD = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
8 years ago
|
}
|
||
10 years ago
|
}
|