Exemple #1
0
    private static Texture2D[] DoImportTextures(FntParse parse, string rootPath, string fnt)
    {
        int len = parse.textureNames.Length;

        Texture2D[] textures = new Texture2D[len];
        for (int i = 0; i < len; i++)
        {
            // The texture name of the file generated by ShoeBox uses an absolute path
            string textureName = Path.GetFileName(parse.textureNames[i]);
            string texPath     = string.Format("{0}/{1}", rootPath, textureName);

            Texture2D texture = AssetDatabase.LoadMainAssetAtPath(texPath) as Texture2D;
            if (texture == null)
            {
                return(textures);
            }
            TextureImporter texImporter = AssetImporter.GetAtPath(texPath) as TextureImporter;
            texImporter.textureType      = TextureImporterType.Sprite;
            texImporter.spriteImportMode = SpriteImportMode.Multiple;
            texImporter.mipmapEnabled    = false;
            texImporter.SaveAndReimport();
            textures[i] = texture;
        }

        return(textures);
    }
    public static FntParse GetFntParse(ref string text)
    {
        FntParse parse = null;

        if (text.StartsWith("info"))
        {
            parse = new FntParse();
            parse.DoTextParse(ref text);
        }
        else if (text.StartsWith("<"))
        {
            parse = new FntParse();
            parse.DoXMLPase(ref text);
        }

        return(parse);
    }
Exemple #3
0
        void UpdateFont(TMP_FontAsset fontFile)
        {
            var fontText = m_SourceFontFile.text;
            var fnt      = FntParse.GetFntParse(ref fontText);

            for (int i = 0; i < fontFile.characterTable.Count; i++)
            {
                var unicode    = fontFile.characterTable[i].unicode;
                var glyphIndex = fontFile.characterTable[i].glyphIndex;
                for (int j = 0; j < fnt.charInfos.Length; j++)
                {
                    if (unicode == fnt.charInfos[j].index)
                    {
                        var glyph = fontFile.glyphLookupTable[glyphIndex];
                        PatchGlyph(fnt.rawCharInfos[j],
                                   fnt.textureHeight,
                                   fnt.textureWidth,
                                   ref glyph);
                        fontFile.glyphLookupTable[glyphIndex] = glyph;
                        break;
                    }
                }
            }

            var newFaceInfo = fontFile.faceInfo;

            newFaceInfo.baseline   = fnt.lineBaseHeight;
            newFaceInfo.lineHeight = fnt.lineHeight;
            newFaceInfo.ascentLine = fnt.lineHeight;
            newFaceInfo.pointSize  = fnt.fontSize;

            var fontType         = typeof(TMP_FontAsset);
            var faceInfoProperty = fontType.GetProperty("faceInfo");

            faceInfoProperty.SetValue(fontFile, newFaceInfo);

            fontFile.material.SetTexture("_MainTex", m_Texture2D);
            fontFile.atlasTextures[0] = m_Texture2D;
        }
Exemple #4
0
    static List <icon> icons;//= new List<icon>();
    static void Main(string[] args)
    {
        icons = new List <icon>();
        using (TextFieldParser parser = new TextFieldParser(@"c:\temp\map.csv"))
        {
            parser.TextFieldType = FieldType.Delimited;
            parser.SetDelimiters(",");
            while (!parser.EndOfData)
            {
                //Process row                  s
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");

                string[] fields = parser.ReadFields();
                var      str1   = Strings.StrConv(fields[0], VbStrConv.Wide, 1041);
                var      idd    = (int)char.Parse(str1);
                icon     s      = new icon
                {
                    id     = idd.ToString(),
                    x      = ToInt(fields[2]),
                    y      = ToInt(fields[3]),
                    height = ToInt(fields[4]),
                    width  = ToInt(fields[3])
                };
                icons.Add(s);
            }
            //foreach (var item in icons)
            //{
            //    Console.WriteLine($"{item.id} {item.x} {item.y} {item.height} {item.width}");
            //}
        }
        using (StreamReader sw = new StreamReader(@"c:\temp\m.fnt"))
        {
            string s = sw.ReadToEnd();
            FntParse.DoXMLPase(s, icons);
        }


        // Console.ReadKey();
    }
Exemple #5
0
    private void Build()
    {
        var texturePath = AssetDatabase.GetAssetPath(Texture);
        var rootPath    = Path.GetDirectoryName(texturePath);
        var fontPath    = string.Format("{0}/{1}.fontsettings", rootPath, Texture.name);
        var objs        = AssetDatabase.LoadAllAssetsAtPath(texturePath).ToList();

        objs.RemoveAt(0);
        Sprite[] sprites = objs.Cast <Sprite>().ToArray();

        string   text  = GetFntFormat(Characters, sprites);
        FntParse parse = FntParse.GetFntParse(ref text);

        if (parse == null)
        {
            return;
        }
        Texture2D[] textures = DoImportTextures(parse, rootPath, text);
        Font        font     = AssetDatabase.LoadMainAssetAtPath(fontPath) as Font;

        if (font == null)
        {
            font = new Font();
            AssetDatabase.CreateAsset(font, fontPath);
            AssetDatabase.WriteImportSettingsIfDirty(fontPath);
            AssetDatabase.ImportAsset(fontPath);
        }
        Material material = AssetDatabase.LoadAssetAtPath(fontPath, typeof(Material)) as Material;

        if (material == null)
        {
            material      = new Material(Shader.Find("UI/Default"));
            material.name = "Font Material";
            AssetDatabase.AddObjectToAsset(material, fontPath);
            AssetDatabase.ImportAsset(fontPath);
        }
        font.material        = material;
        material.shader      = Shader.Find(textures.Length > 1 ? "BFI/Font" + textures.Length : "UI/Default");
        material.mainTexture = textures[0];
        for (int i = 1; i < textures.Length; i++)
        {
            material.SetTexture("_MainTex" + (i + 1), textures[i]);
        }
        font.characterInfo = parse.charInfos;
        SerializedObject so = new SerializedObject(font);

        so.Update();
        so.FindProperty("m_FontSize").floatValue    = Mathf.Abs(parse.fontSize);
        so.FindProperty("m_LineSpacing").floatValue = parse.lineHeight;
        so.FindProperty("m_Ascent").floatValue      = parse.lineBaseHeight;
        SerializedProperty prop = so.FindProperty("m_Descent");

        if (prop != null)
        {
            prop.floatValue = parse.lineBaseHeight - parse.lineHeight;
        }
        UpdateKernings(so, parse.kernings);
        so.ApplyModifiedProperties();
        so.SetIsDifferentCacheDirty();
        AssetDatabase.SaveAssets();
    }