最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

unity將圖片轉(zhuǎn)換成字體的方法

 更新時(shí)間:2020年04月18日 09:20:51   作者:醉落塵陽(yáng)光  
這篇文章主要為大家詳細(xì)介紹了unity將圖片轉(zhuǎn)換成字體的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了unity利用圖片來(lái)生成字體的具體代碼,供大家參考,具體內(nèi)容如下

開(kāi)發(fā)中,可能會(huì)用到需要將圖片轉(zhuǎn)換成字體的需求。

BMFONT 插件 導(dǎo)入圖片

然后生成 .fnt 和 .png 兩個(gè)文件 (文件格式可以在設(shè)置中更改)
將這兩個(gè)文件導(dǎo)入unity 將png 切割成精靈
創(chuàng)建材質(zhì)、將貼圖拖上去。
創(chuàng)建字體、將材質(zhì)拖上去。

數(shù)據(jù)怎么算出來(lái)的公式百度上面有,此處略去。也可以利用代碼來(lái)生成

using UnityEngine;
using System.Collections;
using System;
using System.Xml;

public class CustomFontImportor : MonoBehaviour {

  public Font font;
  public TextAsset textAsset;


  void Awake()
  {
    if (font == null || textAsset == null)
    {
      Debug.LogError("請(qǐng)?jiān)O(shè)置font和textAsset.");
      return;
    }

    XmlDocument xmlDocument = new XmlDocument();
    xmlDocument.LoadXml(textAsset.text);


    int totalWidth = Convert.ToInt32(xmlDocument["font"]["common"].Attributes["scaleW"].InnerText);
    int totalHeight = Convert.ToInt32(xmlDocument["font"]["common"].Attributes["scaleH"].InnerText);

    XmlElement xml = xmlDocument["font"]["chars"];
    ArrayList characterInfoList = new ArrayList();


    for (int i = 0; i < xml.ChildNodes.Count; ++i)
    {
      XmlNode node = xml.ChildNodes[i];
      if (node.Attributes == null)
      {
        continue;
      }
      int index = Convert.ToInt32(node.Attributes["id"].InnerText);
      int x = Convert.ToInt32(node.Attributes["x"].InnerText);
      int y = Convert.ToInt32(node.Attributes["y"].InnerText);
      int width = Convert.ToInt32(node.Attributes["width"].InnerText);
      int height = Convert.ToInt32(node.Attributes["height"].InnerText);
      int xOffset = Convert.ToInt32(node.Attributes["xoffset"].InnerText);
      int yOffset = Convert.ToInt32(node.Attributes["yoffset"].InnerText);
      int xAdvance = Convert.ToInt32(node.Attributes["xadvance"].InnerText);

      CharacterInfo info = new CharacterInfo();
      Rect uv = new Rect();
      uv.x = (float)x / totalWidth;
      uv.y = (float)(totalHeight - y - height) / totalHeight;
      uv.width = (float)width / totalWidth;
      uv.height = (float)height / totalHeight;


      info.index = index;
      info.uvBottomLeft = new Vector2(uv.xMin, uv.yMin);
      info.uvBottomRight = new Vector2(uv.xMax, uv.yMin);
      info.uvTopLeft = new Vector2(uv.xMin, uv.yMax);
      info.uvTopRight = new Vector2(uv.xMax, uv.yMax);
      info.minX = xOffset;
      info.maxX = xOffset + width;
      info.minY = -yOffset - height;
      info.maxY = -yOffset;
      info.advance = xAdvance;
      info.glyphWidth = width;
      info.glyphHeight = height;


      characterInfoList.Add(info);
    }
    font.characterInfo = characterInfoList.ToArray(typeof(CharacterInfo)) as CharacterInfo[];


    Debug.Log("生成成功.");
  }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

林州市| 遂川县| 富顺县| 贵德县| 宿松县| 枣庄市| 东丰县| 开远市| 巴彦淖尔市| 深泽县| 兰州市| 泗洪县| 固始县| 安国市| 饶阳县| 都匀市| 宜丰县| 巴林右旗| 邵武市| 中阳县| 霍山县| 东至县| 保亭| 库车县| 抚宁县| 凤台县| 平凉市| 三台县| 赫章县| 任丘市| 海伦市| 方山县| 沙雅县| 石嘴山市| 靖边县| 平原县| 巨野县| 藁城市| 红桥区| 罗源县| 西藏|