123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- [AddComponentMenu("NGUI/Interaction/Event Trigger")]
- public class UIEventTrigger : MonoBehaviour
- {
- private void OnHover(bool isOver)
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- if (isOver)
- {
- EventDelegate.Execute(this.onHoverOver);
- }
- else
- {
- EventDelegate.Execute(this.onHoverOut);
- }
- UIEventTrigger.current = null;
- }
- private void OnPress(bool pressed)
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- if (pressed)
- {
- EventDelegate.Execute(this.onPress);
- }
- else
- {
- EventDelegate.Execute(this.onRelease);
- }
- UIEventTrigger.current = null;
- }
- private void OnSelect(bool selected)
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- if (selected)
- {
- EventDelegate.Execute(this.onSelect);
- }
- else
- {
- EventDelegate.Execute(this.onDeselect);
- }
- UIEventTrigger.current = null;
- }
- private void OnClick()
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- EventDelegate.Execute(this.onClick);
- UIEventTrigger.current = null;
- }
- private void OnDoubleClick()
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- EventDelegate.Execute(this.onDoubleClick);
- UIEventTrigger.current = null;
- }
- private void OnDragStart()
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- EventDelegate.Execute(this.onDragStart);
- UIEventTrigger.current = null;
- }
- private void OnDragEnd()
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- EventDelegate.Execute(this.onDragEnd);
- UIEventTrigger.current = null;
- }
- private void OnDragOver(GameObject go)
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- EventDelegate.Execute(this.onDragOver);
- UIEventTrigger.current = null;
- }
- private void OnDragOut(GameObject go)
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- EventDelegate.Execute(this.onDragOut);
- UIEventTrigger.current = null;
- }
- private void OnDrag(Vector2 delta)
- {
- if (UIEventTrigger.current != null)
- {
- return;
- }
- UIEventTrigger.current = this;
- EventDelegate.Execute(this.onDrag);
- UIEventTrigger.current = null;
- }
- public static UIEventTrigger current;
- public List<EventDelegate> onHoverOver = new List<EventDelegate>();
- public List<EventDelegate> onHoverOut = new List<EventDelegate>();
- public List<EventDelegate> onPress = new List<EventDelegate>();
- public List<EventDelegate> onRelease = new List<EventDelegate>();
- public List<EventDelegate> onSelect = new List<EventDelegate>();
- public List<EventDelegate> onDeselect = new List<EventDelegate>();
- public List<EventDelegate> onClick = new List<EventDelegate>();
- public List<EventDelegate> onDoubleClick = new List<EventDelegate>();
- public List<EventDelegate> onDragStart = new List<EventDelegate>();
- public List<EventDelegate> onDragEnd = new List<EventDelegate>();
- public List<EventDelegate> onDragOver = new List<EventDelegate>();
- public List<EventDelegate> onDragOut = new List<EventDelegate>();
- public List<EventDelegate> onDrag = new List<EventDelegate>();
- }
|