public static void UpdateSizeFromResourceDic(ResourceDic resourceDic, ref Vector2 defultSize) { if (resourceDic.ContainsKey("size")) { defultSize = ParamAnalysisTool.StringToVector2(resourceDic["size"]); } }
public static ResourceDic ToDictionary(string resourceStr) { if (string.IsNullOrEmpty(resourceStr)) { return(null); } var array = resourceStr.Split(line_seperator); var dic = new ResourceDic(); for (int i = 0; i < array.Length; i++) { var keyValue = array[i]; if (keyValue.Contains(dic_seperator.ToString())) { var index = keyValue.IndexOf(dic_seperator); if (index < 0 || index == keyValue.Length - 1) { continue; } var key = keyValue.Substring(0, index); var value = keyValue.Substring(index + 1); dic[key] = value; } } return(dic); }
/// <summary> /// 支持结构体的赋值 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="target"></param> /// <param name="resourceDic"></param> /// <returns></returns> public static object ChargeInfo(object target, ResourceDic resourceDic) { using (var enumerator = resourceDic.GetEnumerator()) { while (enumerator.MoveNext()) { var pair = enumerator.Current; var member = GetFieldOrPropertyMember(target, pair.Key); if (member != null) { if (member is FieldInfo) { var info = (member as FieldInfo); var value = GetValueFromTypeString(info.FieldType, pair.Value); if (value != null) { info.SetValue(target, value); } } else if (member is PropertyInfo) { var info = (member as PropertyInfo); var value = GetValueFromTypeString(info.PropertyType, pair.Value); if (value != null) { info.SetValue(target, value, null); } } } } } return(target); }
private static void ChargeDic(ResourceDic target, ResourceDic source) { target.Clear(); foreach (var keyvalue in source) { target.Add(keyvalue.Key, keyvalue.Value); } }
public LayerInfo() { resourceDic = new ResourceDic(); subResourceDic = new Dictionary <string, ResourceDic>(); sub_images = new List <ResourceDic>(); sub_rawImages = new List <ResourceDic>(); sub_texts = new List <ResourceDic>(); }
private static void AppendSubDic(StringBuilder stringBuilder, string subKey, ResourceDic subDic) { var subText = FromDictionary(subDic); stringBuilder.Append(subKey); stringBuilder.Append(":{\n"); stringBuilder.Append(subText); stringBuilder.Append("}\n"); }
/// <summary> /// 从字典中解析rect信息 /// </summary> /// <param name="defultRect"></param> /// <param name="resourceDic"></param> /// <returns></returns> public static Rect AddSubRectFromResourceDic(Rect defultRect, ResourceDic resourceDic) { if (resourceDic.ContainsKey("rect")) { var subRect = ParamAnalysisTool.StringToRect(resourceDic["rect"]); defultRect = new Rect(defultRect.x + subRect.x, defultRect.y + subRect.y, subRect.width, subRect.height); } return(defultRect); }
public static string FromDictionary(ResourceDic resourceDic) { StringBuilder text = new StringBuilder(); using (var enumerator = resourceDic.GetEnumerator()) { while (enumerator.MoveNext()) { var pair = enumerator.Current; text.Append(string.Format("{0}:{1}\n", pair.Key, pair.Value)); } } return(text.ToString()); }
/// <summary> /// 从字典中解析rect信息 /// </summary> /// <param name="defultRect"></param> /// <param name="resourceDic"></param> /// <returns></returns> public static bool UpdateRectFromResourceDic(ref Rect defultRect, ResourceDic resourceDic) { if (resourceDic.ContainsKey("rect")) { defultRect = ParamAnalysisTool.StringToRect(resourceDic["rect"]); return(true); } else if (resourceDic.ContainsKey("padding")) { var paddingRect = ParamAnalysisTool.StringToVector4(resourceDic["padding"]); defultRect = new Rect(defultRect.x + paddingRect.x, defultRect.y + paddingRect.y, defultRect.width - paddingRect.z - paddingRect.x, defultRect.height - paddingRect.y - paddingRect.w); } return(false); }
public void SetUIParams(UINode node) { var inputField = node.GetComponent <InputField>(); ResourceDic textComponentResourceDic = null; ResourceDic placeHolderResourceDic = null; ///加载子项资源 if (node.layerInfo.subResourceDic != null) { using (var enumerator = node.layerInfo.subResourceDic.GetEnumerator()) { while (enumerator.MoveNext()) { var current = enumerator.Current; if (current.Key == key_placeholder) { mechine.ChargeInfo(inputField.placeholder, current.Value); placeHolderResourceDic = current.Value; } else if (current.Key == key_textComponent) { mechine.ChargeInfo(inputField.textComponent, current.Value); textComponentResourceDic = current.Value; } else { mechine.ChargeSubInfo(inputField, current.Key, current.Value); } } } } //加载属性信息 if (node.layerInfo.resourceDic != null) { mechine.ChargeInfo(inputField, node.layerInfo.resourceDic); } inputField.placeholder.rectTransform.SetRectFromResource(node.layerInfo.rect, placeHolderResourceDic); inputField.textComponent.rectTransform.SetRectFromResource(node.layerInfo.rect, textComponentResourceDic); }
public ResourceDic(ResourceDic info) : base(info) { }
public void SetUIParams(UINode node) { var slider = node.GetComponent <Slider>(); var backgroundImage = node.GetSubComponent <Image>(runtime_key_background); ///加载Slider属性 if (node.layerInfo.resourceDic != null) { mechine.ChargeInfo(slider, node.layerInfo.resourceDic); } var fillRect = node.GetSubComponent <RectTransform>(runtime_key_fill); ResourceDic fillResourceDic = null; ///加载子项资源 if (node.layerInfo.subResourceDic != null) { using (var enumerator = node.layerInfo.subResourceDic.GetEnumerator()) { while (enumerator.MoveNext()) { var current = enumerator.Current; if (current.Key == runtime_key_background)//动态背景 { backgroundImage.rectTransform.SetRectFromResource(node.layerInfo.rect, current.Value); mechine.ChargeInfo(backgroundImage, current.Value); } else if (current.Key == runtime_key_fill) { var key = current.Key; mechine.ChargeInfo(slider.fillRect.GetComponent <Image>(), current.Value); fillResourceDic = current.Value; } else if (current.Key == runtime_key_handle) { var handleArea = new GameObject("Handle Slide Area", typeof(RectTransform)).GetComponent <RectTransform>(); handleArea.transform.SetParent(slider.transform, false); var handle = new GameObject("Handle", typeof(Image)).GetComponent <RectTransform>(); handle.transform.SetParent(handleArea.transform, false); slider.handleRect = handle.GetComponent <RectTransform>(); mechine.ChargeInfo(slider.handleRect.GetComponent <Image>(), current.Value); Vector2 handleSize = new Vector2(node.layerInfo.rect.height, node.layerInfo.rect.height); LayerImportUtil.UpdateSizeFromResourceDic(current.Value, ref handleSize); if (slider.direction == Slider.Direction.BottomToTop || slider.direction == Slider.Direction.TopToBottom) { var handleRectX = (node.layerInfo.rect.width - handleSize.x) * 0.5f; var handleAreaRect = new Rect(handleRectX, handleSize.y * 0.5f, handleSize.x, node.layerInfo.rect.height - handleSize.y); handleAreaRect = ParamAnalysisTool.PsRectToUnityRect(node.layerInfo.rect.size, handleAreaRect); LayerImportUtil.SetRectTransform(handleAreaRect, handleArea); LayerImportUtil.SetCustomAnchor(node.layerInfo.rect.size, handleArea); handle.anchorMin = Vector2.zero; handle.anchorMax = new Vector2(1, 0); handle.sizeDelta = new Vector2(0, handleSize.y); } else { var handleRectY = (node.layerInfo.rect.height - handleSize.y) * 0.5f; var handleAreaRect = new Rect(handleSize.x * 0.5f, handleRectY, node.layerInfo.rect.width - handleSize.x, handleSize.y); handleAreaRect = ParamAnalysisTool.PsRectToUnityRect(node.layerInfo.rect.size, handleAreaRect); LayerImportUtil.SetRectTransform(handleAreaRect, handleArea); LayerImportUtil.SetCustomAnchor(node.layerInfo.rect.size, handleArea); handle.anchorMin = Vector2.zero; handle.anchorMax = new Vector2(0, 1); handle.sizeDelta = new Vector2(handleSize.x, 0); } } else { mechine.ChargeSubInfo(slider, current.Key, current.Value); } } } } fillRect.SetRectFromResource(node.layerInfo.rect, fillResourceDic); slider.fillRect.anchorMin = Vector2.zero; slider.fillRect.anchorMax = Vector2.one; slider.fillRect.sizeDelta = Vector2.zero; LayerImportUtil.LoadCommonResources(mechine, node); slider.value = slider.minValue; }
/// <summary> /// 装载入信息 /// </summary> /// <param name="component"></param> /// <param name="resourceDic"></param> public static void ChargeSubInfo(this AssemblerStateMechine mechine, Component component, string current, ResourceDic resourceDic) { component.gameObject.SetActive(resourceDic.active); if (!resourceDic.active) { return; } using (var enumerator = resourceDic.GetEnumerator()) { while (enumerator.MoveNext()) { var pair = enumerator.Current; var key = current + "." + pair.Key; ChargeInfoInternal(component, mechine, key, pair.Value); } } }
/// <summary> /// 按资源的Rect设置拉伸的坐标 /// </summary> /// <param name="rectTransform"></param> /// <param name="rootRect"></param> /// <param name="baseRect"></param> /// <param name="resourceDic"></param> public static void SetRectFromResource(this RectTransform rectTransform, Rect rootRect, Rect baseRect, ResourceDic resourceDic = null) { var rect = new Rect(Vector2.zero, baseRect.size); if (resourceDic != null) { if (LayerImportUtil.UpdateRectFromResourceDic(ref rect, resourceDic)) { //得到相对于BaseRect的相对值 rect = new Rect(rect.x + rootRect.x - baseRect.x, rect.y + rootRect.y - baseRect.y, rect.width, rect.height); } } rect = ParamAnalysisTool.PsRectToUnityRect(baseRect.size, rect); LayerImportUtil.SetRectTransform(rect, rectTransform); LayerImportUtil.SetCustomAnchor(baseRect.size, rectTransform); }
/// <summary> /// 按资源的Rect设置拉伸的坐标 /// </summary> /// <param name="rectTransform"></param> /// <param name="baseRect"></param> /// <param name="resourceDic"></param> public static void SetRectFromResource(this RectTransform rectTransform, Rect baseRect, ResourceDic resourceDic = null) { var rect = new Rect(Vector2.zero, baseRect.size); if (resourceDic != null) { LayerImportUtil.UpdateRectFromResourceDic(ref rect, resourceDic); } rect = ParamAnalysisTool.PsRectToUnityRect(baseRect.size, rect); LayerImportUtil.SetRectTransform(rect, rectTransform); LayerImportUtil.SetCustomAnchor(baseRect.size, rectTransform); }