unity3d GUI字体设置

  1 using System.Collections;
  2 using System.Collections.Generic;
  3 using UnityEngine;
  4
  5 public class click001 : MonoBehaviour {
  6     public bool WindowShow = false;
  7     private Rect rect = new Rect(30, 40, 150, 150);
  8
  9     public Renderer rend;
 10
 11     public int fontSize;
 12     public FontStyle fontStyle;
 13     public RectOffset margin;
 14     public RectOffset padding;
 15     public Font font;
 16
 17
 18
 19     void Start()
 20     {
 21         //获取renderer组件
 22         rend = GetComponent<Renderer>();
 23     }
 24
 25
 26     void OnGUI()
 27     {
 28
 29         //窗口id  窗口大小  窗口回调(定义窗口内视图) 窗口标题
 30         if (WindowShow)
 31         {
 32             GUI.skin.window.font = font;
 33             GUI.skin.window.fontStyle = fontStyle;
 34             GUI.skin.window.fontSize = fontSize;
 35             GUI.skin.window.margin = margin;
 36             GUI.skin.window.padding = padding;
 37
 38             if (gameObject.tag == "pipe")
 39             {
 40                 GUI.Window(0, rect, onWindowOne, "管道");
 41             }
 42             else if(gameObject.tag == "stand")
 43             {
 44                 GUI.Window(1, rect, onWindowOne, "支架");
 45             }
 46             else if(gameObject.tag == "base")
 47             {
 48                 GUI.Window(2, rect, onWindowOne, "底座");
 49             }
 50             else if(gameObject.tag == "valve")
 51             {
 52                 GUI.Window(3, rect, onWindowOne, "阀门");
 53             }
 54         }
 55
 56     }
 57
 58
 59     void onWindowOne(int winId)
 60     {
 61
 62
 63         GUI.skin.label.font = font;
 64         GUI.skin.label.fontStyle = fontStyle;
 65         GUI.skin.label.fontSize = fontSize;
 66         GUI.skin.label.margin = margin;
 67         GUI.skin.label.padding = padding;
 68
 69         if (gameObject.tag == "pipe")
 70         {
 71             GUI.Label(new Rect(10, 10, 140, 40), "当前窗口是管道");
 72         }
 73         else if (gameObject.tag == "stand")
 74         {
 75             GUI.Label(new Rect(10, 10, 140, 40), "当前窗口是支架");
 76         }
 77         else if (gameObject.tag == "base")
 78         {
 79             GUI.Label(new Rect(10, 10, 140, 40), "当前窗口是底座");
 80         }
 81         else if (gameObject.tag == "valve")
 82         {
 83             GUI.Label(new Rect(10, 10, 140, 40), "当前窗口是阀门");
 84         }
 85
 86         GUI.skin.button.font = font;
 87         //GUI.Label(new Rect(10, 10, 140, 40), "当前窗口id是" + winId);
 88         if (GUI.Button(new Rect(10, 50, 80, 30), "按钮1"))
 89         {
 90             Debug.Log("当前窗口id" + winId);
 91         }
 92         //定义窗体可以活动的范围 这个功能不知道为什么没有实现
 93         //GUI.DragWindow(new Rect(0, 0, 10000, 10000));
 94     }
 95
 96     void OnMouseDown()
 97     {
 98         if (WindowShow)
 99         {
100             WindowShow = false;
101         }
102         else
103         {
104             WindowShow = true;
105         }
106
107     }
108 }

原文地址:https://www.cnblogs.com/caoxen/p/9504789.html

时间: 2024-08-09 15:18:01

unity3d GUI字体设置的相关文章

CFileDialog(文件夹对话框类)和CFontDialog(字体设置对话框类)的使用学习

CFileDialog(文件夹对话框类) 主要用于文件的保存,另存,打开,关闭等功能 功能“另存为”的实现: 1 void CTXTDlg::OnFileSaveas() 2 { 3 LPCTSTR szFilter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||"; //过滤器设置,注意格式 4 CFileDialog fd(FALSE,"txt",NULL,OFN_OVERWRITEPROMPT|OFN_PATHMUSTEXIST| /

Emacs Org-mode中英文字体设置

Emacs Org-mode中英文字体设置 Table of Contents 1. 缺省字体存在的问题 2. 解决方法 2.1. 环境说明 2.2. 思路和方法 2.3. emacs设置代码 2.4. 显示效果 1 缺省字体存在的问题 一直在找一款能随心所欲记笔记的软件,近期发现了Org-mode,试用之后感觉确实非常好用. 不过,org-mode缺省字体在绘制表格时存在一个问题:因为中英文字体宽度不同,表格无法对齐.如下图所示: 2 解决方法 2.1 环境说明 本机环境为Mac OS X.E

Ubuntu字体设置

Ubuntu所带的字体不是很好看,比较模糊,现修改为微软雅黑 Win7安装分区下的 \windows\fonts\文件夹下,复制msyh.ttf和msyhhd.ttf到/home/m/msfonts文件夹下(m为我的用户名). 第一种方法: 如果只想添加到当前用户下,拷贝到/home/m/.fonts目录下,重启x即可. 第二种方法: 将字体放入字体文件夹 sudo sumkdir /usr/share/fonts/msfontscd /usr/share/fonts/msfontscp /ho

unity3d web.config设置

原地址:http://www.cnblogs.com/88999660/archive/2013/03/22/2976105.html <?xml version="1.0"?> <!-- 有关如何配置 ASP.NET 应用程序的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=169433 --> <configuration> <system.web> <compilation de

Eclipse中的字体设置

Eclipse是java开发者使用最广泛的开发工具,作为一名初学者,感觉Eclipse能对java中许多不同的字段进行颜色划分的功能非常实用,于是对Eclipse中的字体稍微进行了研究. 常见进行字体调整的界面有三种,1.基本的字体设置:2.程序编写界面的颜色设置:3.java程序内特殊字的颜色设置. 1.基本的字体设置 Windous->Preferences->General->Appearance->Basic 基本字体的设置 常用Text Font->Edit(右侧)

SecureCRT学习之道:SecureCRT常用快捷键设置与字体设置方法

常用快捷键: 全屏View->Full Screen 快捷键 Alt + Enter 菜单View 快捷键 Alt + V 打开新的终端 快捷键 Alt + B 字体设置: options->global options->general->Default session-> Edit Defalut Settings 网上有人建议用fixedsys,这个字体虽然不是最美丽的,但在终端上也是一个不错选择,大家都可以接受. 选择它,主要是因为它大小固定,在所有地方显示,效果都一

Android 字体设置-Typeface讲解

控件的字体设置的两种方式 常用的字体类型名称还有: Typeface.DEFAULT //常规字体类型 Typeface.DEFAULT_BOLD //黑体字体类型 Typeface.MONOSPACE //等宽字体类型 Typeface.SANS_SERIF //sans serif字体类型 常用的字体风格名称还有: Typeface.BOLD //粗体 Typeface.BOLD_ITALIC //粗斜体 Typeface.ITALIC //斜体 Typeface.NORMAL //常规 1

SecureCRT学习之道:SecureCRT经常使用快捷键设置与字体设置方法

1:假设不想每次登陆都输入password,能够在你打开的session里邮件session option->login action 选中automate logon 双击ogin 和assword分别输入username和password即可了,telnet的命令符为〉,敲入指令的命令符为# 2:假设在global option->terminal->emulation->mapped keys勾选CUA setting就会导致Linux命令下快捷键ctrl+C失效,假设勾选就

VBA在WORD中给表格外的字体设置为标题

使用VB可以将表外的字体设置标题字体实际操作如下: VB代码如下: Sub oliver_1() Selection.EndKey Unit:=wdStory '光标移到文末 For i = 1 To ActiveDocument.Tables.Count '有几个表格,下面操作就循环几次 With Application.Browser .Target = wdBrowseTable '插入点在表格中 .Previous '插入点移至前一张表格之前 End With Selection.Mov