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.
68 lines
2.1 KiB
68 lines
2.1 KiB
9 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
|
|
||
11 years ago
|
using UnityEngine;
|
||
|
|
||
11 years ago
|
namespace Fungus
|
||
11 years ago
|
{
|
||
9 years ago
|
/// <summary>
|
||
|
/// Marks the start of a command block to be executed when the preceding If statement is False.
|
||
|
/// </summary>
|
||
9 years ago
|
[CommandInfo("Flow",
|
||
|
"Else",
|
||
|
"Marks the start of a command block to be executed when the preceding If statement is False.")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class Else : Command
|
||
|
{
|
||
|
public override void OnEnter()
|
||
|
{
|
||
9 years ago
|
if (ParentBlock == null)
|
||
9 years ago
|
{
|
||
|
return;
|
||
|
}
|
||
11 years ago
|
|
||
9 years ago
|
// Stop if this is the last command in the list
|
||
9 years ago
|
if (CommandIndex >= ParentBlock.CommandList.Count - 1)
|
||
9 years ago
|
{
|
||
|
StopParentBlock();
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
// Find the next End command at the same indent level as this Else command
|
||
|
int indent = indentLevel;
|
||
9 years ago
|
for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i)
|
||
9 years ago
|
{
|
||
9 years ago
|
Command command = ParentBlock.CommandList[i];
|
||
9 years ago
|
|
||
9 years ago
|
if (command.IndentLevel == indent)
|
||
9 years ago
|
{
|
||
|
System.Type type = command.GetType();
|
||
|
if (type == typeof(End))
|
||
|
{
|
||
|
// Execute command immediately after the EndIf command
|
||
9 years ago
|
Continue(command.CommandIndex + 1);
|
||
9 years ago
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// No End command found
|
||
|
StopParentBlock();
|
||
|
}
|
||
10 years ago
|
|
||
9 years ago
|
public override bool OpenBlock()
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
11 years ago
|
|
||
9 years ago
|
public override bool CloseBlock()
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
11 years ago
|
|
||
9 years ago
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(253, 253, 150, 255);
|
||
|
}
|
||
|
}
|
||
11 years ago
|
}
|