示例#1
0
        private void OnDone()
        {
            EditorUtility.ClearProgressBar();

            EditorApplication.update -= OnUpdate;

            UpdateRenderFeedbackWindow();
            CreateFontTexture();

            foreach (var asset in m_assets)
            {
                Save_SDF_FontAsset(asset);
            }

            m_fontAtlas = null;

            TMPro_FontPlugin.Destroy_FontEngine();

            if (m_fontAtlas != null && EditorUtility.IsPersistent(m_fontAtlas) == false)
            {
                GameObject.DestroyImmediate(m_fontAtlas);
            }

            Resources.UnloadUnusedAssets();
        }
示例#2
0
    public void OnDisable()
    {
        //Debug.Log("TextMeshPro Editor Window has been disabled.");

        // Destroy Engine only if it has been initialized already
        TMPro_FontPlugin.Destroy_FontEngine();

        if (m_FontAtlas != null && EditorUtility.IsPersistent(m_FontAtlas) == false)
        {
            //Debug.Log("Destroying font_Atlas!");
            DestroyImmediate(m_FontAtlas);
        }

        if (File.Exists("Assets/TextMesh Pro/Glyph Report.txt"))
        {
            File.Delete("Assets/TextMesh Pro/Glyph Report.txt");
            File.Delete("Assets/TextMesh Pro/Glyph Report.txt.meta");

            AssetDatabase.Refresh();
        }

        Resources.UnloadUnusedAssets();
    }
示例#3
0
    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);
        }
    }