Пример #1
0
    static int GetComponents(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2)
        {
            GameObject obj     = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
            var        classId = (int)LuaScriptMgr.GetNumber(L, 2);
            var        t       = WrapClassID.GetClassType(classId);
            if (t == null)
            {
                LuaDLL.luaL_error(L, "invalid arguments to method: GameObject.GetComponent");
                return(0);
            }
            else
            {
                Component[] o = obj.GetComponents(t);
                LuaScriptMgr.PushArray(L, o);
                return(1);
            }
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: GameObject.GetComponents");
        }

        return(0);
    }
Пример #2
0
    static int AddComponent(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        GameObject obj = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");
        //Type arg0 = LuaScriptMgr.GetTypeObject(L, 2);
        var       classId = (int)LuaScriptMgr.GetNumber(L, 2);
        var       arg0    = WrapClassID.GetClassType(classId);
        Component o       = obj.AddComponent(arg0);

        LuaScriptMgr.Push(L, o);
        return(1);
    }
Пример #3
0
    static int GetComponentInChildren(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        GameObject obj = (GameObject)LuaScriptMgr.GetUnityObjectSelf(L, 1, "GameObject");

        var classId = (int)LuaScriptMgr.GetNumber(L, 2);
        var t       = WrapClassID.GetClassType(classId);

        if (t == null)
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: GameObject.GetComponent");
            return(0);
        }
        else
        {
            Component o = obj.GetComponentInChildren(t);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
    }
Пример #4
0
    //This overrides the callback of a UI Component to a single call
    public void RegisterSingleObjHandler(GameObject control, int class_type, bool recursion)
    {
        if (control == null)
        {
            Debug.LogError("Cannot register event since the control object is null!");
            return;
        }

        System.Type type = WrapClassID.GetClassType(class_type);

        if (type == typeof(UnityEngine.UI.Button) || type == typeof(GButton))
        {
            GButton gbtn = control.GetComponent <GButton>();
            if (gbtn != null)
            {
                gbtn.OnClick = OnClick;
                return;
            }

            Button btn = control.GetComponent <Button>();
            if (btn != null)
            {
                btn.onClick.RemoveAllListeners();
                btn.onClick.AddListener(delegate() { OnClick(btn.gameObject); });
            }
            if (recursion)
            {
                GButton[] btns = control.GetComponentsInChildren <GButton>(true);
                for (int i = 0; i < btns.Length; i++)
                {
                    if (btns[i] != null)
                    {
                        btns[i].OnClick = OnClick;
                    }
                }
            }
        }
        else if (type == typeof(Toggle))
        {
            if (recursion)
            {
                Toggle[] toggles = control.GetComponentsInChildren <Toggle>(true);
                for (int i = 0; i < toggles.Length; i++)
                {
                    if (toggles[i] != null)
                    {
                        toggles[i].onValueChanged.RemoveAllListeners();
                        GameObject go = toggles[i].gameObject;
                        toggles[i].onValueChanged.AddListener(delegate(bool ischeck) { OnToggle(go, ischeck); });
                    }
                }
            }
            else
            {
                Toggle toggle = control.GetComponent <Toggle>();
                if (toggle != null)
                {
                    toggle.onValueChanged.RemoveAllListeners();
                    toggle.onValueChanged.AddListener(delegate(bool ischeck) { OnToggle(toggle.gameObject, ischeck); });
                }
            }
        }
        else if (type == typeof(GNewIOSToggle))
        {
            GNewIOSToggle gTgl = control.GetComponent <GNewIOSToggle>();
            if (gTgl != null)
            {
                gTgl.OnClick = OnClick;
                //gTgl.OnValueChanged = OnToggleSpecial;
            }
            if (recursion)
            {
                GNewIOSToggle[] gToggles = control.GetComponentsInChildren <GNewIOSToggle>(true);
                for (int i = 0; i < gToggles.Length; i++)
                {
                    if (gToggles[i] != null)
                    {
                        gToggles[i].OnClick = OnClick;
                        //gToggles[i].OnValueChanged = OnToggleSpecial;
                    }
                }
            }
        }
        else if (type == typeof(GText))
        {
            // 现在需求中GText不在root上,所以这么处理;其实不太好
            GText gtext = control.GetComponentInChildren <GText>();
            if (gtext != null)
            {
                gtext.OnClick = OnGTextClick;
            }
            if (recursion)
            {
                GText[] gts = control.GetComponentsInChildren <GText>(true);
                for (int i = 0; i < gts.Length; i++)
                {
                    if (gts[i] != null)
                    {
                        gts[i].OnClick = OnGTextClick;
                    }
                }
            }
        }
        else if (type == typeof(GImageModel))
        {
            GImageModel gim = control.GetComponent <GImageModel>();
            if (gim != null)
            {
                gim.OnModelClick = OnClick;
            }
            if (recursion)
            {
                GImageModel[] gims = control.GetComponentsInChildren <GImageModel>(true);
                for (int i = 0; i < gims.Length; i++)
                {
                    if (gims[i] != null)
                    {
                        gims[i].OnModelClick = OnClick;
                    }
                }
            }
        }
        else if (type == typeof(Slider))
        {
            Slider sld = control.GetComponent <Slider>();
            if (sld != null)
            {
                sld.onValueChanged.AddListener(delegate(float value) { OnSliderChanged(sld.gameObject, value); });
            }
            if (recursion)
            {
                Slider[] sliders = control.GetComponentsInChildren <Slider>(true);
                for (int i = 0; i < sliders.Length; i++)
                {
                    if (sliders[i] != null)
                    {
                        sliders[i].onValueChanged.AddListener(delegate(float value) { OnSliderChanged(sliders[i].gameObject, value); });
                    }
                }
            }
        }
        else if (type == typeof(GScaleScroll))
        {
            GScaleScroll gss = control.GetComponent <GScaleScroll>();
            if (gss != null)
            {
                gss.onScaleChanged = OnScaleChanged;
            }
            if (recursion)
            {
                GScaleScroll[] gsss = control.GetComponentsInChildren <GScaleScroll>(true);
                for (int i = 0; i < gsss.Length; i++)
                {
                    if (gsss[i] != null)
                    {
                        gsss[i].onScaleChanged = OnScaleChanged;
                    }
                }
            }
        }
        else if (type == typeof(GBlood))
        {
            GBlood gwv = control.GetComponent <GBlood>();
            if (gwv != null)
            {
                gwv.OnTweenFinishCallBack = this.OnDOTComplete;
            }
            if (recursion)
            {
                GBlood[] gwvs = control.GetComponentsInChildren <GBlood>(true);
                for (int i = 0; i < gwvs.Length; i++)
                {
                    gwvs[i].OnTweenFinishCallBack = this.OnDOTComplete;
                }
            }
        }
        else if (type == typeof(GWebView))
        {
            GWebView gwv = control.GetComponent <GWebView>();
            if (gwv != null)
            {
                gwv.OnReceiveMessage = this.OnReceiveWebViewMessage;
            }
            if (recursion)
            {
                GWebView[] gwvs = control.GetComponentsInChildren <GWebView>(true);
                for (int i = 0; i < gwvs.Length; i++)
                {
                    gwvs[i].OnReceiveMessage = OnReceiveWebViewMessage;
                }
            }
        }
        else if (type == typeof(GNewListBase))
        {
            GNewListBase list = control.GetComponent <GNewListBase>();
            if (list != null)
            {
                list.ClickItemCallBack = this.OnSelectItem;
                //list.PressItemCallBack = this.OnPressItem;
                //list.ReleaseItemCallBack = this.OnReleaseItem;
                list.LongPressCallBack = this.OnLongPressItem;
                list.InitItemCallBack  = this.OnInitItem;

                if (list.HasChildButton)
                {
                    list.ClickItemButtonCallBack = this.OnSelectItemButton;
                }
            }
            if (recursion)
            {
                GNewListBase[] lists = control.GetComponentsInChildren <GNewListBase>(true);
                for (int i = 0; i < lists.Length; i++)
                {
                    lists[i].ClickItemCallBack = this.OnSelectItem;
                    lists[i].LongPressCallBack = this.OnLongPressItem;
                    lists[i].InitItemCallBack  = this.OnInitItem;
                    if (lists[i].HasChildButton)
                    {
                        lists[i].ClickItemButtonCallBack = this.OnSelectItemButton;
                    }
                }
            }
        }
        else
        {
            // TODO: 将来根据需要自行扩展
            HobaDebuger.LogError("<RegisterUIEventHandler>WrapClassID not supported!" + class_type);
        }
    }