コード例 #1
0
        public AStateBase()
        {
            var t     = this.GetType();
            var cache = StateFactory.GetCache(t);

            if (cache == null)
            {
                List <MemberInfo> list = new List <MemberInfo>();
                var flag = BindingFlags.Instance | BindingFlags.Public;
                list.AddRange(t.GetFields(flag));
                list.AddRange(t.GetProperties(flag));
                //缓存所有属性
                propMap = new Dictionary <string, MemberInfo>();
                foreach (var mi in list)
                {
                    var attrs = mi.GetCustomAttributes(typeof(TransformPath), false);
                    if (attrs.Length > 0)
                    {
                        propMap[mi.Name] = mi;
                    }
                }

                StateFactory.AddCache(t, propMap);
            }
            else
            {
                propMap = cache;
            }
        }
コード例 #2
0
        /// <summary>
        /// 设置所有属性改变
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        public void SetAllPropertyChanged()
        {
            var t    = this.GetType();
            var map  = StateFactory.GetCache(t);
            var list = map.Keys.ToArray();

            this.curProptyChangeList.Clear();
            this.curProptyChangeList.AddRange(list);
        }
コード例 #3
0
        /// <summary>
        /// bind Tansform和State的值,防止每次都修改
        /// </summary>
        /// <param name="transform"></param>
        /// <param name="props"></param>
        /// <returns></returns>
        private Dictionary <string, TransformBindData.ComponentFieldCahce> BindTransformProps(Transform transform,
                                                                                              APropsBase props)
        {
            var componentFieldCacheMap = new Dictionary <string, TransformBindData.ComponentFieldCahce>();
            //先初始化Props的成员信息
            var type = props.GetType();

            if (props.MemberinfoMap == null)
            {
                var memberInfoMap = StateFactory.GetMemberinfoCache(type);
                if (memberInfoMap == null)
                {
                    memberInfoMap = new Dictionary <string, MemberInfo>();
                    List <MemberInfo> memberInfoList = new List <MemberInfo>();
                    var flag = BindingFlags.Instance | BindingFlags.Public;
                    memberInfoList.AddRange(type.GetFields(flag));
                    memberInfoList.AddRange(type.GetProperties(flag));
                    //缓存所有属性
                    foreach (var mi in memberInfoList)
                    {
                        var attr = mi.GetAttributeInILRuntime <ComponentValueBindAttribute>();
                        if (attr != null)
                        {
                            memberInfoMap[mi.Name] = mi;
                        }
                    }

                    StateFactory.AddMemberinfoCache(type, memberInfoMap);
                }

                props.MemberinfoMap = memberInfoMap;
            }

            //进行值绑定
            foreach (var mi in props.MemberinfoMap.Values)
            {
                var cf        = new TransformBindData.ComponentFieldCahce();
                var attribute = mi.GetAttributeInILRuntime <ComponentValueBindAttribute>();
                if (attribute.Type == null)
                {
                    Debug.LogErrorFormat("is null: {0} - {1}", attribute.Type, attribute.FunctionName);
                    continue;
                }

                cf.Transform = transform.Find(attribute.TransformPath);
                if (attribute.Type.IsSubclassOf(typeof(UIBehaviour)))
                {
                    cf.UIBehaviour = cf.Transform.GetComponent(attribute.Type) as UIBehaviour;
                }

                cf.Attribute = attribute;
                //缓存
                componentFieldCacheMap[mi.Name] = cf;
            }

            return(componentFieldCacheMap);
        }
コード例 #4
0
        /// <summary>
        /// 设置所有属性改变
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        public void SetAllPropertyChanged()
        {
            IsMunalMarkMode = true;
            var t    = this.GetType();
            var map  = StateFactory.GetMemberinfoCache(t);
            var list = map.Keys.ToArray();

            this.changeProptyList.Clear();
            this.changeProptyList.AddRange(list);
        }
コード例 #5
0
        /// <summary>
        /// bind Tansform和State的值,防止每次都修改
        /// </summary>
        /// <param name="t"></param>
        /// <param name="aState"></param>
        /// <returns></returns>
        private Dictionary <string, ComponentValueCahce> TransformStateBind(Transform t, AStateBase aState)
        {
            Dictionary <string, ComponentValueCahce> retMap = new Dictionary <string, ComponentValueCahce>();
            //所有的成员信息
            var memberInfos = StateFactory.GetCache(aState.GetType());

            foreach (var mi in memberInfos.Values)
            {
                //先寻找节点
                Transform transform = null;
                {
                    var attrs = mi.GetCustomAttributes(typeof(TransformPath), false);
                    if (attrs.Length > 0)
                    {
                        var attr = attrs[0] as TransformPath;
                        transform = t.Find(attr.Path);
                        if (!transform)
                        {
                            BDebug.LogError("节点不存在:" + attr.Path + "  -" + aState.GetType().Name);
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                //再进行值绑定
                {
                    ComponentValueCahce cvc = new ComponentValueCahce();

                    var attrType = typeof(ComponentValueBind);
                    var attrs    = mi.GetCustomAttributes(attrType, false);
                    //
                    if (attrs.Length > 0) //寻找ComponentValueBind
                    {
                        if (attrs[0] is ComponentValueBind)
                        {
                            var cvb = (ComponentValueBind)attrs[0];

                            if (cvb.Type.IsSubclassOf(typeof(UIBehaviour)))
                            {
                                cvc.UIBehaviour = transform.GetComponent(cvb.Type) as UIBehaviour;
                            }
                            else
                            {
                                cvc.Transform = transform;
                            }

                            cvc.ValueBind = cvb;
                        }
                    }
                    else //如果只有Transform 没有ComponentValueBind标签,处理默认逻辑
                    {
                        Type type = null;

                        if (mi is FieldInfo)
                        {
                            type = ((FieldInfo)mi).FieldType;
                        }
                        else if (mi is PropertyInfo)
                        {
                            type = ((PropertyInfo)mi).PropertyType;
                        }


                        if (type.IsSubclassOf(typeof(PropsBase)))
                        {
                            //填充 子节点赋值逻辑
                            cvc.ValueBind =
                                new ComponentValueBind(typeof(UFluxAutoLogic), nameof(UFluxAutoLogic.SetChildValue));
                        }
                        else
                        {
                            cvc.ValueBind = new ComponentValueBind(typeof(UFluxAutoLogic), nameof(UFluxAutoLogic.ForeachSetChildValue));

                            #if UNITY_EDITOR
                            //props 数组
                            if (type.IsArray && !type.GetElementType().IsSubclassOf(typeof(PropsBase)))  //数组
                            {
                                Debug.LogError("自动适配节点逻辑失败,类型元素不是Props!!!");
                            }
                            //泛型
                            else if (type.IsGenericType && !type.GetGenericArguments()[0].IsSubclassOf(typeof(PropsBase))) //泛型
                            {
                                Debug.LogError("自动适配节点逻辑失败,类型元素不是Props!!!");
                            }
                            #endif

                            //list t或者array
                            if (type.IsArray || type.IsGenericType)  //数组
                            {
                                cvc.ValueBind = new ComponentValueBind(typeof(UFluxAutoLogic), nameof(UFluxAutoLogic.ForeachSetChildValue));
                            }
                        }

                        cvc.Transform = transform;
                    }

                    //缓存
                    retMap[mi.Name] = cvc;
                }
            }

            return(retMap);
        }