Skip to content
This repository was archived by the owner on Aug 10, 2021. It is now read-only.

Commit 4341e6b

Browse files
authored
Tests (#13)
* Add listener tests, fix Vector2 GameEvent naming * Rename test class * Add game event listener test class, rename test methods * Update local var naming * Make API more flexible, rename raise method, update tests to match real use-cases * Fixup link in README * Add initial changelog * Put changes into proper place * Add mutable object test, update readme, update(?) quality settings, make mutable obj handler more flexible * Remove unnecessary Debug.Log statements * Copy over README to package docs
1 parent 65db3a8 commit 4341e6b

29 files changed

+650
-31
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [0.4.0] - 2020-10-07
7+
## [0.5.0] - 2020-10-07
8+
9+
### Added
10+
- Tests for game events and their listeners.
11+
- Tests for mutable objects.
12+
13+
### Changed
14+
- **Renamed** event and listener trigger functions (`OnGameEvent` -> `RaiseGameEvent`).
15+
- **Renamed** `GameEvents.Vector2.Vector3GameEvent` to `GameEvents.Vector2.Vector2GameEvent`, fixed typo.
16+
- Made `MutableObjectHandler` more extensible.
17+
- Exposed `GameEvent` and `OnGameEvent` on listeners via properties.
18+
- `MutableObject` instances are now reset using `SceneManager.activeSceneChanged`.
19+
20+
## [0.4.0] - 2020-10-06
821

922
### Added
1023
- `MutableObjectHandler` which would automate the process of resetting `MutableObjects`.

Documentation~/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Available game events:
3131
width="100%" alt="Example usage of Mutable Objects"
3232
/>
3333

34-
Mutable objects are used for storing and editing data on `ScriptableObject` assets at runtime. This data can be referenced, observed and used as a bridge by various scripts. Mutable objects are useful in situations where `ScriptableObject` data needs to be reset when a new level loads.
34+
Mutable objects are used for storing and editing data on `ScriptableObject` assets at runtime. This data can be referenced, observed and used as a bridge by various scripts. Mutable objects are useful in situations where `ScriptableObject` data needs to be reset when the [active scene changes](https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager-activeSceneChanged.html).
3535

3636
Available mutable objects:
3737
- `MutableBool` - encapsulates a `bool` value.
@@ -104,3 +104,5 @@ public class MutableCustom : MutableObject
104104
}
105105
}
106106
```
107+
108+
[Unity Package Manager]: https://docs.unity3d.com/Packages/[email protected]/manual/index.html

Editor/GameEvents/Vector2/Vector2GameEventEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace GameEvents.Vector2
66
{
7-
[CustomEditor(typeof(Vector3GameEvent))]
7+
[CustomEditor(typeof(Vector2GameEvent))]
88
public class Vector2GameEventEditor
9-
: ArgumentGameEventEditor<Vector3GameEvent, UnityEngine.Vector2>
9+
: ArgumentGameEventEditor<Vector2GameEvent, UnityEngine.Vector2>
1010
{
1111
protected override UnityEngine.Vector2 DrawArgumentField(UnityEngine.Vector2 value)
1212
{

Runtime/GameEvents/Game/GameEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void RaiseGameEvent()
2929
Debug.Log($"Raise event: {name}, listener: {listener}");
3030
}
3131

32-
listener.OnGameEvent();
32+
listener.RaiseGameEvent();
3333
}
3434
}
3535

Runtime/GameEvents/Generic/ArgumentGameEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void RaiseGameEvent(TArgument argument)
2828
Debug.Log($"Raise event: {name}, listener: {listener}, argument: {argument}");
2929
}
3030

31-
listener.OnGameEvent(argument);
31+
listener.RaiseGameEvent(argument);
3232
}
3333
}
3434

Runtime/GameEvents/Generic/ArgumentGameEventListener.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,28 @@ public abstract class ArgumentGameEventListener<TGameEvent, TUnityEvent, TArgume
1818
[Tooltip("Called when the listener is triggered with an argument")]
1919
private TUnityEvent onGameEvent = default;
2020

21+
/// <summary>
22+
/// Get or set the underlying GameEvent.
23+
/// </summary>
24+
public TGameEvent GameEvent
25+
{
26+
get => gameEvent;
27+
set => gameEvent = value;
28+
}
29+
30+
/// <summary>
31+
/// Get or set the underlying UnityEvent.
32+
/// </summary>
33+
public TUnityEvent OnGameEvent
34+
{
35+
get => onGameEvent;
36+
set => onGameEvent = value;
37+
}
38+
2139
/// <summary>
2240
/// Trigger this listener with an argument.
2341
/// </summary>
24-
public void OnGameEvent(TArgument argument)
42+
public void RaiseGameEvent(TArgument argument)
2543
{
2644
onGameEvent.Invoke(argument);
2745
}

Runtime/GameEvents/Generic/BaseGameEventListener.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ public abstract class BaseGameEventListener<TGameEvent>
1515
[Tooltip("Called when the listener is triggered with an argument")]
1616
private UnityEvent onGameEvent = default;
1717

18+
/// <summary>
19+
/// Get or set the underlying GameEvent.
20+
/// </summary>
21+
public TGameEvent GameEvent
22+
{
23+
get => gameEvent;
24+
set => gameEvent = value;
25+
}
26+
27+
/// <summary>
28+
/// Get or set the underlying UnityEvent.
29+
/// </summary>
30+
public UnityEvent OnGameEvent
31+
{
32+
get => onGameEvent;
33+
set => onGameEvent = value;
34+
}
35+
36+
public void RaiseGameEvent()
37+
{
38+
onGameEvent.Invoke();
39+
}
40+
1841
private void OnEnable()
1942
{
2043
if (gameEvent == null)
@@ -36,10 +59,5 @@ private void OnDisable()
3659

3760
gameEvent.UnregisterListener(this);
3861
}
39-
40-
public void OnGameEvent()
41-
{
42-
onGameEvent.Invoke();
43-
}
4462
}
4563
}

Runtime/GameEvents/Generic/IArgumentGameEventListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ public interface IArgumentGameEventListener<in TArgument>
55
/// <summary>
66
/// Trigger this listener with an argument.
77
/// </summary>
8-
void OnGameEvent(TArgument argument);
8+
void RaiseGameEvent(TArgument argument);
99
}
1010
}

Runtime/GameEvents/Generic/IGameEventListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ public interface IGameEventListener
55
/// <summary>
66
/// Trigger this listener.
77
/// </summary>
8-
void OnGameEvent();
8+
void RaiseGameEvent();
99
}
1010
}

Runtime/GameEvents/Vector2/Vector3GameEvent.cs renamed to Runtime/GameEvents/Vector2/Vector2GameEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace GameEvents.Vector2
55
{
66
[CreateAssetMenu(fileName = "Vector2GameEvent", menuName = "Game Events/Vector2 Game Event")]
7-
public class Vector3GameEvent : ArgumentGameEvent<UnityEngine.Vector2>
7+
public class Vector2GameEvent : ArgumentGameEvent<UnityEngine.Vector2>
88
{
99
}
1010
}

0 commit comments

Comments
 (0)