private void AddUIEditorButton() { string title = "UI Layer"; string tooltip = "只显示UI Layer\r\n便于编辑UI"; ViewExpandUtils.AddToggleButton(ref m_SceneExpandItems , title , tooltip , (toggled) => { //Debug.Log(Tools.visibleLayers); //Tools.visibleLayers值的计算方式 //Debug.Log((1 << LayerMask.NameToLayer("UI")) | (1 << LayerMask.NameToLayer("Default"))); //下面这个层不存在的话会返回Int的最小值-2147483648 //Debug.Log((1 << LayerMask.NameToLayer("NGUI"))); SceneView view = SceneView.currentDrawingSceneView; if (toggled) { m_PlayerLayer = EditorPrefs.GetInt("VisibleLayers"); //需要根据工程Layer设定更改要打开的层级名 Tools.visibleLayers = 1 << LayerMask.NameToLayer("UI"); view.in2DMode = true; Transform target = GameObject.Find("Canvas").transform; view.LookAt(target.position); view.size = 500; } else { Tools.visibleLayers = m_PlayerLayer; view.in2DMode = false; view.size = 1; } } , GUILayout.Width(60)); }
/// <summary> /// 添加Recent Scene下拉菜单 /// </summary> private void AddRecentButton() { string title = "Recent"; string tooltip = "快速切换历史Scene\r\n至多可储存5个历史Scene"; ViewExpandUtils.AddCustom(ref m_SceneExpandItems , () => { GUIContent contentRecent = new GUIContent(title, tooltip); GUIStyle styleRecent = EditorStyles.toolbarDropDown; Rect rect = GUILayoutUtility.GetRect(contentRecent, styleRecent, GUILayout.Width(60)); if (GUI.Button(rect, contentRecent, styleRecent)) { EditorUtility.DisplayCustomMenu(rect, SceneDisplayOptions, -1, OnRecentMenuSelected, null); } }); }
/// <summary> /// 添加启动游戏菜单(无论当前是哪个场景只要BuildSettings里添加过场景就会自动切换到第0个场景并启动游戏) /// </summary> private void AddStartGameButton() { string title = "StartGame"; string tooltip = "快速启动游戏\r\n无论你现在在编辑哪个Scene"; ViewExpandUtils.AddPushButton(ref m_SceneExpandItems , title , tooltip , () => { if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) { EditorBuildSettingsScene[] sceneInBuilderSettings = EditorBuildSettings.scenes; if (sceneInBuilderSettings.Length > 0 && !string.IsNullOrEmpty(sceneInBuilderSettings[0].path)) { EditorSceneManager.OpenScene(sceneInBuilderSettings[0].path); } EditorApplication.isPlaying = true; } }, GUILayout.Width(70)); }
private void AddSpace() { ViewExpandUtils.AddSpace(ref m_SceneExpandItems, 6); }