Created
May 7, 2014 03:12
-
-
Save insominx/8823991dba760b5da0ff to your computer and use it in GitHub Desktop.
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
using UnityEngine; | |
using System.Collections; | |
namespace Util { | |
// ========================================================================= | |
public class EventListener<T> where T: GameEvent { | |
public T receivedEvent; | |
// ------------------------------------------------------------------------- | |
public IEnumerator Listen() { | |
receivedEvent = null; | |
EventMessenger.Instance.AddListener<T>(OnReceiveEvent); | |
do | |
{ | |
yield return null; | |
} while (receivedEvent == null); | |
EventMessenger.Instance.RemoveListener<T>(OnReceiveEvent); | |
} | |
// ------------------------------------------------------------------------- | |
public T TakeEvent() { | |
T eventToReturn = receivedEvent; | |
receivedEvent = null; | |
return eventToReturn; | |
} | |
// ------------------------------------------------------------------------- | |
void OnReceiveEvent(T newEvent) { | |
receivedEvent = newEvent; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment