using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class window_manager : MonoBehaviour
{
private bool isShow = false;
private Rect windowRect ;
private AudioSource audioSource;
private int marginLeft = 140;
private int marginTop = 70;
private int margin = 60;
private int width = 200;
private int height = 40;
// Start is called before the first frame update
void Start()
{
windowRect =new Rect(300, 280, 640, 600);
audioSource = GameObject.Find("Terrain").GetComponent<AudioSource>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape)) {
isShow = true;
}
}
void OnGUI() {
if (isShow) {
windowRect= GUI.Window(0, windowRect, WindowContain, "调试窗口");
}
}
void WindowContain(int id) {
Debug.Log("WindowContain isShow:" + isShow);
if (GUI.Button(new Rect(marginLeft, marginTop, width, height), "关闭音乐")) {
//audioSource.enable()=false;
audioSource.Stop();
isShow = false;
}
if (GUI.Button(new Rect(marginLeft, marginTop+margin, width, height), "播放音乐"))
{
audioSource.Play();
//audioSource.enable()=true;
isShow = false;
}
if (GUI.Button(new Rect(marginLeft, marginTop + margin*2, width, height), "关闭窗口"))
{
audioSource.Play();
//audioSource.enable()=true;
isShow = false;
}
if (GUI.Button(new Rect(marginLeft, marginTop + margin * 3, width, height), "退出游戏"))
{
isShow = false;
Application.Quit();
}
//允许拖拽 在此范围内
GUI.DragWindow(new Rect(0, 0, 1000, 1000));
}
}