UGUI中UI系统采用NGUI调用

UGUI原版方法的调用

 1 using System.Collections.Generic;
 2 using UnityEngine;
 3 using UnityEngine.Events;
 4 using UnityEngine.EventSystems;
 5 
 6 public class ScriptControl : MonoBehaviour {
 7 
 8     // Use this for initialization
 9     void Start ()
10     {
11         var trigger = transform.gameObject.GetComponent();
12         if (trigger == null)
13             trigger = transform.gameObject.AddComponent();
14 
15         // 实例化delegates
16         trigger.delegates = new List();
17 
18         // 定义需要绑定的事件类型。并设置回调函数
19         EventTrigger.Entry entry = new EventTrigger.Entry();
20         // 设置 事件类型
21         entry.eventID = EventTriggerType.PointerClick;
22         // 设置回调函数
23         entry.callback = new EventTrigger.TriggerEvent();
24         UnityAction callback = new UnityAction(OnScriptControll);
25         entry.callback.AddListener(callback);
26         // 添加事件触发记录到GameObject的事件触发组件
27         trigger.delegates.Add(entry);
28     }
29     
30     // Update is called once per frame
31     void Update () {
32     
33     }
34 
35     public void OnScriptControll(BaseEventData arg0)
36     {
37         Debug.Log("Test Click");
38     }
39 
40 }

使用NGUI方式来调用,即给物体添加一个EventTrigger



using UnityEngine.Events;
using UnityEngine.EventSystems;


public class EventTriggerListener : EventTrigger
{
    public delegate void VoidDelegate(GameObject go);


    public VoidDelegate onInitializePotentialDrag;//开始拖拽时初始化,比BeginDrag更早一步调用
    public VoidDelegate onBeginDrag;//当开始进行拖拽
    public VoidDelegate onDrag;//当一直被拖拽
    public VoidDelegate onEndDrag;//当结束拖拽
    public VoidDelegate onDrop;//未知


    public VoidDelegate onCancel;//Called when the cancel button is pressed
    public VoidDelegate onSubmit;//Called when the submit button is pressed
    public VoidDelegate onMove;//Called when a move event occurs (left, right, up, down, ect)


    public VoidDelegate onPointerDown;//当按下鼠标左键
    public VoidDelegate onPointerClick;//当点击
    public VoidDelegate onPointerUp;//当按下后抬起


    public VoidDelegate onPointerEnter;//Hover进入
    public VoidDelegate onPointerExit;//Hover移出


    public VoidDelegate onScroll;//当滚轮滑动  Input.GetAxis("Mouse ScrollWheel")


    public VoidDelegate onSelect;//当一个对象被click之后
    public VoidDelegate onUpdateSelected;//被click之后一直调用
    public VoidDelegate onDeselect;//当一个新的对象被选中,取消选择上一个click对象


    static public EventTriggerListener Get(GameObject go)
    {
        EventTriggerListener listener = go.GetComponent();
        if (listener == null) listener = go.AddComponent();
        return listener;
    }
    public override void OnBeginDrag(PointerEventData eventData)
    {
        if (onBeginDrag != null)
            onBeginDrag(gameObject);
    }
    public override void OnCancel(BaseEventData eventData)
    {
        if (onCancel != null)
            onCancel(gameObject);
    }
    public override void OnDeselect(BaseEventData eventData)
    {
        if (onDeselect != null)
            onDeselect(gameObject);
    }
    public override void OnDrag(PointerEventData eventData)
    {
        if (onDrag != null)
            onDrag(gameObject);
    }
    public override void OnDrop(PointerEventData eventData)
    {
        if (onDrop != null)
            onDrop(gameObject);
    }
    public override void OnEndDrag(PointerEventData eventData)
    {
        if (onEndDrag != null)
            onEndDrag(gameObject);
    }
    public override void OnInitializePotentialDrag(PointerEventData eventData)
    {
        if (onInitializePotentialDrag != null)
            onInitializePotentialDrag(gameObject);
    }
    public override void OnMove(AxisEventData eventData)
    {
        if (onMove != null)
            onMove(gameObject);
    }
    public override void OnPointerClick(PointerEventData eventData)
    {
        if (onPointerClick != null)
            onPointerClick(gameObject);
    }
    public override void OnPointerDown(PointerEventData eventData)
    {
        if (onPointerDown != null)
            onPointerDown(gameObject);
    }
    public override void OnPointerEnter(PointerEventData eventData)
    {
        if (onPointerEnter != null)
            onPointerEnter(gameObject);
    }
    public override void OnPointerExit(PointerEventData eventData)
    {
        if (onPointerExit != null)
            onPointerExit(gameObject);
    }
    public override void OnPointerUp(PointerEventData eventData)
    {
        if (onPointerUp != null)
            onPointerUp(gameObject);
    }
    public override void OnScroll(PointerEventData eventData)
    {
        if (onScroll != null)
            onScroll(gameObject);
    }
    public override void OnSelect(BaseEventData eventData)
    {
        if (onSelect != null)
            onSelect(gameObject);
    }
    public override void OnSubmit(BaseEventData eventData)
    {
        if (onSubmit != null)
            onSubmit(gameObject);
    }
    public override void OnUpdateSelected(BaseEventData eventData)
    {
        if (onUpdateSelected != null)
            onUpdateSelected(gameObject);
    }
}

你可能感兴趣的:(UGUI,&,DoTween)