励普教育在线培训
全国统一学习专线 8:30-21:00
位置:尚训网 > 培训 > 动态 > 游戏程序开发培训-地址  正文

游戏程序开发培训-地址

2023-05-24 14:26:46来源:互联网

最近这段时间总有小伙伴问小编游戏程序开发培训-地址是什么,小编为此在网上搜寻了一些有关于游戏程序开发培训-地址的知识送给大家,希望能解答各位小伙伴的疑惑。


(资料图片)

相关知识点:Unity中咱们经常对字体做Create Editable Copy,虽然已经非常方便了,但是实际使用场景中,有时候会有不方便的地方。
我们经常对同一个字体做不同字体大小的Copy,这个时候,每次都去修改font的属性,非常之蛋疼。
本地化翻译文件导出的文字需要手工加到字体属性中,如果同一个字体还有不同大小,更蛋疼了。
以上你都可以忍了,但是你再次Create Editable Copy之后,你发现场景中已经使用了改字体的Text组件全显示Miss Font
已经不能忍了……
咱们脚本搞定这事,具体实现后效果
1. 用配置文件指明需要使用的font name,font size,导出的字符集内容
2. 根据配置文件Create Editable Copy,同时确保场景中已存在的组件不丢失字体
using UnityEditor using UnityEngine
using UnityEngine
using System
using System
using System
public? class CreateEditableCopyFont
{
? [MenuItem ()]
? static void CreateFont ()
? {
? TextAsset sourceTextAsset=null
? try {
? sourceTextAsset=(TextAsset)Selection
? } catch (InvalidCastException e) {
? Debug ( + Environment + e)
? }
? if (sourceTextAsset==null) {
? EditorUtility (, , )
? return
? }
? int targetFontSize
? string sourceFontPath, targetFontPath, targetFontCharacters=
? try {
? string sourceConfigPath=AssetDatabase (Selection)
? string[] sourceConfigInfos=sourceTextAsset ()
? string headInfo=sourceConfigInfos []
? string[] headInfos=headInfo ()
? sourceFontPath=headInfos [] () []
? targetFontPath=sourceConfigPath (, )
? targetFontSize=int (headInfos [] () [])
? for (int i=
? targetFontCharacters +=sourceConfigInfos [i]
? }
? } catch (Exception ex) {
? EditorUtility (, , )
? return
? }
? // 重新生成字体文件会导致场景中已存在的丢失,
? // 所以需要生成后再次赋值
? string[] targetFontPathInfos=targetFontPath ()
? string textCheckName=targetFontPathInfos [targetFontPathInfos – ]
? List listTexts=new List ()
? foreach (Text text UnityEngine(typeof(Text))) {
? if (text==textCheckName) {
? listTexts (text)
? }
? }
? UnityEngine f=AssetDatabase (sourceFontPath)
? string path=AssetDatabase (f)
? TrueTypeFontImporter fontImporter=AssetImporter (path) as TrueTypeFontImporter
? fontImporter=FontTextureCase
? fontImporter=targetFontCharacters
? fontImporter=targetFontSize
? fontImporter ()
? AssetDatabase ()
? Font font=fontImporter (targetFontPath)
? foreach (Text item listTexts) {
? item=font
? }
? // 还原ttf设置
? fontImporter=FontTextureCase
? fontImporter ()
? AssetDatabase ()
? System ()
? }
}
impact_40.txt
name=Assets/HEGameLib/Examples/Fonts/impact.ttf,size=
abcdefg, you want export.
注意,配置文件我弄的很简单,第一行是使用的原字体和大小,第二行开始是你的需要导出的字符集。
将该文件放到你需要生成字体的目录,比如:Assets/GameAssets/Fonts/ 下。
右键第二步中放入的配置文件,在弹出菜单中点击 Create Editable Copy Font
该目录下会生成所需字体。
再次生成该字体,场景中已存在的字体不会丢失。好了,本篇unity3d教程到此结束,下篇我们再会!

相关内容:游戏程序开发培训

同类文章