using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[ExecuteInEditMode]
public class Menu : MonoBehaviour {
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown("m"))
Debug.Log("menu");
}
}
首先,Update功能不在场景视图中调用。 第二,我如何在开始或其他情况下添加一个盒子菜单?例如:
GUILayout.Window(0, new Rect(10, 10, 100, 100), (id)=> {
GUILayout.Button("A Button");
},
答案 0 :(得分:0)
解决方案:
using UnityEditor;
using UnityEngine;
public class SceneGUI : EditorWindow
{
[MenuItem("Window/Scene GUI/Enable")]
public static void Enable()
{
SceneView.onSceneGUIDelegate += OnScene;
Debug.Log("Scene GUI : Enabled");
}
[MenuItem("Window/Scene GUI/Disable")]
public static void Disable()
{
SceneView.onSceneGUIDelegate -= OnScene;
Debug.Log("Scene GUI : Disabled");
}
private static void OnScene(SceneView sceneview)
{
Handles.BeginGUI();
if (GUILayout.Button("Destroy Objects", GUILayout.Width(100), GUILayout.Height(100)))
{
}
Handles.EndGUI();
}
}