Last active
August 29, 2015 14:04
-
-
Save Problematic/31007b5955a1683dd0d3 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; | |
public class EventConsumer : MonoBehaviour | |
{ | |
EventProvider ep; | |
void Awake () | |
{ | |
ep = GetComponent<EventProvider>(); | |
} | |
void OnEnable () | |
{ | |
ep.OnSomeEvent += HandleOnSomeEvent; | |
} | |
void OnDisable () | |
{ | |
// Remove our event handler when we're | |
// disabled to prevent handling the same | |
// event multiple times | |
ep.OnSomeEvent -= HandleOnSomeEvent; | |
} | |
void HandleOnSomeEvent () | |
{ | |
Debug.Log("SomeEvent handled!"); | |
} | |
} |
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; | |
public class EventProvider : MonoBehaviour | |
{ | |
public delegate void SomeEvent(); | |
public event SomeEvent OnSomeEvent; | |
void Update () | |
{ | |
if (OnSomeEvent != null) | |
{ | |
OnSomeEvent(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment