protected override void OnLoopGridValueChanged(UILoopGrid loopGrid, ILuaPanelItem item, int index)
 {
     if (LuaPanelItem != null)
     {
         LuaPanelItem.OnLoopGridValueChanged(loopGrid, item, index);
     }
 }
Beispiel #2
0
 protected override void OnLoopGridValueChanged(UILoopGrid loopGrid, ILuaPanelItem item, int index)
 {
     LuaMgr.Instance.LuaPanelMgr.OnLoopGridValueChanged(Prefab, loopGrid, item, index);
 }
Beispiel #3
0
        public void BuildControl()
        {
            Transform[] trs = gameObject.GetComponentsInChildren <Transform>(true);
            for (int i = 0; i < trs.Length; ++i)
            {
                string name   = trs[i].name;
                int    len    = name.IndexOf('_') + 1;
                string prefix = name.Substring(0, len);
                switch (prefix)
                {
                case "Widget_":
                {
                    RectTransform rt = trs[i].GetComponent <RectTransform>();
                    if (rt == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'RectTransform\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, rt);
                    }
                }
                break;

                case "Text_":
                {
                    Component label = trs[i].GetComponent <Text>();
                    if (label == null)
                    {
                        label = trs[i].GetComponent <TextMeshProUGUI>();
                    }
                    if (label == null)
                    {
                        trs[i].GetComponent <TextMeshProUGUI>();
                        Debug.LogErrorFormat("{0} require component \'Text\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, label);
                    }
                }
                break;

                case "Button_":
                {
                    Button btn = trs[i].GetComponent <Button>();
                    if (btn == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'Button\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, btn);
                        btn.onClick.RemoveAllListeners();
                        btn.onClick.AddListener(() => onClick(btn));
                    }
                }
                break;

                case "ExtButton_":
                {
                    Button btn = trs[i].GetComponent <Button>();
                    if (btn == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'Button\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, btn);
                        UIEventListener li = UIEventListener.Get(btn.gameObject);
                        li.onClick          = (go) => onClick(btn);
                        li.onLongPressStart = onLongPressStart;
                        li.onLongPress      = onLongPress;
                        li.onLongPressEnd   = onLongPressEnd;
                    }
                }
                break;

                case "Input_":
                {
                    InputField input = trs[i].GetComponent <InputField>();
                    if (input == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'InputField\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, input);

                        input.onValueChanged.RemoveAllListeners();
                        input.onValueChanged.AddListener((val) =>
                            {
                                onInputValueChanged(input, val);
                            });
                        input.onEndEdit.RemoveAllListeners();
                        input.onEndEdit.AddListener((val) =>
                            {
                                onInputEndEdit(input, val);
                            });
                    }
                }
                break;

                case "TMPInput_":
                {
                    if (!name.Contains("Input Caret"))
                    {
                        TMP_InputField input = trs[i].GetComponent <TMP_InputField>();
                        if (input == null)
                        {
                            Debug.LogErrorFormat("{0} require component \'InputField\'.", name);
                        }
                        else
                        {
                            mControlHash.Add(name, input);

                            input.onValueChanged.RemoveAllListeners();
                            input.onValueChanged.AddListener((val) =>
                                {
                                    onInputValueChanged(input, val);
                                });
                            input.onEndEdit.RemoveAllListeners();
                            input.onEndEdit.AddListener((val) =>
                                {
                                    onInputEndEdit(input, val);
                                });
                        }
                    }
                }
                break;

                case "Toggle_":
                {
                    Toggle tog = trs[i].GetComponent <Toggle>();
                    if (tog == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'Toggle\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, tog);

                        tog.onValueChanged.RemoveAllListeners();
                        tog.onValueChanged.AddListener((val) =>
                            {
                                onToggleValueChanged(tog, val);
                            });
                    }
                }
                break;

                case "Slider_":
                {
                    Slider slider = trs[i].GetComponent <Slider>();
                    if (slider == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'Slider\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, slider);

                        slider.onValueChanged.RemoveAllListeners();
                        slider.onValueChanged.AddListener((val) =>
                            {
                                onSliderValueChanged(slider, val);
                            });
                    }
                }
                break;

                case "Sprite_":
                {
                    Image img = trs[i].GetComponent <Image>();
                    if (img == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'Image\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, img);

                        UIEventListener li = UIEventListener.Get(img.gameObject);
                        li.onDown           = onDown;
                        li.onUp             = onUp;
                        li.onEnter          = onEnter;
                        li.onExit           = onExit;
                        li.onLongPressStart = onLongPressStart;
                        li.onLongPress      = onLongPress;
                        li.onLongPressEnd   = onLongPressEnd;

                        UIDragListener dl = UIDragListener.Get(img.gameObject);
                        dl.onDragStart = onDragStart;
                        dl.onDrag      = onDrag;
                        dl.onDragEnd   = onDragEnd;
                    }
                }
                break;

                case "RawImage_":
                {
                    RawImage img = trs[i].GetComponent <RawImage>();
                    if (img == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'RawImage\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, img);
                    }
                }
                break;

                case "Progress_":
                {
                    Image img = trs[i].GetComponent <Image>();
                    if (img == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'Image\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, img);
                    }
                }
                break;

                case "LoopGrid_":
                {
                    UILoopGrid loopGird = trs[i].GetComponent <UILoopGrid>();
                    if (loopGird == null)
                    {
                        Debug.LogErrorFormat("{0} require component \'UILoopGrid\'.", name);
                    }
                    else
                    {
                        mControlHash.Add(name, loopGird);

                        loopGird.Init();
                        loopGird.OnLoopGridValueChanged = (item, index) =>
                        {
                            onLoopGridValueChanged(loopGird.gameObject, item, index);
                        };
                    }
                }
                break;
                }
            }
        }
Beispiel #4
0
        private void onLoopGridValueChanged(GameObject go, ILuaPanelItem item, int index)
        {
            UILoopGrid loopGird = go.GetComponent <UILoopGrid>();

            OnLoopGridValueChanged(loopGird, item, index);
        }
Beispiel #5
0
 protected virtual void OnLoopGridValueChanged(UILoopGrid loopGrid, ILuaPanelItem item, int index)
 {
 }