chrisgregan
10 years ago
5 changed files with 132 additions and 0 deletions
@ -0,0 +1,40 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CommandInfo("Scripting", |
||||
"Break", |
||||
"Force a loop to terminate immediately.")] |
||||
[AddComponentMenu("")] |
||||
public class Break : Command |
||||
{ |
||||
public override void OnEnter() |
||||
{ |
||||
// Find next End statement at -1 relative indent level |
||||
for (int i = commandIndex + 1; i < parentSequence.commandList.Count; ++i) |
||||
{ |
||||
End endCommand = parentSequence.commandList[i] as End; |
||||
|
||||
if (endCommand != null && |
||||
endCommand.indentLevel == indentLevel - 1) |
||||
{ |
||||
// Continue at next command after End |
||||
Continue (endCommand.commandIndex + 1); |
||||
return; |
||||
} |
||||
} |
||||
|
||||
// No matching End command found so just continue |
||||
Continue(); |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(253, 253, 150, 255); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: c9b9c7a9785c34fc889da2b3a40344db |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
@ -0,0 +1,59 @@
|
||||
using UnityEngine; |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
[CommandInfo("Scripting", |
||||
"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(); |
||||
} |
||||
|
||||
// Find next End statement at same indent level |
||||
End endCommand = null; |
||||
for (int i = commandIndex + 1; i < parentSequence.commandList.Count; ++i) |
||||
{ |
||||
End command = parentSequence.commandList[i] as End; |
||||
|
||||
if (command != null && |
||||
command.indentLevel == indentLevel) |
||||
{ |
||||
endCommand = command; |
||||
} |
||||
} |
||||
|
||||
if (execute) |
||||
{ |
||||
// Tell the following end command to loop back |
||||
endCommand.loop = true; |
||||
Continue(); |
||||
} |
||||
else |
||||
{ |
||||
// Continue at next command after End |
||||
Continue (endCommand.commandIndex + 1); |
||||
} |
||||
} |
||||
|
||||
public override bool OpenBlock() |
||||
{ |
||||
return true; |
||||
} |
||||
|
||||
public override Color GetButtonColor() |
||||
{ |
||||
return new Color32(253, 253, 150, 255); |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue