Skip to content
Snippets Groups Projects
Commit 075dedab authored by Guerrero, Michael J's avatar Guerrero, Michael J
Browse files

Added a coroutine listener for easy event waiting inside a coroutine.

parent 1381d545
No related branches found
Tags 0.1.9
No related merge requests found
using UnityEngine;
using System.Collections;
using UnityEngine;
namespace Shared.ScriptableVariables {
// ScriptableVariable that decouples components firing and listening to game events
......@@ -7,12 +8,22 @@ namespace Shared.ScriptableVariables {
public delegate void GameEventRaised();
public event GameEventRaised OnRaised;
int lastEventRaisedFrame = 0;
//---------------------------------------------------------------------------
[ContextMenu("Raise")]
public void Raise() {
if (OnRaised != null) {
OnRaised();
}
lastEventRaisedFrame = Time.frameCount;
}
//---------------------------------------------------------------------------
public IEnumerator WaitForEvent() {
while (Time.frameCount != lastEventRaisedFrame) {
yield return null;
}
}
}
......@@ -21,11 +32,22 @@ namespace Shared.ScriptableVariables {
public delegate void GameEventRaised(T value);
public event GameEventRaised OnRaised;
int lastEventRaisedFrame = 0;
//---------------------------------------------------------------------------
public void Raise(T value) {
if (OnRaised != null) {
OnRaised(value);
}
lastEventRaisedFrame = Time.frameCount;
}
//---------------------------------------------------------------------------
public IEnumerator WaitForEvent() {
while (Time.frameCount != lastEventRaisedFrame) {
yield return null;
}
}
}
}
......@@ -2,7 +2,7 @@
"name": "com.futuretech.shared",
"displayName": "FutureTech Shared",
"description": "Contains shared items such as the Scriptable Variables.",
"version": "0.1.8",
"version": "0.1.9",
"unity": "2018.3",
"license": "MIT",
"repository": {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment