Skip to content

Commit

Permalink
Create WaitWhileCoroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
Inspiaaa committed Aug 30, 2023
1 parent a17703f commit e4c50c9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Co.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public static WaitDelayCoroutine Wait(float delay)
=> new WaitDelayCoroutine(delay);


public static WaitWhileCoroutine WaitWhile(Func<Boolean> condition)
=> new WaitWhileCoroutine(condition);


public static WaitForSignalCoroutine WaitForSignal(Godot.Object obj, string signal)
=> new WaitForSignalCoroutine(obj, signal);

Expand Down
37 changes: 37 additions & 0 deletions src/Coroutines/WaitWhileCoroutine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using HCoroutines.Util;

namespace HCoroutines
{
/// <summary>
/// Waits while a certain condition is true.
/// </summary>
public class WaitWhileCoroutine : CoroutineBase
{
private Func<Boolean> condition;

public WaitWhileCoroutine(Func<Boolean> condition)
{
this.condition = condition;
}

public override void OnEnter()
{
CheckCondition();
ResumeUpdates();
}

public override void Update()
{
CheckCondition();
}

private void CheckCondition()
{
if (!this.condition())
{
Kill();
}
}
}
}

0 comments on commit e4c50c9

Please sign in to comment.