コード例 #1
0
ファイル: TEXSDFImporter.cs プロジェクト: step4/rac-quiz
        static TexFont Deconvert(TexFontSigned asset)
        {
            var n = ScriptableObject.CreateInstance <TexFont>();

            asset.ImportDictionary();
            EditorJsonUtility.FromJsonOverwrite(EditorJsonUtility.ToJson(asset), n);
            n.ImportAsset(asset.rawpath);
            var main = TEXPreference.main;

            main.fontnames[asset.id] = main.fonts[Array.IndexOf(main.fonts, asset)] = n;
            AssetDatabase.CreateAsset(n, AssetDatabase.GetAssetPath(asset));
            n.ImportDictionary();
            return(n);
        }
コード例 #2
0
ファイル: TEXSDFImporter.cs プロジェクト: step4/rac-quiz
        static void OnFinished(TexFontSigned font)
        {
            var sdfPath = TEXPreference.main.MainFolderPath + "/Fonts/TMPro/" + font.id + ".asset";

            TMP_FontAsset asset;

            if (!(asset = AssetDatabase.LoadAssetAtPath <TMP_FontAsset>(sdfPath)))
            {
                // It doesn't exist (or invalid), so create new
                asset = font.asset = ScriptableObject.CreateInstance <TMP_FontAsset>();
                if (!AssetDatabase.IsValidFolder(TEXPreference.main.MainFolderPath + "/Fonts/TMPro"))
                {
                    AssetDatabase.CreateFolder(TEXPreference.main.MainFolderPath + "/Fonts", "TMPro");
                }
                AssetDatabase.CreateAsset(asset, sdfPath);
            }
            asset.fontAssetType = _render >= RenderModes.DistanceField16 ? TMP_FontAsset.FontAssetTypes.SDF : TMP_FontAsset.FontAssetTypes.Bitmap;
            FaceInfo face = GetFaceInfo(_faceInfo, 1);

            asset.AddFaceInfo(face);

            _atlasInfo = new Texture2D(_bufferWidth, _bufferHeight, TextureFormat.Alpha8, false, true);
            var _buffer32 = Array.ConvertAll(_buffers, x => new Color32(x, x, x, x));

            _atlasInfo.SetPixels32(_buffer32);
            _atlasInfo.Apply(false, true);

            // Add GlyphInfo[] to Font Asset
            TMP_Glyph[] glyphs = GetGlyphInfo(_glyphsInfo, 1);
            asset.AddGlyphInfo(glyphs);

            // Get and Add Kerning Pairs to Font Asset

            KerningTable kerningTable = GetKerningTable(font.rawpath, (int)face.PointSize);

            asset.AddKerningInfo(kerningTable);

            // Add Line Breaking Rules
            //LineBreakingTable lineBreakingTable = new LineBreakingTable();
            //

            // Add Font Atlas as Sub-Asset
            asset.atlas          = _atlasInfo;
            _atlasInfo.name      = font.id + " Atlas";
            _atlasInfo.hideFlags = HideFlags.HideInHierarchy;
            AssetDatabase.AddObjectToAsset(_atlasInfo, asset);

            // Create new Material and Add it as Sub-Asset
            Shader   default_Shader = Shader.Find("TextMeshPro/Distance Field"); //m_shaderSelection;
            Material tmp_material   = new Material(default_Shader);

            tmp_material.name = _atlasInfo + " Material";
            tmp_material.SetTexture(ShaderUtilities.ID_MainTex, _atlasInfo);
            tmp_material.SetFloat(ShaderUtilities.ID_TextureWidth, _atlasInfo.width);
            tmp_material.SetFloat(ShaderUtilities.ID_TextureHeight, _atlasInfo.height);

            tmp_material.SetFloat(ShaderUtilities.ID_WeightNormal, asset.normalStyle);
            tmp_material.SetFloat(ShaderUtilities.ID_WeightBold, asset.boldStyle);

            int spread = _render >= RenderModes.DistanceField16 ? _padding + 1 : _padding;

            tmp_material.SetFloat(ShaderUtilities.ID_GradientScale, spread); // Spread = Padding for Brute Force SDF.

            asset.material         = tmp_material;
            tmp_material.hideFlags = HideFlags.HideInHierarchy;

            AssetDatabase.AddObjectToAsset(tmp_material, asset);

            font.asset = asset;
            font.ImportDictionary();
            AssetDatabase.SaveAssets();
        }