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