예제 #1
0
        public bool TypeConvert(object o, TargetBindingProperty target)
        {
            if (string.IsNullOrEmpty(target.name))
            {
                return(false);
            }
            if (target.name == "atlas")
            {
                var sprite = target.target.GetComponent <UISprite>();
                if (sprite == null)
                {
                    return(true);
                }
                var currentValue = "";
                if (sprite.atlas != null)
                {
                    currentValue = sprite.atlas.name;
                    if (currentValue.Equals(o.ToString()))
                    {
                        return(true);
                    }
                }
                var targetValue = "";
                var value       = o.ToString();
                if (value == "Grey")
                {
//需要把原本的设为灰度
                    if (currentValue.Contains("Grey"))
                    {
                        return(true);
                    }
                    //原来不是灰度
                    targetValue = currentValue + "Grey";
                }
                else if (value == "NotGrey")
                {
//需要把原本的设为彩色
                    if (currentValue.Contains("Grey"))
                    {
                        targetValue = currentValue.Remove(currentValue.Length - 4, 4);
                    }
                    else
                    {
//原来不是灰度
                        return(true);
                    }
                }
                else
                {
                    targetValue = value;
                }

                if (currentValue.Equals(targetValue))
                {
                    return(true);
                }
                target.AtlasValue = targetValue;

                if (targetValue.Contains("Circle"))
                {
                    var i = 1;
                }
                ResourceManager.PrepareResource <GameObject>("UI/Atlas/" + target.AtlasValue + ".prefab",
                                                             res =>
                {
                    if (res == null)
                    {
                        return;
                    }
                    //异步加载找不到原控件
                    if (target.target == null)
                    {
                        return;
                    }
                    if (targetValue == target.AtlasValue)
                    {
                        target.Set(res.GetComponent <UIAtlas>());
                    }
                }, true, true, true, false, true);
                return(true);
            }
            if (target.name == "mainTexture")
            {
                target.AtlasValue = o.ToString();
                ResourceManager.PrepareResource <Texture>(o.ToString(), res =>
                {
                    if (o.ToString() == target.AtlasValue)
                    {
                        target.Set(res);
                    }
                }, true, true, false, false, true);
                return(true);
            }
            if (target.name == "color")
            {
                if (o is string)
                {
                    var c = GameUtils.StringToColor(o.ToString());
                    target.Set(c);
                    return(true);
                }
            }
            if (target.name == "gradientBottom")
            {
                if (o is string)
                {
                    var c = GameUtils.StringToColor(o.ToString());
                    target.Set(c);
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        public void SetValue(object obj)
        {
            if (obj != null)
            {
                if (obj != null && mInvisibleListStr != null && mInvisibleListStr.Length > 0)
                {
                    for (var i = 0; i < mInvisibleListStr.Length; i++)
                    {
                        if (obj.ToString() == mInvisibleListStr[i])
                        {
                            if (obj.ToString() == mInvisibleListStr[i])
                            {
                                Target.target.gameObject.SetActive(false);
                                Target.target.gameObject.GetComponent <UIClassBinding>().SignalActiveChanged();
                                return;
                            }
                        }
                    }
                }
            }
            else
            {
                if (Target.target == null)
                {
                    Debug.LogError("........SetValue(object obj)  Target.target == null............");
                    return;
                }
                if (Target.target.gameObject == null)
                {
                    Debug.LogError("........SetValue(object obj)  Target.target.gameObject == null............");
                    return;
                }
                Target.Set(DefaultValue);
                return;
            }

            if (Target.target == null)
            {
                Debug.LogError("........SetValue(object obj)  Target.target == null............");
                return;
            }
            if (Target.target.gameObject == null)
            {
                Debug.LogError("........SetValue(object obj)  Target.target.gameObject == null............");
                return;
            }

            if (!string.IsNullOrEmpty(InvisibleValue) || Target.target is UILabel)
            {
                if (Target.target.gameObject.activeSelf == false)
                {
                    Target.target.gameObject.SetActive(true);
                    Target.target.gameObject.GetComponent <UIClassBinding>().SignalActiveChanged();
                }
            }

            if (!string.IsNullOrEmpty(InvisibleValue) && InvisibleValue.IndexOf('#') == 0)
            {
                if (SourceList == null || SourceList.Count == 0)
                {
                    SetValue(null);
                    return;
                }
//                 var visiRet = ExpressionHelper.GetExpressionString(
//                     Target.target.gameObject.GetComponent<UIClassBinding>().DataSource, InvisibleValue);
                var visiRet = ExpressionHelper.GetExpressionString(SourceList[0].RootData, InvisibleValue);
                Target.target.gameObject.SetActive(!(visiRet == "1"));
                Target.Set(obj);
                return;
            }

            if (string.IsNullOrEmpty(Target.name) || Target.name == "Null")
            {
                return;
            }

            if (Target.target is UILabel && Target.name == "text" && string.IsNullOrEmpty(obj.ToString()))
            {
                Target.target.gameObject.SetActive(false);
                Target.target.gameObject.GetComponent <UIClassBinding>().SignalActiveChanged();
            }

            if (TypeConvert(obj, Target))
            {
                return;
            }

            Target.Set(obj);
        }