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.
77 lines
2.6 KiB
77 lines
2.6 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;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Marks the start of a command block to be executed when the preceding If statement is False and the test expression is true.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Flow",
|
||
|
"Else If",
|
||
|
"Marks the start of a command block to be executed when the preceding If statement is False and the test expression is true.")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class ElseIf : If
|
||
|
{
|
||
|
public override void OnEnter()
|
||
|
{
|
||
8 years ago
|
System.Type previousCommandType = ParentBlock.GetPreviousActiveCommandType();
|
||
10 years ago
|
|
||
8 years ago
|
if (previousCommandType == typeof(If) ||
|
||
|
previousCommandType == typeof(ElseIf) )
|
||
|
{
|
||
|
// Else If behaves the same as an If command
|
||
|
EvaluateAndContinue();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Else If behaves mostly like an Else command,
|
||
|
// but will also jump to a following Else command.
|
||
10 years ago
|
|
||
8 years ago
|
// Stop if this is the last command in the list
|
||
8 years ago
|
if (CommandIndex >= ParentBlock.CommandList.Count - 1)
|
||
8 years ago
|
{
|
||
|
StopParentBlock();
|
||
|
return;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
// Find the next End command at the same indent level as this Else If command
|
||
|
int indent = indentLevel;
|
||
8 years ago
|
for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i)
|
||
8 years ago
|
{
|
||
8 years ago
|
Command command = ParentBlock.CommandList[i];
|
||
10 years ago
|
|
||
8 years ago
|
if (command.IndentLevel == indent)
|
||
8 years ago
|
{
|
||
|
System.Type type = command.GetType();
|
||
|
if (type == typeof(End))
|
||
|
{
|
||
|
// Execute command immediately after the Else or End command
|
||
8 years ago
|
Continue(command.CommandIndex + 1);
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
// No End command found
|
||
|
StopParentBlock();
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override bool OpenBlock()
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override bool CloseBlock()
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(253, 253, 150, 255);
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|