u3d:关于动态添加各种按钮事件的方法记录

using UnityEngine.UI;
using UnityEngine.EventSystems;
    /// 
    /// 给button添加各种事件
    /// 
    public void BtnEvents(Button btn,Image listImg)
    {
        EventTrigger.Entry en1 = new EventTrigger.Entry();
        EventTrigger.Entry en2 = new EventTrigger.Entry();


        en1.eventID = EventTriggerType.PointerEnter;
        en2.eventID = EventTriggerType.PointerExit;

        EventTrigger _trigger = btn.gameObject.GetComponent();

        en1.callback = new EventTrigger.TriggerEvent();
        en1.callback.AddListener((BaseEventData pointData)=> { ImgListEnable(listImg); });
        _trigger.triggers.Add(en1);

        en2.callback = new EventTrigger.TriggerEvent();
        en2.callback.AddListener((BaseEventData pointData) => { ImgListEnable(listImg); });
        _trigger.triggers.Add(en2);
    }

 

 

你可能感兴趣的:(u3d:关于动态添加各种按钮事件的方法记录)