Skip to content

Instantly share code, notes, and snippets.

@zhenlinyang
Created July 26, 2016 02:28
Show Gist options
  • Save zhenlinyang/48961ba697454c275b51189bec47cb03 to your computer and use it in GitHub Desktop.
Save zhenlinyang/48961ba697454c275b51189bec47cb03 to your computer and use it in GitHub Desktop.
Unity Event Sample
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