/// <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); }
/// <summary> /// 设置数据 /// </summary> /// <param name="propsBase"></param> public void SetProps(APropsBase propsBase) { var t = propsBase as T; if (t == null) { BDebug.LogError("类型转换失败:" + propsBase.GetType().Name); } else { this.SetProps(t); } }