-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Proxy): add boolean event proxy emitter
A new Proxy Emitter has been added for Boolean data types to easily allow chaining and proxying boolean data types.
- Loading branch information
1 parent
6c0d740
commit 0e1f0d9
Showing
4 changed files
with
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Zinnia.Event.Proxy | ||
{ | ||
using System; | ||
using UnityEngine.Events; | ||
|
||
/// <summary> | ||
/// Emits a <see cref="UnityEvent"/> with a <see cref="bool"/> payload whenever the <see cref="SingleEventProxyEmitter{TValue,TEvent}.Receive"/> method is called. | ||
/// </summary> | ||
public class BooleanEventProxyEmitter : RestrictableSingleEventProxyEmitter<bool, BooleanEventProxyEmitter.UnityEvent> | ||
{ | ||
/// <summary> | ||
/// Defines the event with the specified state. | ||
/// </summary> | ||
[Serializable] | ||
public class UnityEvent : UnityEvent<bool> { } | ||
|
||
/// <inheritdoc /> | ||
protected override object GetTargetToCheck() | ||
{ | ||
return Payload; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
147 changes: 147 additions & 0 deletions
147
Tests/Editor/Event/Proxy/BooleanEventProxyEmitterTest.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,147 @@ | ||
using Zinnia.Data.Type; | ||
using Zinnia.Event.Proxy; | ||
using Zinnia.Rule; | ||
|
||
namespace Test.Zinnia.Event.Proxy | ||
{ | ||
using NUnit.Framework; | ||
using Test.Zinnia.Utility.Mock; | ||
using UnityEngine; | ||
|
||
public class BooleanEventProxyEmitterTest | ||
{ | ||
private GameObject containingObject; | ||
private BooleanEventProxyEmitter subject; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
containingObject = new GameObject("BooleanEventProxyEmitterTest"); | ||
subject = containingObject.AddComponent<BooleanEventProxyEmitter>(); | ||
} | ||
|
||
[TearDown] | ||
public void TearDown() | ||
{ | ||
Object.DestroyImmediate(containingObject); | ||
} | ||
|
||
[Test] | ||
public void Receive() | ||
{ | ||
UnityEventListenerMock emittedMock = new UnityEventListenerMock(); | ||
subject.Emitted.AddListener(emittedMock.Listen); | ||
bool payload = true; | ||
|
||
Assert.IsFalse(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
|
||
subject.Receive(payload); | ||
|
||
Assert.IsTrue(subject.Payload); | ||
Assert.IsTrue(emittedMock.Received); | ||
} | ||
|
||
[Test] | ||
public void EmitPayload() | ||
{ | ||
UnityEventListenerMock emittedMock = new UnityEventListenerMock(); | ||
subject.Emitted.AddListener(emittedMock.Listen); | ||
bool payload = true; | ||
subject.Payload = payload; | ||
|
||
Assert.IsTrue(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
|
||
subject.EmitPayload(); | ||
|
||
Assert.IsTrue(subject.Payload); | ||
Assert.IsTrue(emittedMock.Received); | ||
} | ||
|
||
[Test] | ||
public void ClearPayload() | ||
{ | ||
UnityEventListenerMock emittedMock = new UnityEventListenerMock(); | ||
subject.Emitted.AddListener(emittedMock.Listen); | ||
bool payload = true; | ||
subject.Payload = payload; | ||
|
||
Assert.IsTrue(subject.Payload); | ||
subject.ClearPayload(); | ||
Assert.IsFalse(subject.Payload); | ||
} | ||
|
||
[Test] | ||
public void ReceiveInactiveGameObject() | ||
{ | ||
UnityEventListenerMock emittedMock = new UnityEventListenerMock(); | ||
subject.Emitted.AddListener(emittedMock.Listen); | ||
subject.gameObject.SetActive(false); | ||
|
||
bool payload = true; | ||
|
||
Assert.IsFalse(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
|
||
subject.Receive(payload); | ||
|
||
Assert.IsFalse(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
} | ||
|
||
[Test] | ||
public void ReceiveInactiveComponent() | ||
{ | ||
UnityEventListenerMock emittedMock = new UnityEventListenerMock(); | ||
subject.Emitted.AddListener(emittedMock.Listen); | ||
subject.enabled = false; | ||
|
||
bool payload = true; | ||
|
||
Assert.IsFalse(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
|
||
subject.Receive(payload); | ||
|
||
Assert.IsFalse(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
} | ||
|
||
[Test] | ||
public void EmitPayloadInactiveGameObject() | ||
{ | ||
UnityEventListenerMock emittedMock = new UnityEventListenerMock(); | ||
subject.Emitted.AddListener(emittedMock.Listen); | ||
subject.gameObject.SetActive(false); | ||
bool payload = false; | ||
subject.Payload = payload; | ||
|
||
Assert.IsFalse(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
|
||
subject.EmitPayload(); | ||
|
||
Assert.IsFalse(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
} | ||
|
||
[Test] | ||
public void EmitPayloadInactiveComponent() | ||
{ | ||
UnityEventListenerMock emittedMock = new UnityEventListenerMock(); | ||
subject.Emitted.AddListener(emittedMock.Listen); | ||
subject.enabled = false; | ||
bool payload = false; | ||
subject.Payload = payload; | ||
|
||
Assert.IsFalse(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
|
||
subject.EmitPayload(); | ||
|
||
Assert.IsFalse(subject.Payload); | ||
Assert.IsFalse(emittedMock.Received); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Tests/Editor/Event/Proxy/BooleanEventProxyEmitterTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.