1 using UnityEngine; 2 using System.Collections; 3 using UnityEngine.EventSystems; 4 public class EventTriggerListener : UnityEngine.EventSystems.EventTrigger{ 5 public delegate void VoidDelegate (GameObject go); 6 public VoidDelegate onClick; 7 public VoidDelegate onDown; 8 public VoidDelegate onEnter; 9 public VoidDelegate onExit;10 public VoidDelegate onUp;11 public VoidDelegate onSelect;12 public VoidDelegate onUpdateSelect;13 14 static public EventTriggerListener Get (GameObject go)15 {16 EventTriggerListener listener = go.GetComponent();17 if (listener == null) listener = go.AddComponent ();18 return listener;19 }20 public override void OnPointerClick(PointerEventData eventData)21 {22 if(onClick != null) onClick(gameObject);23 }24 public override void OnPointerDown (PointerEventData eventData){25 if(onDown != null) onDown(gameObject);26 }27 public override void OnPointerEnter (PointerEventData eventData){28 if(onEnter != null) onEnter(gameObject);29 }30 public override void OnPointerExit (PointerEventData eventData){31 if(onExit != null) onExit(gameObject);32 }33 public override void OnPointerUp (PointerEventData eventData){34 if(onUp != null) onUp(gameObject);35 }36 public override void OnSelect (BaseEventData eventData){37 if(onSelect != null) onSelect(gameObject);38 }39 public override void OnUpdateSelected (BaseEventData eventData){40 if(onUpdateSelect != null) onUpdateSelect(gameObject);41 }42 }
1 using UnityEngine; 2 using System.Collections; 3 using UnityEngine.UI; 4 using UnityEngine.EventSystems; 5 using UnityEngine.Events; 6 public class UIMain : MonoBehaviour { 7 Button button; 8 Image image; 9 void Start () 10 {11 button = transform.Find("Button").GetComponent
链接: