Created
July 26, 2016 02:28
-
-
Save zhenlinyang/48961ba697454c275b51189bec47cb03 to your computer and use it in GitHub Desktop.
Unity Event Sample
This file contains hidden or 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 System; | |
using UnityEngine; | |
using UnityEngine.Events; | |
using UnityEngine.EventSystems; | |
using UnityEngine.UI; | |
public class UnityEventSample : Graphic, IPointerUpHandler, IPointerDownHandler | |
{ | |
[Serializable] | |
public class EventNone : UnityEvent | |
{ | |
} | |
[Serializable] | |
public class EventBool : UnityEvent<string> | |
{ | |
} | |
public EventNone EventNoneInstance = new EventNone(); | |
public EventBool EventBoolInstance = new EventBool(); | |
protected override void Awake() | |
{ | |
base.Awake(); | |
EventNoneInstance.AddListener(() => { Debug.Log("None"); }); | |
EventBoolInstance.AddListener((str) => { Debug.Log(str); }); | |
} | |
public void OnPointerUp(PointerEventData eventData) | |
{ | |
EventNoneInstance.Invoke(); | |
} | |
public void OnPointerDown(PointerEventData eventData) | |
{ | |
EventBoolInstance.Invoke("Bool"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment