Unity - UIWidgets 4. 添加图标显示

十年热恋 提交于 2020-01-28 20:11:49

Material Icon字体下载(github)

前面的返回按钮, 以及自己试验的一些Icon都不显示, 然后回去翻UIWidgets的README

     public class UIWidgetsExample : UIWidgetsPanel {
         protected override void OnEnable() {
             // if you want to use your own font or font icons.
             // FontManager.instance.addFont(Resources.Load<Font>(path: "path to your font"), "font family name");

             // load custom font with weight & style. The font weight & style corresponds to fontWeight, fontStyle of
             // a TextStyle object
             // FontManager.instance.addFont(Resources.Load<Font>(path: "path to your font"), "Roboto", FontWeight.w500,
             //    FontStyle.italic);

             // add material icons, familyName must be "Material Icons"
             // FontManager.instance.addFont(Resources.Load<Font>(path: "path to material icons"), "Material Icons");

             base.OnEnable();
         }

emmm

下载字体放到Assets\Resources\Fonts
修改UI入口处

// UIMain.lua

using System.Collections.Generic;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.material;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;

namespace UI
{
    public class UIMain : UIWidgetsPanel
    {
        protected override void OnEnable()
        {
            FontManager.instance.addFont(Resources.Load<Font>(path: "Fonts/MaterialIcons-Regular"), "Material Icons");

            base.OnEnable();
        }

        // ...
    }
}

图标就可以正常显示了

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!