コード例 #1
0
 private void OnValidate()
 {
     if (string.IsNullOrEmpty(key))
     {
         key = System.Guid.NewGuid().ToString();
     }
     if (target == null)
     {
         target = GetComponent <UIBehaviour>();
     }
     else if (!(typeof(Slider).IsAssignableFrom(target.GetType()) ||
                typeof(Dropdown).IsAssignableFrom(target.GetType()) ||
                typeof(InputField).IsAssignableFrom(target.GetType()) ||
                typeof(Toggle).IsAssignableFrom(target.GetType())))
     {
         Debug.LogWarning("SaveUIComponent does not support target type (" + target.GetType().Name + "). Supported types are Slider, Dropdown, InputField, Toggle.");
     }
 }
コード例 #2
0
ファイル: Utils.cs プロジェクト: shanteng/GameIdea
    public static UICompleteEnum GetUIComponent(UIBehaviour rect)
    {
        if (rect == null)
        {
            return(UICompleteEnum.Window);
        }
        string typeName = rect.GetType().ToString();

        if (typeName.Equals("xUIControlMonoPanel"))
        {
            return(UICompleteEnum.Window);
        }
        else if (typeName.Equals("xUIControlMonoButton"))
        {
            return(UICompleteEnum.Button);
        }
        else if (typeName.Equals("xUIControlMonoLabel"))
        {
            return(UICompleteEnum.Label);
        }
        else if (typeName.Equals("EasyListView"))
        {
            return(UICompleteEnum.ListView);
        }
        else if (typeName.Equals("xUIControlMonoScrollView"))
        {
            return(UICompleteEnum.ScrollView);
        }
        else if (typeName.Equals("xUIControlMonoProgressBar"))
        {
            return(UICompleteEnum.ProgressBar);
        }
        else if (typeName.Equals("xUIControlMonoDynamicImage"))
        {
            return(UICompleteEnum.DynamicImage);
        }
        else if (typeName.Equals("xUIControlMonoSlider"))
        {
            return(UICompleteEnum.Slider);
        }

        return(UICompleteEnum.Window);
    }
コード例 #3
0
        /// <summary>
        /// 绑定控件
        /// </summary>
        /// <param name="control">绑定的目标控件</param>
        protected override void Binding(UIBehaviour control)
        {
            base.Binding(control);

            if (control is InputField)
            {
                InputField inputField = control as InputField;
                inputField.text = Value;
                inputField.onValueChanged.AddListener((value) => { Value = value; });
                _onValueChanged += (value) => { if (inputField)
                                                {
                                                    inputField.text = value;
                                                }
                };
            }
            else if (control is Text)
            {
                Text text = control as Text;
                text.text        = Value;
                _onValueChanged += (value) => { if (text)
                                                {
                                                    text.text = value;
                                                }
                };
            }
            else
            {
                Log.Warning(string.Format("数据驱动器:数据绑定失败,当前不支持控件 {0} 与 BindableString 类型的数据绑定!", control.GetType().FullName));
            }
        }
コード例 #4
0
    static public void AddPanelItem()
    {
        GameObject gameObject = Selection.activeGameObject;

        if (gameObject.transform.parent == null || gameObject.transform.parent.parent == null)
        {
            Debug.LogError(gameObject.name + "父节点为 null 不是ui控件!");
            return;
        }
        if (gameObject.name.EndsWith("Panel"))
        {
            Debug.LogError(gameObject.name + "Panel Root");
            return;
        }

        UIBehaviour uiBehaviour = gameObject.GetComponent <Button>();

        if (uiBehaviour == null)
        {
            uiBehaviour = gameObject.GetComponent <UIBehaviour>();
        }

        Type t = uiBehaviour.GetType();

        string addRefCode   = "";
        string addEventCode = "";

        //判断选中组件类型
        if (t.Equals(typeof(UnityEngine.UI.Image)))
        {
            addRefCode = string.Format("self.{0} = self.transform:Find('{0}')", gameObject.name);
            Debug.LogWarning("UnityEngine.UI.Image");
        }
        else if (t.Equals(typeof(UnityEngine.UI.Button)))
        {
            addRefCode   = string.Format("self.{0} = self.transform:Find('Button')", gameObject.name);
            addEventCode = string.Format("view.{0}:GetComponent(\"Button\").onClick:AddListener(function()\n\tprint('onClick:{0}')\n\tend)", gameObject.name);
            Debug.LogWarning("UnityEngine.UI.Button");
        }
        else if (t.Equals(typeof(UnityEngine.UI.Text)))
        {
            addRefCode = string.Format("self.{0} = self.transform:Find('Text')", gameObject.name);
            Debug.LogWarning("UnityEngine.UI.Text");
        }
        else if (t.Equals(typeof(UnityEngine.UI.InputField)))
        {
            addRefCode = string.Format("self.{0} = self.transform:Find('InputField')", gameObject.name);
            Debug.LogWarning("UnityEngine.UI.InputField");
        }
        else
        {
            addRefCode = string.Format("self.{0} = self.transform:Find('{1}')", gameObject.name, t.ToString().Replace("UnityEngine.UI.", ""));
            Debug.LogWarning(t.ToString());
        }

        Stack <Transform> pathStack = new Stack <Transform> ();

        Transform curTransform = gameObject.transform;

        while (curTransform != null)
        {
            if (curTransform.name.EndsWith("Canvas"))
            {
                break;
            }
            pathStack.Push(curTransform);

            curTransform = curTransform.parent;
        }

        string moduleMame    = pathStack.Pop().name;
        string subModuleMame = pathStack.Pop().name;
        string panelName     = pathStack.Pop().name;

        Dictionary <string, string> repkey = new Dictionary <string, string> ();

        repkey["$PanelName$"]     = panelName;
        repkey["$SubModuleMame$"] = subModuleMame;
        repkey["$ModuleMame$"]    = moduleMame;

        Debug.LogWarning("moduleMame:" + moduleMame + " > subModuleMame:" + subModuleMame);
        /* 视图层追加 */
        string viewLuaFile = Application.dataPath +
                             string.Format("{0}/{1}/modules/{2}/{3}View.lua",
                                           LuaCodeOutPath, repkey ["$ModuleMame$"], repkey ["$SubModuleMame$"], repkey ["$PanelName$"]);

        string appendFalgText = "--AddRefCode 追加引用标志";

        string luaCode = File.ReadAllText(viewLuaFile);

        if (luaCode.IndexOf(appendFalgText) == -1)
        {
            Debug.LogErrorFormat("{0} 缺少追加标志行! ", viewLuaFile);
            return;
        }
        if (luaCode.IndexOf(addRefCode) == -1)
        {
            luaCode = luaCode.Replace(appendFalgText, string.Format("{0}\n\t{1}", addRefCode, appendFalgText));
            File.WriteAllText(viewLuaFile, luaCode);
        }
        else
        {
            Debug.LogWarningFormat(" {0} 代码已经存在 {1} ", addRefCode, viewLuaFile);
        }
        /* 控制层追加 */
        if (addEventCode.Equals(""))
        {
            //没有要追加的
            return;
        }
        string ctrLuaFile = Application.dataPath +
                            string.Format("{0}/{1}/modules/{2}/{3}Ctrl.lua",
                                          LuaCodeOutPath, repkey ["$ModuleMame$"], repkey ["$SubModuleMame$"], repkey ["$PanelName$"]);

        appendFalgText = "--AddEventCode 追加事件标志";

        luaCode = File.ReadAllText(ctrLuaFile);

        if (luaCode.IndexOf(appendFalgText) == -1)
        {
            Debug.LogErrorFormat("{0} 缺少追加标志行! ", ctrLuaFile);
            return;
        }

        if (luaCode.IndexOf(addEventCode) == -1)
        {
            luaCode = luaCode.Replace(appendFalgText, string.Format("{0}\n\t{1}", addEventCode, appendFalgText));
            File.WriteAllText(ctrLuaFile, luaCode);
        }
        else
        {
            Debug.LogWarningFormat(" {0} 代码已经存在 {1} ", addEventCode, ctrLuaFile);
        }
    }
コード例 #5
0
 void OnUIEventXU(XUEventType eventType, string strEvent, object objParam, UIBehaviour sender, object senderParam)
 {
     Debug.Log("OnUIEventXU = " + eventType + "  " + strEvent + "  " + objParam + "  " + sender.name + "(" + sender.GetType() + ")  " + senderParam);
 }
コード例 #6
0
        /// <summary>
        /// 绑定控件
        /// </summary>
        /// <param name="control">绑定的目标控件</param>
        protected override void Binding(UIBehaviour control)
        {
            base.Binding(control);

            if (control is Dropdown)
            {
                Dropdown dropdown = control as Dropdown;
                if (dropdown.options == null)
                {
                    dropdown.options = new List <Dropdown.OptionData>();
                }
                for (int i = 0; i < _values.Count; i++)
                {
                    dropdown.options.Add(new Dropdown.OptionData(_values[i]));
                }
                dropdown.value = Value;
                dropdown.onValueChanged.AddListener((value) => { Value = value; });
                _onValueChanged += (value) => { if (dropdown)
                                                {
                                                    dropdown.value = value;
                                                }
                };
            }
            else
            {
                Log.Warning(string.Format("数据驱动器:数据绑定失败,当前不支持控件 {0} 与 BindableSelectable 类型的数据绑定!", control.GetType().FullName));
            }
        }
コード例 #7
0
        /// <summary>
        /// 绑定控件
        /// </summary>
        /// <param name="control">绑定的目标控件</param>
        protected override void Binding(UIBehaviour control)
        {
            base.Binding(control);

            if (control is Toggle)
            {
                Toggle toggle = control as Toggle;
                toggle.isOn = Value;
                toggle.onValueChanged.AddListener((value) => { Value = value; });
                _onValueChanged += (value) => { if (toggle)
                                                {
                                                    toggle.isOn = value;
                                                }
                };
            }
            else if (control is Button)
            {
                Button button = control as Button;
                button.interactable = Value;
                _onValueChanged    += (value) => { if (button)
                                                   {
                                                       button.interactable = value;
                                                   }
                };
            }
            else
            {
                Log.Warning(string.Format("数据驱动器:数据绑定失败,当前不支持控件 {0} 与 BindableBool 类型的数据绑定!", control.GetType().FullName));
            }
        }
コード例 #8
0
        /// <summary>
        /// 绑定控件
        /// </summary>
        /// <param name="control">绑定的目标控件</param>
        protected override void Binding(UIBehaviour control)
        {
            base.Binding(control);

            if (_bindedControls.Contains(control))
            {
                return;
            }

            if (control is Toggle)
            {
                Toggle toggle = control as Toggle;
                toggle.isOn = Value;
                toggle.onValueChanged.AddListener(_callback);
                _onValueChanged += (value) => { if (toggle)
                                                {
                                                    toggle.isOn = value;
                                                }
                };
                _bindedControls.Add(control);
            }
            else if (control is Button)
            {
                Button button = control as Button;
                button.interactable = Value;
                _onValueChanged    += (value) => { if (button)
                                                   {
                                                       button.interactable = value;
                                                   }
                };
                _bindedControls.Add(control);
            }
            else if (control is Text)
            {
                Text text = control as Text;
                text.text        = Value.ToString();
                _onValueChanged += (value) => { if (text)
                                                {
                                                    text.text = value.ToString();
                                                }
                };
                _bindedControls.Add(control);
            }
            else
            {
                Log.Warning(string.Format("自动化任务:数据绑定失败,当前不支持控件 {0} 与 BindableBool 类型的数据绑定!", control.GetType().FullName));
            }
        }
コード例 #9
0
        /// <summary>
        /// 绑定控件
        /// </summary>
        /// <param name="control">绑定的目标控件</param>
        protected override void Binding(UIBehaviour control)
        {
            base.Binding(control);

            if (_bindedControls.Contains(control))
            {
                return;
            }

            if (control is InputField)
            {
                InputField inputField = control as InputField;
                inputField.text = Value.ToString();
                inputField.onValueChanged.AddListener(_callbackString);
                _onValueChanged += (value) => { if (inputField)
                                                {
                                                    inputField.text = value.ToString();
                                                }
                };
                _bindedControls.Add(control);
            }
            else if (control is Text)
            {
                Text text = control as Text;
                text.text        = Value.ToString();
                _onValueChanged += (value) => { if (text)
                                                {
                                                    text.text = value.ToString();
                                                }
                };
                _bindedControls.Add(control);
            }
            else if (control is Slider)
            {
                Slider slider = control as Slider;
                slider.value = Value;
                slider.onValueChanged.AddListener(_callbackFloat);
                _onValueChanged += (value) => { if (slider)
                                                {
                                                    slider.value = value;
                                                }
                };
                _bindedControls.Add(control);
            }
            else if (control is Dropdown)
            {
                Dropdown dropdown = control as Dropdown;
                dropdown.value = Value;
                dropdown.onValueChanged.AddListener(_callbackInt);
                _onValueChanged += (value) => { if (dropdown)
                                                {
                                                    dropdown.value = value;
                                                }
                };
                _bindedControls.Add(control);
            }
            else
            {
                Log.Warning(string.Format("自动化任务:数据绑定失败,当前不支持控件 {0} 与 BindableInt 类型的数据绑定!", control.GetType().FullName));
            }
        }
コード例 #10
0
        /// <summary>
        /// 绑定控件
        /// </summary>
        /// <param name="control">绑定的目标控件</param>
        protected override void Binding(UIBehaviour control)
        {
            base.Binding(control);

            if (_bindedControls.Contains(control))
            {
                return;
            }

            if (control is Dropdown)
            {
                Dropdown dropdown = control as Dropdown;
                if (dropdown.options == null)
                {
                    dropdown.options = new List <Dropdown.OptionData>();
                }
                while (dropdown.options.Count != _values.Count)
                {
                    if (dropdown.options.Count < _values.Count)
                    {
                        dropdown.options.Add(new Dropdown.OptionData());
                    }
                    else if (dropdown.options.Count > _values.Count)
                    {
                        dropdown.options.RemoveAt(0);
                    }
                }
                for (int i = 0; i < _values.Count; i++)
                {
                    dropdown.options[i].text = _values[i];
                }
                dropdown.value = Value;
                dropdown.onValueChanged.AddListener(_callback);
                _onValueChanged += (value) => { if (dropdown)
                                                {
                                                    dropdown.value = value;
                                                }
                };
                _bindedControls.Add(control);
            }
            else if (control is Text)
            {
                Text text = control as Text;
                text.text        = ValueString;
                _onValueChanged += (value) => { if (text)
                                                {
                                                    text.text = ValueString;
                                                }
                };
                _bindedControls.Add(control);
            }
            else
            {
                Log.Warning(string.Format("自动化任务:数据绑定失败,当前不支持控件 {0} 与 BindableSelectable 类型的数据绑定!", control.GetType().FullName));
            }
        }
コード例 #11
0
        /// <summary>
        /// 绑定控件
        /// </summary>
        /// <param name="control">绑定的目标控件</param>
        protected override void Binding(UIBehaviour control)
        {
            base.Binding(control);

            if (control is InputField)
            {
                InputField inputField = control as InputField;
                inputField.text = Value.ToString();
                inputField.onValueChanged.AddListener((value) =>
                {
                    float newValue;
                    if (float.TryParse(value, out newValue))
                    {
                        Value = newValue;
                    }
                });
                _onValueChanged += (value) => { if (inputField)
                                                {
                                                    inputField.text = value.ToString();
                                                }
                };
            }
            else if (control is Text)
            {
                Text text = control as Text;
                text.text        = Value.ToString();
                _onValueChanged += (value) => { if (text)
                                                {
                                                    text.text = value.ToString();
                                                }
                };
            }
            else if (control is Slider)
            {
                Slider slider = control as Slider;
                slider.value = Value;
                slider.onValueChanged.AddListener((value) => { Value = value; });
                _onValueChanged += (value) => { if (slider)
                                                {
                                                    slider.value = value;
                                                }
                };
            }
            else if (control is Scrollbar)
            {
                Scrollbar scrollbar = control as Scrollbar;
                scrollbar.value = Value;
                scrollbar.onValueChanged.AddListener((value) => { Value = value; });
                _onValueChanged += (value) => { if (scrollbar)
                                                {
                                                    scrollbar.value = value;
                                                }
                };
            }
            else
            {
                Log.Warning(string.Format("数据驱动器:数据绑定失败,当前不支持控件 {0} 与 BindableFloat 类型的数据绑定!", control.GetType().FullName));
            }
        }
コード例 #12
0
        /// <summary>
        /// 绑定控件
        /// </summary>
        /// <param name="control">绑定的目标控件</param>
        protected override void Binding(UIBehaviour control)
        {
            base.Binding(control);

            if (_bindedControls.Contains(control))
            {
                return;
            }

            if (control is InputField)
            {
                InputField inputField = control as InputField;
                inputField.text = Value;
                inputField.onValueChanged.AddListener(_callback);
                _onValueChanged += (value) => { if (inputField)
                                                {
                                                    inputField.text = value;
                                                }
                };
                _bindedControls.Add(control);
            }
            else if (control is Text)
            {
                Text text = control as Text;
                text.text        = Value;
                _onValueChanged += (value) => { if (text)
                                                {
                                                    text.text = value;
                                                }
                };
                _bindedControls.Add(control);
            }
            else
            {
                Log.Warning(string.Format("自动化任务:数据绑定失败,当前不支持控件 {0} 与 BindableString 类型的数据绑定!", control.GetType().FullName));
            }
        }