0.6.0: Added ui layer and canvas picker
This commit is contained in:
parent
27d7ecb2dd
commit
169d11a2dd
|
|
@ -36,16 +36,17 @@ namespace Game.NavigationTool.Editor
|
|||
private static void OnGUI()
|
||||
{
|
||||
const float Y = 5.0f;
|
||||
const float SPACING = 8.0f;
|
||||
const float SPACING = 4.0f;
|
||||
const float HEIGHT = 22.0f;
|
||||
const float PLAY_BUTTON_EXTENT = 48.0f;
|
||||
const float PLAY_BUTTON_EXTENT = 75.0f;
|
||||
const float PLAY_BUTTON_OFFSET = -23.0f;
|
||||
|
||||
if (DRAWERS == null)
|
||||
return;
|
||||
|
||||
styles.Initialize(GUI.skin);
|
||||
float xLeft = EditorGUIUtility.currentViewWidth * 0.5f - PLAY_BUTTON_EXTENT;
|
||||
float xRight = EditorGUIUtility.currentViewWidth * 0.5f + PLAY_BUTTON_EXTENT;
|
||||
float xLeft = EditorGUIUtility.currentViewWidth * 0.5f + PLAY_BUTTON_OFFSET - PLAY_BUTTON_EXTENT;
|
||||
float xRight = EditorGUIUtility.currentViewWidth * 0.5f + PLAY_BUTTON_OFFSET + PLAY_BUTTON_EXTENT;
|
||||
|
||||
for (var i = 0; i < DRAWERS.Length; i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ using UnityEditor;
|
|||
|
||||
namespace Game.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal sealed class ToolbarPostProcess : AssetPostprocessor
|
||||
internal sealed class ToolScenePickerPostProcess : AssetPostprocessor
|
||||
{
|
||||
private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
|
||||
{
|
||||
|
|
@ -14,7 +14,7 @@ namespace Game.NavigationTool.Editor.Toolbar
|
|||
|
||||
private static bool HasChange(string[] assets)
|
||||
{
|
||||
return assets.Any(s => s.EndsWith(".unity"));
|
||||
return assets.Any(s => s.EndsWith(".unity")) || assets.Any(s => s.EndsWith("EditorBuildSettings.asset"));
|
||||
}
|
||||
}
|
||||
}
|
||||
98
Editor/Toolbar/Tools/ToolUICanvasPicker.cs
Normal file
98
Editor/Toolbar/Tools/ToolUICanvasPicker.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
using System.Collections.Generic;
|
||||
using Game.NavigationTool.Editor.Toolbar;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UTools = UnityEditor.Tools;
|
||||
|
||||
namespace Game.NavigationTool.Editor.Tools
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class ToolUICanvasPicker : IToolbarDrawer
|
||||
{
|
||||
public bool Visible => true;
|
||||
public bool Enabled => !EditorApplication.isPlayingOrWillChangePlaymode;
|
||||
public EToolbarPlacement Placement => EToolbarPlacement.Left;
|
||||
|
||||
private static bool IS_DIRTY = true;
|
||||
private static string[] OPTIONS = new string[0];
|
||||
private static int[] INSTANCE_IDS = new int[0];
|
||||
|
||||
private void Initialize()
|
||||
{
|
||||
if (!IS_DIRTY)
|
||||
return;
|
||||
|
||||
Canvas[] canvases = Object.FindObjectsOfType<Canvas>();
|
||||
var list = new List<Canvas>(canvases.Length);
|
||||
var listNames = new List<string>(canvases.Length);
|
||||
var listIds = new List<int>(canvases.Length);
|
||||
|
||||
listNames.Add("Select");
|
||||
listIds.Add(-1);
|
||||
|
||||
for (var i = 0; i < canvases.Length; i++)
|
||||
{
|
||||
Canvas root = canvases[i].rootCanvas;
|
||||
|
||||
if (list.Contains(root))
|
||||
continue;
|
||||
|
||||
list.Add(root);
|
||||
listNames.Add(root.name);
|
||||
listIds.Add(root.GetInstanceID());
|
||||
}
|
||||
|
||||
OPTIONS = listNames.ToArray();
|
||||
INSTANCE_IDS = listIds.ToArray();
|
||||
IS_DIRTY = false;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public void Draw(Rect rect, Styles styles)
|
||||
{
|
||||
Initialize();
|
||||
int temp = EditorGUI.Popup(rect, 0, OPTIONS, styles.popup);
|
||||
|
||||
if (temp != 0 && OPTIONS.Length != 1)
|
||||
Focus(INSTANCE_IDS[temp]);
|
||||
}
|
||||
|
||||
public float CalculateWidth()
|
||||
{
|
||||
return 100.0f;
|
||||
}
|
||||
|
||||
private static void Focus(int instanceId)
|
||||
{
|
||||
var canvas = EditorUtility.InstanceIDToObject(instanceId) as Canvas;
|
||||
|
||||
if (canvas == null)
|
||||
return;
|
||||
|
||||
Selection.activeObject = canvas;
|
||||
Bounds bounds = InternalEditorUtility.CalculateSelectionBounds(false, true, true);
|
||||
Vector3 point = bounds.center;
|
||||
Quaternion direction = canvas.transform.rotation;
|
||||
float size = Mathf.Max(bounds.extents.x, bounds.extents.y);
|
||||
bool ortho = canvas.renderMode == RenderMode.ScreenSpaceOverlay;
|
||||
|
||||
for (var i = 0; i < SceneView.sceneViews.Count; i++)
|
||||
{
|
||||
var view = (SceneView)SceneView.sceneViews[i];
|
||||
view.in2DMode = false;
|
||||
view.LookAt(point, direction, size, ortho, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetAsDirty()
|
||||
{
|
||||
IS_DIRTY = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Toolbar/Tools/ToolUICanvasPicker.cs.meta
Normal file
3
Editor/Toolbar/Tools/ToolUICanvasPicker.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 43fccdd423a34d8f9505996a9102888f
|
||||
timeCreated: 1615549429
|
||||
35
Editor/Toolbar/Tools/ToolUICanvasPickerPostProcess.cs
Normal file
35
Editor/Toolbar/Tools/ToolUICanvasPickerPostProcess.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
using Game.NavigationTool.Editor.Tools;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Game.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal static class ToolUICanvasPickerPostProcess
|
||||
{
|
||||
static ToolUICanvasPickerPostProcess()
|
||||
{
|
||||
EditorSceneManager.sceneSaved -= OnSceneSaved;
|
||||
EditorSceneManager.sceneOpened -= OnSceneOpened;
|
||||
EditorSceneManager.sceneClosed -= OnSceneClosed;
|
||||
|
||||
EditorSceneManager.sceneSaved += OnSceneSaved;
|
||||
EditorSceneManager.sceneOpened += OnSceneOpened;
|
||||
EditorSceneManager.sceneClosed += OnSceneClosed;
|
||||
}
|
||||
|
||||
private static void OnSceneSaved(Scene scene)
|
||||
{
|
||||
ToolUICanvasPicker.SetAsDirty();
|
||||
}
|
||||
|
||||
private static void OnSceneOpened(Scene scene, OpenSceneMode mode)
|
||||
{
|
||||
ToolUICanvasPicker.SetAsDirty();
|
||||
}
|
||||
|
||||
private static void OnSceneClosed(Scene scene)
|
||||
{
|
||||
ToolUICanvasPicker.SetAsDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 19979bf45bee4bad9f060e404dac726e
|
||||
timeCreated: 1615563991
|
||||
47
Editor/Toolbar/Tools/ToolUILayerToggle.cs
Normal file
47
Editor/Toolbar/Tools/ToolUILayerToggle.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using Game.NavigationTool.Editor.Toolbar;
|
||||
using JetBrains.Annotations;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UTools = UnityEditor.Tools;
|
||||
|
||||
namespace Game.NavigationTool.Editor.Tools
|
||||
{
|
||||
[UsedImplicitly]
|
||||
internal sealed class ToolUILayerToggle : IToolbarDrawer
|
||||
{
|
||||
public bool Visible => true;
|
||||
public bool Enabled => !EditorApplication.isPlayingOrWillChangePlaymode;
|
||||
public EToolbarPlacement Placement => EToolbarPlacement.Left;
|
||||
|
||||
public void Update()
|
||||
{
|
||||
}
|
||||
|
||||
public void Draw(Rect rect, Styles styles)
|
||||
{
|
||||
int layer = 1 << LayerMask.NameToLayer("UI");
|
||||
bool value = (UTools.visibleLayers & layer) != 0;
|
||||
bool temp = EditorGUI.Toggle(rect, value, styles.button);
|
||||
GUI.Label(rect, "UI", styles.labelCenter);
|
||||
|
||||
if (temp == value)
|
||||
return;
|
||||
|
||||
if (temp)
|
||||
{
|
||||
UTools.visibleLayers |= layer;
|
||||
SceneView.RepaintAll();
|
||||
}
|
||||
else
|
||||
{
|
||||
UTools.visibleLayers &= ~layer;
|
||||
SceneView.RepaintAll();
|
||||
}
|
||||
}
|
||||
|
||||
public float CalculateWidth()
|
||||
{
|
||||
return 30.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Toolbar/Tools/ToolUILayerToggle.cs.meta
Normal file
3
Editor/Toolbar/Tools/ToolUILayerToggle.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 067b241abe324f7ead0fb8c076f89f5e
|
||||
timeCreated: 1615550968
|
||||
|
|
@ -7,6 +7,8 @@ namespace Game.NavigationTool.Editor.Toolbar
|
|||
public GUIStyle popup;
|
||||
public GUIStyle button;
|
||||
public GUIStyle slider;
|
||||
public GUIStyle label;
|
||||
public GUIStyle labelCenter;
|
||||
|
||||
private GUISkin skin;
|
||||
|
||||
|
|
@ -17,8 +19,11 @@ namespace Game.NavigationTool.Editor.Toolbar
|
|||
|
||||
this.skin = skin;
|
||||
popup = skin.FindStyle("ToolbarPopup");
|
||||
button = skin.FindStyle("ToolbarButtonFlat");
|
||||
button = skin.FindStyle("toolbarbutton");
|
||||
slider = skin.FindStyle("ToolbarSlider");
|
||||
label = skin.FindStyle("ToolbarLabel");
|
||||
labelCenter = skin.FindStyle("ToolbarLabel");
|
||||
labelCenter.alignment = TextAnchor.MiddleCenter;
|
||||
|
||||
// Available: ToolbarBoldLabel, ToolbarBottom, ToolbarButtonLeft, ToolbarButtonRight, ToolbarDropDown,
|
||||
// ToolbarLabel, ToolbarTextField, ...
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "com.module.navigationtool",
|
||||
"version": "0.5.0",
|
||||
"version": "0.6.0",
|
||||
"displayName": "Module.NavigationTool",
|
||||
"description": "Support for navigation tools, like favorites, history and toolbars",
|
||||
"unity": "2019.2",
|
||||
|
|
|
|||
Loading…
Reference in a new issue