mirror of
https://github.com/tym1116/BH3.git
synced 2025-12-19 09:54:46 +01:00
45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
namespace BehaviorDesigner.Runtime.Tasks
|
|
{
|
|
[TaskIcon("{SkinColor}RepeaterIcon.png")]
|
|
[HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=37")]
|
|
[TaskDescription("The repeater task will repeat execution of its child task until the child task has been run a specified number of times. It has the option of continuing to execute the child task even if the child task returns a failure.")]
|
|
public class Repeater : Decorator
|
|
{
|
|
[Tooltip("The number of times to repeat the execution of its child task")]
|
|
public SharedInt count = 1;
|
|
|
|
[Tooltip("Allows the repeater to repeat forever")]
|
|
public SharedBool repeatForever;
|
|
|
|
[Tooltip("Should the task return if the child task returns a failure")]
|
|
public SharedBool endOnFailure;
|
|
|
|
private int executionCount;
|
|
|
|
private TaskStatus executionStatus;
|
|
|
|
public override bool CanExecute()
|
|
{
|
|
return (repeatForever.Value || executionCount < count.Value) && (!endOnFailure.Value || (endOnFailure.Value && executionStatus != TaskStatus.Failure));
|
|
}
|
|
|
|
public override void OnChildExecuted(TaskStatus childStatus)
|
|
{
|
|
executionCount++;
|
|
executionStatus = childStatus;
|
|
}
|
|
|
|
public override void OnEnd()
|
|
{
|
|
executionCount = 0;
|
|
executionStatus = TaskStatus.Inactive;
|
|
}
|
|
|
|
public override void OnReset()
|
|
{
|
|
count = 0;
|
|
endOnFailure = true;
|
|
}
|
|
}
|
|
}
|