Esempio n. 1
0
    void AddEventaHandler(Selectable st)
    {
        UGUIEventListener listener = st.gameObject.GetComponent <UGUIEventListener>();

        if (listener == null) //防止多次AttachListener
        {
            if ((st is Scrollbar) || (st is InputField) || (st is Slider))
            {
                listener = st.gameObject.AddComponent <UGUIDragEventListenner>();
            }
            else
            {
                //此处正常button是可以响应拖拽事件但有ScrollRect作为父组件的情况下会存在冲突
                bool useDrag = false;
                if (st is Button)
                {
                    ScrollRect[] rect = st.gameObject.GetComponentsInParent <ScrollRect>(true);
                    useDrag = (rect == null || rect.Length == 0);
                }

                if (useDrag)
                {
                    listener = st.gameObject.AddComponent <UGUIDragEventListenner>();
                }
                else
                {
                    listener = st.gameObject.AddComponent <UGUIEventListener>();
                }
            }
            listener.uiHandler = this;
        }
        else
        {
            if (this == listener.uiHandler) //如果当前的和原来的一样 就不用再Attach一次
            {
                listener.CurSelectable = st;
                return;
            }
            else             //如果想Attach一个新的对象 先清除掉原来的
            {
                IUGUIEventHandler prevHandler = listener.uiHandler;
                if (null != prevHandler)
                {
                    prevHandler.RemoveEventHandler(listener.gameObject);
                }
                listener.uiHandler = this;
            }
        }
        //在listenner上面记录Selectable组件
        listener.CurSelectable = st;
        AddEventHandlerEx(listener);
    }
Esempio n. 2
0
    static int set_uiHandler(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UGUIEventListener obj  = (UGUIEventListener)o;
            IUGUIEventHandler arg0 = (IUGUIEventHandler)ToLua.CheckObject <IUGUIEventHandler>(L, 2);
            obj.uiHandler = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index uiHandler on a nil value"));
        }
    }
Esempio n. 3
0
    static int get_uiHandler(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UGUIEventListener obj = (UGUIEventListener)o;
            IUGUIEventHandler ret = obj.uiHandler;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index uiHandler on a nil value"));
        }
    }