zoukankan      html  css  js  c++  java
  • 点击ui事件传参

    监听泛型

    public class PEListener : MonoBehaviour,IPointerClickHandler,IPointerDownHandler,IPointerUpHandler,IDragHandler{

    public Action<object> onClick;

     public Action<PointerEventData> onClickDown;

    public object args;

    public void OnPointerClick(PointerEventData eventData)
    {
    if (onClick != null)
    {
    onClick(args);
    }
    }

    public void OnPointerDown(PointerEventData eventData)
    {
    if (onClickDown != null)
    {
    onClickDown(eventData);
    }
    }

    }

    监听事件

    protected T GetOrAddComponent<T>(GameObject go) where T:Component {
    T t = go.GetComponent<T>();
    if (t == null)
    t = go.AddComponent<T>();
    return t;
    }

    protected void OnClick(GameObject go, Action<object> cb,object args)
    {
    PEListener listener = GetOrAddComponent<PEListener>(go);
    listener.onClick = cb;
    listener.args = args;
    }

    protected void OnClickDown(GameObject go, Action<PointerEventData> cb) {

    PEListener listener = GetOrAddComponent<PEListener>(go);
    listener.onClickDown = cb;
    }

    多个img添加事件

    for (int i = 0; i < posBtnTrans.childCount; i++) {
    Image img = posBtnTrans.GetChild(i).GetComponent<Image>();
    OnClick(img.gameObject, (object args) =>
    {
    ClickPosItem((int)args);
    audioSvc.PlayUIAudio(Constans.UIClickBtn);


    },i);
    }

  • 相关阅读:
    2015-04
    2014-12
    2014-9
    nginx中ngx_http_ssl_module模块
    nginx中ngx_http_gzip_module模块
    Nginx中ngx_http_log_module模块
    Nginx中ngx_http_auth_basic_moudel和ngx_http_stub_status_module模块
    nginx中ngx_http_access_module模块
    nginx中ngx_http_core_module模块
    Nginx安装
  • 原文地址:https://www.cnblogs.com/tqvdong/p/14860984.html
Copyright © 2011-2022 走看看