unity3d GUI字體設置
阿新 • • 發佈:2018-08-20
renderer fse 窗口 視圖 log and 回調 範圍 閥門
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; 12public 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; 36GUI.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 }
unity3d GUI字體設置