While#
Control / While
Description#
Executes the instructions while a conditions are true
Parameters#
| Name | Description |
|---|---|
| Conditions | The conditions to check |
| Instructions | The instructions to execute every iteration |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Title("While")]
[Image(typeof(IconLoop), ColorTheme.Type.Blue)]
[Description("Executes the instructions while a conditions are true")]
[Category("Control/While")]
[Parameter("Conditions", "The conditions to check")]
[Parameter("Instructions", "The instructions to execute every iteration")]
[Keywords("Loop", "For", "Do")]
[NestInnerList(nameof(m_Conditions))]
[NestOuterList(nameof(m_Instructions))]
[Serializable]
public class InstructionCoreWhile : Instruction
{
[SerializeField] private Conditions m_Conditions = new Conditions();
[SerializeField] private Instructions m_Instructions = new Instructions();
protected override string GetTitle(GameObject source) => $"While {this.m_Conditions} do {this.m_Instructions}";
protected override async Awaitable Run(Args args)
{
while (this.m_Conditions.Check(args, Conditions.DEFAULT_OPERATION))
{
await this.m_Instructions.Run(args, this.ParentCancelToken);
}
}
public override void OnCancel()
{
base.OnCancel();
this.m_Instructions.Cancel();
}
}
}