UGUI动态绑定事件

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;

public class EventManager

{

  public static void addEventListener(GameObject go,EventTriggerType type,UnityAction<BaseEventData>callback)

{

  EventTrigger et=go.GetComponent<EventTrigger>();

  if(et==null)

{

  et=go.AddComponent<EventTrigger>();

}

  List<EventTrigger.Entry>entrys=et.triggers;

  if(entrys==null)

{

  entrys=new List<EventTrigger.Entry>();

  et.triggers=entrys;

}

  EventTrigger.TriggerEvent te=new EventTrigger.TriggerEnent();

  te.AddListener(callback);

  EventTrigger.Entry entry=new EvnetTrigger.Entry();

  entry.eventID=type;

  entry.callback=te;

  entrys.Add(entry);

}

}

上一篇:VMware和Centos7的安装和相关配置


下一篇:利用 pip 安装 Python 程序包到个人用户文件夹下