分享

Unity修改GUI字体

 罘罳_图书馆 2018-09-18

参考文章:

Unity3D修改Font字体

Unity GUI设置字体大小



1、用GUIStyle来设置字体样式

  1. <pre name="code" class="csharp"><pre name="code" class="csharp">void OnGUI()  
  2.     {  
  3.         GUIStyle fontStyle = new GUIStyle();  
  4.         fontStyle.normal.background = null;    //设置背景填充  
  5.         fontStyle.normal.textColor= new Color(1,0,0);   //设置字体颜色  
  6.         fontStyle.fontSize = 40;       //字体大小  
  7.         GUI.Label(new Rect(0, 0, 200, 200), "Hello Font", fontStyle);  
  8.     }  

2、用GUI.skin更换字体(例如楷体)

  1. var customFont : Font;
  2. function OnGUI()
  3. {
  4. // 后面的color为 RGBA的格式,支持alpha,取值范围为浮点数: 0 - 1.0
  5. GUI.skin.label.normal.textColor = Color( 0, 255.0/255, 0, 1.0 );
  6. GUI.skin.label.font = customFont;
  7. // 显示文字
  8. GUI.Label( Rect(0,100,100,100), "show text" );
  9. }
根据需要先在inspector面板修改字体ttf文件的属性,例如字体大小等,然后将Assert中的字体拖入customFont变量则可替换字体。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约