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-10-18 00:54:15