From 075dedab37b567abd0ac00e9254a2977f390fd49 Mon Sep 17 00:00:00 2001
From: michael <mjguerre@nps.edu>
Date: Wed, 5 Jun 2019 10:40:59 -0700
Subject: [PATCH] Added a coroutine listener for easy event waiting inside a
 coroutine.

---
 Scriptable Variables/Events/GameEvent.cs | 24 +++++++++++++++++++++++-
 package.json                             |  2 +-
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/Scriptable Variables/Events/GameEvent.cs b/Scriptable Variables/Events/GameEvent.cs
index a47dcaf..49cd47b 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 488bd12..f6d8e23 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": {
-- 
GitLab