- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class click001 : MonoBehaviour {
- public bool WindowShow = false;
- private Rect rect = new Rect(30, 40, 150, 150);
- public Renderer rend;
- public int fontSize;
- public FontStyle fontStyle;
- public RectOffset margin;
- public RectOffset padding;
- public Font font;
- void Start()
- {
- // 获取 renderer 组件
- rend = GetComponent<Renderer>();
- }
- void OnGUI()
- {
- // 窗口 id 窗口大小 窗口回调 (定义窗口内视图) 窗口标题
- if (WindowShow)
- {
- GUI.skin.window.font = font;
- GUI.skin.window.fontStyle = fontStyle;
- GUI.skin.window.fontSize = fontSize;
- GUI.skin.window.margin = margin;
- GUI.skin.window.padding = padding;
- if (gameObject.tag == "pipe")
- {
- GUI.Window(0, rect, onWindowOne, "管道");
- }
- else if(gameObject.tag == "stand")
- {
- GUI.Window(1, rect, onWindowOne, "支架");
- }
- else if(gameObject.tag == "base")
- {
- GUI.Window(2, rect, onWindowOne, "底座");
- }
- else if(gameObject.tag == "valve")
- {
- GUI.Window(3, rect, onWindowOne, "阀门");
- }
- }
- }
- void onWindowOne(int winId)
- {
- GUI.skin.label.font = font;
- GUI.skin.label.fontStyle = fontStyle;
- GUI.skin.label.fontSize = fontSize;
- GUI.skin.label.margin = margin;
- GUI.skin.label.padding = padding;
- if (gameObject.tag == "pipe")
- {
- GUI.Label(new Rect(10, 10, 140, 40), "当前窗口是管道");
- }
- else if (gameObject.tag == "stand")
- {
- GUI.Label(new Rect(10, 10, 140, 40), "当前窗口是支架");
- }
- else if (gameObject.tag == "base")
- {
- GUI.Label(new Rect(10, 10, 140, 40), "当前窗口是底座");
- }
- else if (gameObject.tag == "valve")
- {
- GUI.Label(new Rect(10, 10, 140, 40), "当前窗口是阀门");
- }
- GUI.skin.button.font = font;
- //GUI.Label(new Rect(10, 10, 140, 40), "当前窗口 id 是" + winId);
- if (GUI.Button(new Rect(10, 50, 80, 30), "按钮 1"))
- {
- Debug.Log("当前窗口 id" + winId);
- }
- // 定义窗体可以活动的范围 这个功能不知道为什么没有实现
- //GUI.DragWindow(new Rect(0, 0, 10000, 10000));
- }
- void OnMouseDown()
- {
- if (WindowShow)
- {
- WindowShow = false;
- }
- else
- {
- WindowShow = true;
- }
- }
- }
来源: http://www.bubuko.com/infodetail-2734902.html