/// <summary> /// 分组 /// </summary> private void GroupingFontAsset() { m_FontGroups.Clear(); m_AllGroup.Clear(); if (font == null) { return; } if (font.spriteInfoList.Count <= 0) { return; } int len = font.spriteInfoList.Count; for (int index = 0; index < len; index++) { BMFontSprite sprite = font.spriteInfoList[index]; string group = sprite.group; if (!m_AllGroup.ContainsKey(group)) { m_FontGroups.Add(group); m_AllGroup.Add(group, new Dictionary <string, BMFontSprite>()); } m_AllGroup[group].Add(sprite.key, sprite); } }
private void SetupGroup() { if (m_BMFontAsset == null) { return; } m_FontNotGroupSpriteList.Clear(); m_FontSpriteListDic.Clear(); int len = this.m_BMFontAsset.spriteInfoList.Count; for (int index = 0; index < len; index++) { BMFontSprite element = m_BMFontAsset.spriteInfoList[index]; string group = element.group; if (string.IsNullOrEmpty(group)) { m_FontNotGroupSpriteList.Add(element); } else { if (!m_FontSpriteListDic.ContainsKey(group)) { m_GroupOption.Add(group); m_FontSpriteListDic.Add(group, new List <BMFontSprite>()); } m_FontSpriteListDic[group].Add(element); } } }
/// <summary> /// 解释字符串 /// </summary> private void ParserText() { if (m_FontList != null) { m_FontList.Clear(); } if (font == null) { return; } if (m_AllGroup.Count <= 0) { GroupingFontAsset(); } if (m_CurrentGroup == string.Empty || !m_AllGroup.ContainsKey(m_CurrentGroup)) { m_CurrentGroup = font.spriteInfoList[0].group; } if (string.IsNullOrEmpty(text)) { return; } char[] charArr = text.ToCharArray(); if (charArr.Length <= 0) { return; } Vector2 maxSize = Vector2.zero; for (int i = 0; i < charArr.Length; i++) { string s = charArr[i].ToString(); if (m_AllGroup[m_CurrentGroup].ContainsKey(s)) { BMFontSprite sprite = m_AllGroup[m_CurrentGroup][s]; m_FontList.Add(sprite); maxSize = new Vector2(maxSize.x + sprite.width + gap, maxSize.y > sprite.height ? maxSize.y : sprite.height); } } m_ContentBounds = new Bounds(Vector3.zero, new Vector3(maxSize.x, maxSize.y, 0)); }
private List <BMFontSprite> CreateSpriteFromCustomPackSetting(UnityPackSetting setting) { List <BMFontSprite> list = new List <BMFontSprite>(); for (int i = 0; i < setting.TexturePackSprite.Count; i++) { UnityPackSprite frame = setting.TexturePackSprite[i]; BMFontSprite spriteData = new BMFontSprite(); spriteData.id = i; spriteData.name = frame.filename; spriteData.hashCode = spriteData.name.GetHashCode(); string key = string.Empty; int pos = spriteData.name.LastIndexOf("_"); if (pos == -1) { key = spriteData.name; pos = spriteData.name.Length; } else { key = spriteData.name.Substring(pos + 1, spriteData.name.Length - pos - 1); } spriteData.key = key; spriteData.group = spriteData.name.Substring(0, pos); spriteData.x = frame.x; spriteData.y = frame.y; spriteData.width = frame.width; spriteData.height = frame.height; spriteData.pivot = frame.pivot; spriteData.scale = 1f; spriteData.xOffset = 0f - spriteData.width * spriteData.pivot.x; spriteData.yOffset = spriteData.height - spriteData.height * spriteData.pivot.y; list.Add(spriteData); } return(list); }
/// <summary> /// 分组 /// </summary> private void GroupingFontAsset() { m_FontGroups.Clear(); m_AllGroup.Clear(); if (font == null) { return; } if (font.spriteInfoList.Count <= 0) { return; } int len = font.spriteInfoList.Count; for (int index = 0; index < len; index++) { BMFontSprite sprite = font.spriteInfoList[index]; string group = sprite.group; if (!m_AllGroup.ContainsKey(group)) { m_FontGroups.Add(group); m_AllGroup.Add(group, new Dictionary <string, BMFontSprite>()); } if (!m_AllGroup[group].ContainsKey(sprite.key)) { m_AllGroup[group].Add(sprite.key, sprite); } else { Debug.LogError(string.Format("组{0},键值{1}冲突", group, sprite.key)); } } if (!m_FontGroups.Contains(m_CurrentGroup) || m_CurrentGroup == string.Empty) { m_CurrentGroup = m_FontGroups[0]; } }
private List <BMFontSprite> CreateSpriteFromUnityPackSetting(TextureImporter importer) { List <BMFontSprite> list = new List <BMFontSprite>(); for (int i = 0; i < importer.spritesheet.Length; i++) { SpriteMetaData frame = importer.spritesheet[i]; BMFontSprite fontData = new BMFontSprite(); fontData.id = i; fontData.name = Path.GetFileNameWithoutExtension(frame.name); fontData.hashCode = fontData.name.GetHashCode(); int num = fontData.name.IndexOf('-'); //分组 string key = string.Empty; int pos = fontData.name.LastIndexOf("_"); if (pos == -1) { key = fontData.name; pos = fontData.name.Length; } else { key = fontData.name.Substring(pos + 1, fontData.name.Length - pos - 1); } fontData.key = key; fontData.group = fontData.name.Substring(0, pos); fontData.x = frame.rect.x; fontData.y = frame.rect.y; fontData.width = frame.rect.width; fontData.height = frame.rect.height; fontData.pivot = frame.pivot; fontData.scale = 1f; fontData.xOffset = 0f - fontData.width * fontData.pivot.x; fontData.yOffset = fontData.height - fontData.height * fontData.pivot.y; list.Add(fontData); } return(list); }
private List <BMFontSprite> CreateSpriteInfoList(TP.TexturePackJsonData spriteDataObject) { List <TP.SpriteData> frames = spriteDataObject.frames; List <BMFontSprite> list = new List <BMFontSprite>(); for (int i = 0; i < frames.Count; i++) { BMFontSprite fontData = new BMFontSprite(); fontData.id = i; fontData.name = Path.GetFileNameWithoutExtension(frames[i].filename); fontData.hashCode = fontData.name.GetHashCode(); int num = fontData.name.IndexOf('-'); // int ascii; string key = string.Empty; int pos = fontData.name.LastIndexOf("_"); if (pos == -1) { key = fontData.name; pos = fontData.name.Length; } else { key = fontData.name.Substring(pos + 1, fontData.name.Length - pos - 1); } fontData.key = key; fontData.group = fontData.name.Substring(0, pos); fontData.x = frames[i].frame.x; fontData.y = (float)this.m_TextureSource.height - (frames[i].frame.y + frames[i].frame.h); fontData.width = frames[i].frame.w; fontData.height = frames[i].frame.h; fontData.pivot = frames[i].pivot; fontData.xAdvance = fontData.width; fontData.scale = 1f; fontData.xOffset = 0f - fontData.width * fontData.pivot.x; fontData.yOffset = fontData.height - fontData.height * fontData.pivot.y; list.Add(fontData); } return(list); }
/// <summary> /// 解释字符串 /// </summary> private void ParserText() { m_FontList.Clear(); m_OffestList.Clear(); Vector2 maxSize = Vector2.zero; if (m_FontDataList == null || m_FontDataList.Count == 0) { return; } if (font == null) { return; } for (int index = 0; index < m_FontDataList.Count; index++) { string text = m_FontDataList[index].text; if (string.IsNullOrEmpty(text)) { continue; } if ((m_FontDataList[index].group == null || !m_AllGroup.ContainsKey(m_FontDataList[index].group))) { m_FontDataList[index].group = null; } if (m_FontGroups.Count > 0 && m_FontDataList[index].group == null) { m_FontDataList[index].group = m_FontGroups[0]; } if (string.IsNullOrEmpty(m_FontDataList[index].group)) { continue; } char[] charArr = text.ToCharArray(); if (charArr.Length <= 0) { return; } for (int i = 0; i < charArr.Length; i++) { string s = charArr[i].ToString(); if (m_AllGroup[m_FontDataList[index].group].ContainsKey(s)) { BMFontSprite sprite = m_AllGroup[m_FontDataList[index].group][s]; m_OffestList.Add(m_FontDataList[index].offest); m_FontList.Add(sprite); maxSize = new Vector2(maxSize.x + sprite.width + gap, maxSize.y > sprite.height ? maxSize.y : sprite.height); } } } m_ContentBounds = new Bounds(Vector3.zero, new Vector3(maxSize.x, maxSize.y, 0)); }
private void OnFontSpriteElementGUI(BMFontSprite element) { Rect rect = EditorGUILayout.BeginVertical("box"); float x = element.x; float y = element.y; float width = element.width; float height = element.height; Vector2 pivot = element.pivot; string key = element.key; Texture2D spriteSheet = this.m_SpriteAtlas.objectReferenceValue as Texture2D; if (spriteSheet == null) { Debug.LogWarning("Please assign a valid Sprite Atlas texture to the [" + serializedObject.targetObject.name + "] Sprite Asset.", serializedObject.targetObject); return; } Texture2D tex = null; if (SpriteDic.ContainsKey(element.name)) { tex = SpriteDic[element.name]; } else { tex = new Texture2D((int)element.width, (int)element.height); Color[] colors = spriteSheet.GetPixels((int)element.x, (int)element.y, (int)element.width, (int)element.height); tex.SetPixels(0, 0, (int)element.width, (int)element.height, colors); tex = TexturePackTool.ScaleTextureBilinear(tex, 2); tex.Apply(); SpriteDic.Add(element.name, tex); } EditorGUILayout.BeginHorizontal(); GUILayout.Label("ID: " + element.id); GUILayout.Space(10); GUILayout.Label(element.name); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(tex, GUILayout.Width(80), GUILayout.Height(80)); EditorGUILayout.BeginVertical(); GUILayout.Space(8); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Group: "); GUILayout.TextField(element.group); EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Key: "); element.key = EditorGUILayout.TextField(element.key); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { if (m_FontSpriteListDic.ContainsKey(element.group)) { List <BMFontSprite> tempGroup = m_FontSpriteListDic[element.group]; for (int i = 0; i < tempGroup.Count; i++) { if (tempGroup[i].key == element.key) { Debug.LogError("KEY 冲突"); break; } } } } GUILayout.Label(string.Format(" Size : W: {0} H: {1}", element.width, element.height)); GUILayout.Label(string.Format(" Pivot : X: {0} Y: {1}", element.pivot.x, element.pivot.y)); GUILayout.Label(string.Format(" UV : X: {0} Y: {1} W: {2} H: {3}", element.x, element.y, element.width, element.height)); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); GUILayout.Space(10); EditorGUILayout.EndVertical(); }