【Unity3D ugui】使用藝術字
藝術字製作流程
1、下載BMFont官網
2、首先你還得有美術製作的藝術字,或者自己做幾個藝術字。好吧,全部奉上
3、使用BMFont製作藝術字圖集
4、將生成的.fnt檔案和圖集.png檔案匯入到專案中
5、你還得有NGUI的有關BMFont的程式碼,不知道在哪?已經全部奉上啦
6、製作CustomFont,按照教程來做挺累的,編輯器上場
using UnityEngine;
using UnityEditor;
public class BMFontEditor : EditorWindow
{
[MenuItem("Tools/BMFont Maker")]
static public void OpenBMFontMaker()
{
EditorWindow.GetWindow<BMFontEditor>(false, "BMFont Maker", true).Show();
}
[SerializeField]
private Font targetFont;
[SerializeField]
private TextAsset fntData;
[SerializeField]
private Material fontMaterial;
[SerializeField]
private Texture2D fontTexture;
private BMFont bmFont = new BMFont();
public BMFontEditor()
{
}
void OnGUI()
{
targetFont = EditorGUILayout.ObjectField("Target Font", targetFont, typeof(Font), false) as Font;
fntData = EditorGUILayout.ObjectField("Fnt Data", fntData, typeof(TextAsset), false) as TextAsset;
fontMaterial = EditorGUILayout.ObjectField("Font Material", fontMaterial, typeof(Material), false) as Material;
fontTexture = EditorGUILayout.ObjectField("Font Texture", fontTexture, typeof(Texture2D), false) as Texture2D;
if (GUILayout.Button("Create BMFont"))
{
BMFontReader.Load(bmFont, fntData.name, fntData.bytes); // 借用NGUI封裝的讀取類
CharacterInfo[] characterInfo = new CharacterInfo[bmFont.glyphs.Count];
for (int i = 0; i < bmFont.glyphs.Count; i++)
{
BMGlyph bmInfo = bmFont.glyphs[i];
CharacterInfo info = new CharacterInfo();
info.index = bmInfo.index;
info.uv.x = (float)bmInfo.x / (float)bmFont.texWidth;
info.uv.y = 1 - (float)bmInfo.y / (float)bmFont.texHeight;
info.uv.width = (float)bmInfo.width / (float)bmFont.texWidth;
info.uv.height = -1f * (float)bmInfo.height / (float)bmFont.texHeight;
info.vert.x = 0;
info.vert.y = -(float)bmInfo.height;
info.vert.width = (float)bmInfo.width;
info.vert.height = (float)bmInfo.height;
info.width = (float)bmInfo.advance;
characterInfo[i] = info;
}
targetFont.characterInfo = characterInfo;
if (fontMaterial)
{
fontMaterial.mainTexture = fontTexture;
}
targetFont.material = fontMaterial;
fontMaterial.shader = Shader.Find("UI/Default");//這一行很關鍵,如果用standard的shader,放到Android手機上,第一次載入會很慢
Debug.Log("create font <" + targetFont.name + "> success");
Close();
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
7、給Text指定字型和材質吧,材質用Sprites-Default,顏色就白色
最終效果
需要注意的問題
1、CustomFont用Standard材質,最終放到手機上,第一次載入會很慢,親測,小米3要3秒,紅米2要9秒。既然如此,那就用UI/Default吧,其他的可能也行,我就懶得一個一個測了。至於為什麼Standard會造成載入慢,容我思考思考
2、上面的Editor程式碼執行後,在Unity上能立刻看到效果,但是CustomFont的設定沒有立刻儲存,需要自己手動儲存。博主不才,不知道程式碼怎麼寫才能自動儲存設定。
3、如果單獨某個字顯示的位置不對,可以調整下字元Vertex的位置,比如上面效果圖中的“+”有點偏上了,可以把“Y”值調小一點。有興趣也可以研究下其他引數的含義。
版權宣告:本文為博主原創文章,未經博主允許不得轉載。
相關文章
- unity3d UGUI教程之-UGUI 實現刮刮卡橡皮擦Unity3DUGUI
- Canvas + WebGL中文藝術字渲染CanvasWeb
- Unity3D利用UGUI模擬《海島奇兵》收穫資源的爆炸效果Unity3DUGUI
- Art Text 4 for Mac(藝術字設計軟體)Mac
- 讓藝術在數字世界換髮生命力——umx.art和它的NFT藝術平臺
- 建立數字藏品藝術平臺需要哪些步驟
- AR技術在藝術展館中的使用效果
- 萬彩動畫大師教程 | 給文字新增藝術字效果動畫
- NFT數字藝術品交易平臺型別介紹型別
- 如何開發自己的NFT數字收藏藝術平臺
- 使用Shader進行UGUI的優化UGUI優化
- CSS奇思妙想 -- 使用 CSS 創造藝術CSS
- UGUI的深度UGUI
- UGUI動畫效果UGUI動畫
- 加密的藝術加密
- 控制檯列印類sqlmap啟動場景?Figlet藝術字SQL
- NFT生態藝術開發丨NFT數藏藝術丨NFT生態藝術系統開發技術
- 使用神經網路生成抽象隨機藝術神經網路抽象隨機
- 技術選型的藝術
- 華熙LIVE五棵松2021亞洲數字藝術展讓你體驗數字技術
- WPS 2007藝術字的實用操作技巧
- UGUI研究之SpriteUGUI
- 命令列的藝術命令列
- 授權的藝術
- 軟體藝術 (轉)
- 設計的藝術(二):遊戲與遊戲性與互動藝術遊戲
- 在矩池雲使用Disco Diffusion生成AI藝術圖AI
- 藝術家視角:什麼是加密數字資產NFT? - alex-pardee加密
- 深度構建“數字藝術” 看《夢幻西遊》如何落地“遊戲+文化”策略遊戲
- Art Text 4 Mac下載,藝術字、圖示設計製作工具Mac
- 798藝術數字藏品系統程式設計開發詳情分析程式設計
- 視覺爆炸的藝術 | 《地平線:黎明時分》藝術賞析視覺
- 遊戲“第九藝術”批判遊戲
- Java垃圾收集的藝術Java
- 分析:操縱的藝術
- 藝術與Web:形體Web
- Oracle效能診斷藝術Oracle
- UGUI全面實踐教程UGUI