zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    SpringMVC文件上传
    c函数调用过程原理及函数栈帧分析
    《C++游戏开发》笔记十一 平滑动画:不再颤抖的小雪花
    Java学习笔记——IO操作之以图片地址下载图片
    uva 400 Unix ls 文件输出排版 排序题
    【VC++积累】之八、PreTranslageMessage;TranslageMessage;GetMessage和PeekMessage的区别
    uva 331 Mapping the Swaps 求交换排序的map 纯DFS
    uva 10344 23 out of 5 凑运算结果 全排列+dfs
    Java学习笔记——File类文件管理及IO读写、复制操作
    uva 301 Transportation 铁路公司的阳谋 纯dfs暴力
  • 原文地址:https://www.cnblogs.com/caoxen/p/9504789.html
Copyright © 2011-2022 走看看