diff --git a/Scriptable Variables/Events/GameEvent.cs b/Scriptable Variables/Events/GameEvent.cs index a47dcafeb8329a2fbf4cef548d9b45390012eaff..49cd47bcad9a0ce12ca81538bc7c39045c53f929 100644 --- a/Scriptable Variables/Events/GameEvent.cs +++ b/Scriptable Variables/Events/GameEvent.cs @@ -1,4 +1,5 @@ -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; + } } } } diff --git a/package.json b/package.json index 488bd120e9c9140d5e795513a679b4818fde2a4a..f6d8e238b1d401dda284350d5ac78e75d9efcd02 100644 --- a/package.json +++ b/package.json @@ -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": {