public static void UpdateSizeFromResourceDic(ResourceDic resourceDic, ref Vector2 defultSize) { if (resourceDic.ContainsKey("size")) { defultSize = ParamAnalysisTool.StringToVector2(resourceDic["size"]); } }
/// <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); }
/// <summary> /// 普通UGUI节点 /// </summary> /// <param name="go"></param> /// <param name="rect"></param> /// <param name="parent"></param> /// <returns></returns> public static UINode CreateNormalNode(GameObject go, Transform root, Vector2 rootSize, LayerInfo layerInfo) { go.transform.SetParent(root, false); var uiRect = ParamAnalysisTool.PsRectToUnityRect(rootSize, layerInfo.rect); SetRectTransform(uiRect, go.transform as RectTransform); UINode node = new UINode(go.transform, layerInfo); return(node); }
/// <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); }
/// <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); }
/// <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); }
public static UINode CreateRootNode(this AssemblerStateMechine mechine, LayerInfo layerInfo, Rect customRect) { var path = layerInfo.path; var instenceName = NameFromPath(path); var go = new GameObject(instenceName, typeof(RectTransform)); go.layer = LayerMask.NameToLayer("UI"); go.transform.SetParent(mechine.canvas.transform, false); var uiRect = ParamAnalysisTool.PsRectToUnityRect(mechine.uiSize, customRect); SetRectTransform(uiRect, go.transform as RectTransform); UINode node = new UINode(go.transform, layerInfo); node.layerInfo = layerInfo; return(node); }
public static UIInfo LoadUIInfo(this CsvTable table) { if (table.IsUIInfoTable(false)) { var uiInfo = new UIInfo(table.name); if (table.Rows != null && table.Columns != null) { for (int i = 0; i < table.Rows.Count; i++) { var layerInfo = new LayerInfo(); layerInfo.name = table[0, i]; layerInfo.path = table[1, i]; layerInfo.type = table[2, i]; layerInfo.rect = ParamAnalysisTool.StringToRect(table[3, i]); var resourceDic = ParamAnalysisTool.ToDictionary(table[4, i]); if (resourceDic != null) { ChargeDic(layerInfo.resourceDic, resourceDic); } if (table.Columns.Count > 5) { List <ResourceDic> sub_images; List <ResourceDic> sub_texts; List <ResourceDic> sub_rawImages; var subResourceDic = ParamAnalysisTool.ToDictionary_Sub(table[5, i], out sub_images, out sub_texts, out sub_rawImages); if (subResourceDic != null) { ChargeDic(layerInfo.subResourceDic, subResourceDic); } ChargeList(layerInfo.sub_images, sub_images); ChargeList(layerInfo.sub_texts, sub_texts); ChargeList(layerInfo.sub_rawImages, sub_rawImages); } uiInfo.layers.Add(layerInfo); } } return(uiInfo); } return(null); }
public static CsvTable UIInfoToTable(this UIInfo info) { var table = new CsvTable(info.name); table.Columns = new List <string>(uiInfoHead); for (int i = 0; i < info.layers.Count; i++) { var layer = info.layers[i]; var raw = new string[table.Columns.Count]; raw[0] = layer.name; raw[1] = layer.path; raw[2] = layer.type; raw[3] = ParamAnalysisTool.RectToString(layer.rect); raw[4] = ParamAnalysisTool.FromDictionary(layer.resourceDic); raw[5] = ParamAnalysisTool.FromDictionarySub(layer.subResourceDic, layer.sub_images, layer.sub_texts, layer.sub_rawImages); table.Rows.Add(raw); } return(table); }
/// <summary> /// 按类型和字符串解析值 /// </summary> /// <param name="type"></param> /// <param name="value"></param> /// <returns></returns> public static object GetValueFromTypeString(Type type, string value) { if (type == typeof(Rect)) { return(ParamAnalysisTool.StringToRect(value)); } else if (type == typeof(Vector2)) { return(ParamAnalysisTool.StringToVector2(value)); } else if (type == typeof(Vector3)) { return(ParamAnalysisTool.StringToVector2(value)); } else if (type == typeof(Vector4)) { return(ParamAnalysisTool.StringToVector4(value)); } else if (typeof(IConvertible).IsAssignableFrom(type)) { if (type.IsSubclassOf(typeof(System.Enum))) { return(Enum.Parse(type, value)); } else { try { return(Convert.ChangeType(value, type)); } catch (Exception e) { Debug.LogWarning(e.Message + ":" + value); } } } Debug.LogWarningFormat("未成功解析类型为{0}的信息", type.FullName); return(null); }
public static void LoadFromCsvTable(this TextureInfoTable infoTable, CsvTable table) { var columsCount = table.Columns.Count; if (columsCount >= 3) { if (table.Rows != null && table.Columns != null) { if (infoTable.textureInfos == null) { infoTable.textureInfos = new List <TextureInfo>(); } else { infoTable.textureInfos.Clear(); } for (int i = 0; i < table.Rows.Count; i++) { var textureInfo = new TextureInfo(); textureInfo.texturePath = table[0, i]; textureInfo.type = (TextureImporterType)System.Enum.Parse(typeof(TextureImporterType), table[1, i]); textureInfo.resourceDic = ParamAnalysisTool.ToDictionary(table[2, i]); if (columsCount > 3) { textureInfo.spritesheetList = ParamAnalysisTool.ToDictionaryArray(table[3, i]); } infoTable.textureInfos.Add(textureInfo); } } } else { Debug.LogError("csv文档参数不足3个,请检查"); } }
public static object InnerStructFromString(Type type, string value) { if (type == typeof(ColorBlock)) { return(ParamAnalysisTool.StringToColorBlock(value)); } if (type == typeof(Color)) { return(ParamAnalysisTool.StringToColor(value)); } else if (type == typeof(Vector2)) { return(ParamAnalysisTool.StringToVector2(value)); } else if (type == typeof(Vector2Int)) { return(ParamAnalysisTool.StringToVector2Int(value)); } else if (type == typeof(Vector3)) { return(ParamAnalysisTool.StringToVector3(value)); } else if (type == typeof(Vector3Int)) { return(ParamAnalysisTool.StringToVector3Int(value)); } else if (type == typeof(Vector4)) { return(ParamAnalysisTool.StringToVector4(value)); } else if (type == typeof(Rect)) { return(ParamAnalysisTool.StringToRect(value)); } Debug.LogWarningFormat("未成功解析类型为{0}的信息", type.FullName); return(null); }
public static string InnerStructObjectToString(Type type, object value) { if (type == typeof(Rect)) { return(RectToString((Rect)value)); } else if (type == typeof(RectInt)) { return(RectIntToString((RectInt)value)); } else if (type == typeof(ColorBlock)) { return(ColorBlockToString((ColorBlock)value)); } else if (type == typeof(Vector2)) { return(ParamAnalysisTool.Vector2ToString((Vector2)value)); } else if (type == typeof(Vector2Int)) { return(ParamAnalysisTool.Vector2IntToString((Vector2Int)value)); } else if (type == typeof(Vector3)) { return(ParamAnalysisTool.Vector3ToString((Vector3)value)); } else if (type == typeof(Vector2Int)) { return(ParamAnalysisTool.Vector3IntToString((Vector3Int)value)); } else if (type == typeof(Vector4)) { return(ParamAnalysisTool.Vector4ToString((Vector4)value)); } return(null); }
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; }
public static object GetValueFromTypeString(Type type, string value, AssemblerStateMechine mechine) { if (type == typeof(SpriteState)) { return(ParamAnalysisTool.StringToSpriteState(value, mechine.spriteFolderPath)); } else if (type == typeof(ColorBlock)) { return(ParamAnalysisTool.StringToColorBlock(value)); } else if (type == typeof(Sprite)) { return(ParamAnalysisTool.StringToObject <Sprite>(value, mechine.spriteFolderPath)); } else if (type == typeof(Font)) { return(ParamAnalysisTool.StringToObject <Font>(value, mechine.fontFolderPath)); } else if (type == typeof(Material)) { return(ParamAnalysisTool.StringToObject <Material>(value, mechine.materialFolderPath)); } else if (type == typeof(Texture)) { return(ParamAnalysisTool.StringToObject <Texture>(value, mechine.textureFolderPath)); } else if (type == typeof(Texture2D)) { return(ParamAnalysisTool.StringToObject <Texture2D>(value, mechine.textureFolderPath)); } else if (type == typeof(Color)) { return(ParamAnalysisTool.StringToColor(value)); } else if (type == typeof(Vector2)) { return(ParamAnalysisTool.StringToVector2(value)); } else if (type == typeof(Vector3)) { return(ParamAnalysisTool.StringToVector3(value)); } else if (type == typeof(Vector4)) { return(ParamAnalysisTool.StringToVector4(value)); } else if (type == typeof(Rect)) { return(ParamAnalysisTool.StringToRect(value)); } else if (typeof(IConvertible).IsAssignableFrom(type)) { if (type.IsSubclassOf(typeof(System.Enum))) { return(Enum.Parse(type, value)); } else { try { return(Convert.ChangeType(value, type)); } catch (Exception e) { Debug.LogWarning(e.Message + ":" + value); } } } Debug.LogWarningFormat("未成功解析类型为{0}的信息", type.FullName); return(null); }