遇到問題
我們項目分兩個Unity的工程,Art(美術資源工程),Client(代碼工程)
在Art工程中的TextMeshProUGUI Text中使用Emoji,打包成AB之后,在Client運行時,spriteAsset的圖集是從Resource目錄讀取出來的
軟件環境
Unity3D 5.3.7p4
TextMesh Pro 1.0.555.0b11(Jul 06.2017)
KSFramework:https://github.com/mr-kelly/KSFramework
從Resource讀取SpriteAsset
TextMesh Pro的Resource目錄設置文件TMPSettings.asset 用於設置默認屬性,比如默認的字體,圖集
在Editor中運行,如果使用了Sprite標簽,它會從默認圖集中加載(Resource\xxspriteAsset.asset),比如我的設置文件
原理分析
當Text中使用了Sprite標簽時,在運行時,TextPro會生成兩個Gameobject:一個Text(渲染文字),SubMesh(渲染圖片)
從Assetbundle加載spriteAsset
分析實現原理之后,我們知道,運行時,SubMesh的SpriteAsset默認是從Resource加載出來的,所以我們要做的就是替換掉SubMesh中 SpriteAsset的圖片。
TextMeshPro的Text提供了一個接口方便我們替換掉這張圖片
Lua實現的偽代碼:
AssetFileLoader.Load("ui/spriteassets/emojidata.asset", function(isoK, result) if not isoK or result:IsNull() then return end for i, tmpText in ipairs(tmpTexts) do tmpText.spriteAsset = result local child = tmpText:GetComponentsInChildren(typeof(CS.TMPro.TMP_SubMeshUI),true) if child then child.spriteAsset = result end end end)
替換SpriteAsset后:
注意查看 SpriteAsset的值,變成從ab中加載了。
文檔資料
TextMesh Pro的資料,可以參考我之前的博客:http://www.cnblogs.com/zhaoqingqing/p/7471499.html
參考資料:http://digitalnativestudios.com/forum/index.php?topic=1018.msg8140#msg8140