private void OnUpdate() { var info = m_fontAssetPath; var progress = TMPro_FontPlugin.Check_RenderProgress(); EditorUtility.DisplayProgressBar("TMP_FontAssetUpdater", info, progress); }
private void MyUpdate() { if (m_IsRepaintNeeded) { //Debug.Log("Repainting..."); m_IsRepaintNeeded = false; Repaint(); } // 第一步创建字体渲染数组 // Update Progress bar is we are Rendering a Font. if (m_IsProcessing) { m_RenderingProgress = TMPro_FontPlugin.Check_RenderProgress(); m_FontAssetInfos[m_CurGenerateIndex].genPercent = m_RenderingProgress * 100; m_IsRepaintNeeded = true; } // Update Feedback Window & Create Font Texture once Rendering is done. if (m_IsRenderingDone) { // Stop StopWatch m_StopWatch.Stop(); Debug.Log("Font Atlas generation completed in: " + m_StopWatch.Elapsed.TotalMilliseconds.ToString("0.000 ms.")); m_StopWatch.Reset(); m_IsProcessing = false; m_IsRenderingDone = false; if (m_IsGenerationCancelled == false) { // 第二步输出渲染结果 UpdateRenderFeedbackWindow(); // 第三步将渲染数组填充到纹理贴图(注意,贴图共享不删除) CreateFontTexture(); foreach (var asset in m_FontAssetInfos[m_CurGenerateIndex].assets) { // 最后保存信息到字体资产 Save_SDF_FontAsset(asset); } // 最后置空 m_FontAtlas = null; } Repaint(); } }
public static void SetupGUI(TexAsset asset) { EditorGUI.BeginDisabledGroup(onRendering); GUILayout.BeginHorizontal(); GUI.changed = false; GUILayout.Label("Atlas Resolution", GUILayout.Width(EditorGUIUtility.labelWidth)); _bufferWidth = EditorGUILayout.IntPopup(_bufferWidth, FontResolutionLabels, FontAtlasResolutions); //, GUILayout.Width(80)); _bufferHeight = EditorGUILayout.IntPopup(_bufferHeight, FontResolutionLabels, FontAtlasResolutions); //, GUILayout.Width(80)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Padding", GUILayout.Width(EditorGUIUtility.labelWidth)); _padding = EditorGUILayout.IntSlider(_padding, 1, 10); GUILayout.EndHorizontal(); _render = (RenderModes)EditorGUILayout.EnumPopup(_render); if (GUILayout.Button("Render")) { CreateSDFAsset(asset); } EditorGUI.BeginDisabledGroup(onRendering || asset.type != TexAssetType.FontSigned); GUI.backgroundColor = Color.red; if (GUILayout.Button("Delete SDF Asset")) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(((TexFontSigned)asset).asset)); asset = Deconvert((TexFontSigned)asset); } GUI.backgroundColor = Color.white; EditorGUI.EndDisabledGroup(); { EditorGUILayout.Space(); if (GUILayout.Button("Render All Fonts")) { onRenderingBatch = (EditorUtility.DisplayDialogComplex("Confirm Action", "Are you sure? This will take few moments.\nAnd what will you do with existing SDF Asset?", "Overwrite", "Cancel", "Skip (Faster)")); onRenderingBatch = onRenderingBatch == 1 ? 0 : (onRenderingBatch == 0 ? 1 : 2); if (onRenderingBatch > 0) { DoBatchRendering(); } } EditorGUI.BeginDisabledGroup(onRendering); GUI.backgroundColor = new Color(0.5f, 0, 0.5f); if (GUILayout.Button("Delete All SDF Asset")) { if (EditorUtility.DisplayDialog("Confirm Deletion", "Are you sure you want to delete ALL SDF Font Asset?", "Yes", "No")) { var fonts = TEXPreference.main.fonts; for (int i = 0; i < fonts.Length; i++) { EditorUtility.DisplayProgressBar("Please wait", "Reimporting Fonts...", i / (float)fonts.Length); if (fonts[i].type == TexAssetType.FontSigned) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(((TexFontSigned)fonts[i]).asset)); Deconvert((TexFontSigned)fonts[i]); } } TEXPreference.main.RebuildMaterial(); EditorUtility.ClearProgressBar(); } } GUI.backgroundColor = Color.white; EditorGUI.EndDisabledGroup(); } EditorGUI.EndDisabledGroup(); if (onRendering) { var prog = TMPro_FontPlugin.Check_RenderProgress(); EditorGUI.ProgressBar(EditorGUILayout.GetControlRect(), prog, prog.ToString("P")); if (onRenderingBatch > 0) { if (onRenderingBatch == 3) { EditorGUILayout.HelpBox("Will be stopped after current rendering is done", MessageType.Info); } else { GUI.backgroundColor = Color.yellow; if (GUILayout.Button("Cancel")) { onRenderingBatch = 3; } GUI.backgroundColor = Color.white; } } } }
static void RenderUpdate() { if (renderCompleted) { if (textureChannel == 0) { for (int i = 0; i < textureColors.Length; i++) { textureColors[i].r = textureBuffer[i]; } } if (textureChannel == 1) { for (int i = 0; i < textureColors.Length; i++) { textureColors[i].g = textureBuffer[i]; } } if (textureChannel == 2) { for (int i = 0; i < textureColors.Length; i++) { textureColors[i].b = textureBuffer[i]; } } if (textureChannel == 3) { for (int i = 0; i < textureColors.Length; i++) { textureColors[i].a = textureBuffer[i]; } } var size = (float)textureSize; var ascender = faceInfo.ascender; var glyphCount = faceInfo.characterCount; var charSet = new HashSet <int>(); for (int i = 0; i < glyphCount; i++) { var charInfo = new CharacterInfo(); var id = glyphInfo[i].id; var x = (glyphInfo[i].x - charPadding); var y = (glyphInfo[i].y - charPadding); var width = (glyphInfo[i].width + charPadding + charPadding); var height = (glyphInfo[i].height + charPadding + charPadding); var xOffset = glyphInfo[i].xOffset; var yOffset = glyphInfo[i].yOffset - ascender; var xAdvance = glyphInfo[i].xAdvance; var uvMinX = Mathf.Round(x) / size; var uvMinY = Mathf.Round(size - y - height) / size; var uvMaxX = Mathf.Round(x + width) / size; var uvMaxY = Mathf.Round(size - y) / size; charInfoList.Add(charInfo); charInfo.uvTopLeft = new Vector2(uvMinX, uvMinY); charInfo.uvTopRight = new Vector2(uvMaxX, uvMinY); charInfo.uvBottomLeft = new Vector2(uvMinX, uvMaxY); charInfo.uvBottomRight = new Vector2(uvMaxX, uvMaxY); charInfo.minX = Mathf.RoundToInt(xOffset); charInfo.minY = Mathf.RoundToInt(yOffset); charInfo.maxX = Mathf.RoundToInt(xOffset + width); charInfo.maxY = Mathf.RoundToInt(yOffset - height); charInfo.advance = Mathf.RoundToInt(xAdvance); charInfo.index = id; charSet.Add(id); } for (int i = 0; i < charCodes.Length; i++) { if (!charSet.Contains(charCodes[i])) { Debug.Log("Missing: " + (char)charCodes[i] + "|" + i + "|" + charCodes[i] + "|0x" + charCodes[i].ToString("X4")); } } Debug.Log("Glyph:" + glyphCount + ", " + charCodes[0] + " - " + charCodes[charCodes.Length - 1]); if (textureChannel < 3) { CreateTexture(textureChannel + 1); } else { EditorUtility.ClearProgressBar(); EditorApplication.update -= RenderUpdate; TMPro_FontPlugin.Destroy_FontEngine(); var texturePath = outputFolder + fontName + ".png"; var materialPath = outputFolder + fontName + ".mat"; var fontPath = outputFolder + fontName + ".fontsettings"; var texture = new Texture2D(textureSize, textureSize, TextureFormat.RGBA32, false, true); texture.SetPixels32(textureColors); File.WriteAllBytes(texturePath, texture.EncodeToPNG()); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); var import = AssetImporter.GetAtPath(texturePath) as TextureImporter; import.textureCompression = TextureImporterCompression.Uncompressed; import.alphaIsTransparency = false; import.mipmapEnabled = false; AssetDatabase.ImportAsset(texturePath); var material = new Material(Shader.Find("SDF/GBK/Text")); material.mainTexture = AssetDatabase.LoadAssetAtPath <Texture2D>(texturePath); AssetDatabase.CreateAsset(material, materialPath); var font = new Font(fontName); var mFont = new SerializedObject(font); mFont.FindProperty("m_FontSize").floatValue = faceInfo.pointSize; mFont.FindProperty("m_LineSpacing").floatValue = faceInfo.lineHeight; mFont.ApplyModifiedProperties(); font.material = material; font.characterInfo = charInfoList.ToArray(); AssetDatabase.CreateAsset(font, fontPath); } } else { float progress = TMPro_FontPlugin.Check_RenderProgress(); string progressText = "Channel: " + textureChannel + " , Char: " + (int)(progress * charCount) + "/" + charCount; EditorUtility.DisplayProgressBar("Create Font", progressText, progress); } }