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.
62 lines
2.0 KiB
62 lines
2.0 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>
|
||
|
/// Continuously loop through a block of commands while the condition is true. Use the Break command to force the loop to terminate immediately.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Flow",
|
||
|
"While",
|
||
|
"Continuously loop through a block of commands while the condition is true. Use the Break command to force the loop to terminate immediately.")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class While : If
|
||
|
{
|
||
|
public override void OnEnter()
|
||
|
{
|
||
|
bool execute = true;
|
||
|
if (variable != null)
|
||
|
{
|
||
|
execute = EvaluateCondition();
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
// Find next End statement at same indent level
|
||
|
End endCommand = null;
|
||
8 years ago
|
for (int i = CommandIndex + 1; i < ParentBlock.CommandList.Count; ++i)
|
||
8 years ago
|
{
|
||
8 years ago
|
End command = ParentBlock.CommandList[i] as End;
|
||
8 years ago
|
|
||
|
if (command != null &&
|
||
8 years ago
|
command.IndentLevel == indentLevel)
|
||
8 years ago
|
{
|
||
|
endCommand = command;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
if (execute)
|
||
|
{
|
||
|
// Tell the following end command to loop back
|
||
8 years ago
|
endCommand.Loop = true;
|
||
8 years ago
|
Continue();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// Continue at next command after End
|
||
8 years ago
|
Continue (endCommand.CommandIndex + 1);
|
||
8 years ago
|
}
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override bool OpenBlock()
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
10 years ago
|
|
||
8 years ago
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(253, 253, 150, 255);
|
||
|
}
|
||
8 years ago
|
}
|
||
10 years ago
|
}
|