-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New wait time node returns continue until the passed duration has expired
- Loading branch information
Showing
11 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
Assets/FluidBehaviorTree/Runtime/Tasks/Actions/WaitTime/ITimeMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace CleverCrow.Fluid.BTs.Tasks.Actions { | ||
public interface ITimeMonitor { | ||
float DeltaTime { get; } | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/FluidBehaviorTree/Runtime/Tasks/Actions/WaitTime/ITimeMonitor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Assets/FluidBehaviorTree/Runtime/Tasks/Actions/WaitTime/TimeMonitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.BTs.Tasks.Actions { | ||
public class TimeMonitor : ITimeMonitor { | ||
public float DeltaTime => Time.deltaTime; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/FluidBehaviorTree/Runtime/Tasks/Actions/WaitTime/TimeMonitor.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
Assets/FluidBehaviorTree/Runtime/Tasks/Actions/WaitTime/WaitTime.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
namespace CleverCrow.Fluid.BTs.Tasks.Actions { | ||
/// <summary> | ||
/// Return continue until the time has passed | ||
/// </summary> | ||
public class WaitTime : ActionBase { | ||
private ITimeMonitor _timeMonitor; | ||
private float _timePassed; | ||
|
||
public float time = 1; | ||
|
||
|
||
public WaitTime (ITimeMonitor timeMonitor) { | ||
_timeMonitor = timeMonitor; | ||
} | ||
|
||
protected override void OnStart () { | ||
_timePassed = 0; | ||
} | ||
|
||
protected override TaskStatus OnUpdate () { | ||
_timePassed += _timeMonitor.DeltaTime; | ||
|
||
if (_timePassed < time) { | ||
return TaskStatus.Continue; | ||
} | ||
|
||
return TaskStatus.Success; | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/FluidBehaviorTree/Runtime/Tasks/Actions/WaitTime/WaitTime.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Assets/FluidBehaviorTree/Tests/Editor/Tasks/Actions/WaitTimeTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace CleverCrow.Fluid.BTs.Tasks.Actions.Editors.Tests { | ||
public class WaitTimeTest { | ||
public class UpdateMethod { | ||
[Test] | ||
public void It_should_return_continue_if_time_has_not_passed () { | ||
var timeMonitor = Substitute.For<ITimeMonitor>(); | ||
timeMonitor.DeltaTime.Returns(0); | ||
var waitTime = new WaitTime(timeMonitor) {time = 1}; | ||
|
||
Assert.AreEqual(TaskStatus.Continue, waitTime.Update()); | ||
} | ||
|
||
[Test] | ||
public void It_should_return_success_if_time_has_passed () { | ||
var timeMonitor = Substitute.For<ITimeMonitor>(); | ||
timeMonitor.DeltaTime.Returns(2); | ||
var waitTime = new WaitTime(timeMonitor) {time = 1}; | ||
|
||
Assert.AreEqual(TaskStatus.Success, waitTime.Update()); | ||
} | ||
} | ||
|
||
public class ResetMethod { | ||
[Test] | ||
public void It_should_reset_time () { | ||
var timeMonitor = Substitute.For<ITimeMonitor>(); | ||
var waitTime = new WaitTime(timeMonitor) {time = 1}; | ||
|
||
timeMonitor.DeltaTime.Returns(2); | ||
waitTime.Update(); | ||
waitTime.Reset(); | ||
timeMonitor.DeltaTime.Returns(0); | ||
|
||
Assert.AreEqual(TaskStatus.Continue, waitTime.Update()); | ||
|
||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/FluidBehaviorTree/Tests/Editor/Tasks/Actions/WaitTimeTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.