Search Unity

Make ttf from png images..

Discussion in 'UGUI & TextMesh Pro' started by MinsukCha, Aug 22, 2014.

  1. MinsukCha

    MinsukCha

    Joined:
    Jun 9, 2014
    Posts:
    13
    Is there any way to make font from image files for uGUI?
    Based on what I know so far, I can try below but I am not sure this is the only way to do it.
    First, I make a Bitmap font using BMFont Tool and make a .fnt file and get a image like a atlas.
    Then, I create a custom font from Unity, and Set material and put numbers for each Character Rects.

    I watched all New GUI system tutorials and I couldn't find about any image font. If anyone knows about this or relevant issues, please let me know.

    Thank you~
     
  2. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
  3. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    Code (CSharp):
    1.     public static void Import(TextAsset rects, Font font, Vector3 size)
    2.     {
    3.         string[] lines = rects.text.Split(_splitFile, StringSplitOptions.None);
    4.         CharacterInfo[] info = new CharacterInfo[lines.Length];
    5.         for (var i = 0; i < lines.Length; i++)
    6.         {
    7.             string[] line = lines[i].Split(_splitLine, StringSplitOptions.None);
    8.             int x = Convert.ToInt32(line[0]);
    9.             int y = Convert.ToInt32(line[1]);
    10.             int width = Convert.ToInt32(line[2]);
    11.             int height = Convert.ToInt32(line[3]);
    12.             int offset = Convert.ToInt32(line[4]);
    13.             info[i].uv.x = x / size.x;
    14.             info[i].uv.y = y / size.y;
    15.             info[i].uv.width = width / size.x;
    16.             info[i].uv.height = height / size.y;
    17.             info[i].vert.x = 0;
    18.             info[i].vert.y = -offset;
    19.             info[i].vert.width = width;
    20.             info[i].vert.height = -height;
    21.             info[i].width = width;
    22.             info[i].index = i;
    23.         }
    24.         font.characterInfo = info;
    25.         AssetDatabase.SaveAssets();
    26.     }
    27.  
     
  4. almo

    almo

    Joined:
    Jul 14, 2010
    Posts:
    83
    Thanks, I ended up using most of that code. :)