0.5.0: Added toolbar with scene picker
This commit is contained in:
parent
d35a79faf1
commit
27d7ecb2dd
19 changed files with 365 additions and 3 deletions
78
Editor/Toolbar/ToolbarDrawer.cs
Normal file
78
Editor/Toolbar/ToolbarDrawer.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
using Game.NavigationTool.Editor.Toolbar;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.NavigationTool.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
internal static class ToolbarDrawer
|
||||
{
|
||||
private static bool IS_INITIALIZED;
|
||||
private static IToolbarDrawer[] DRAWERS;
|
||||
private static Styles styles;
|
||||
|
||||
static ToolbarDrawer()
|
||||
{
|
||||
EditorApplication.update -= OnEditorUpdate;
|
||||
EditorApplication.update += OnEditorUpdate;
|
||||
}
|
||||
|
||||
private static void OnEditorUpdate()
|
||||
{
|
||||
if (!IS_INITIALIZED)
|
||||
{
|
||||
styles = new Styles();
|
||||
DRAWERS = ToolbarUtility.GetAllDrawers();
|
||||
ToolbarUtility.AddGuiListener(OnGUI);
|
||||
IS_INITIALIZED = true;
|
||||
}
|
||||
|
||||
for (var i = 0; i < DRAWERS.Length; i++)
|
||||
{
|
||||
DRAWERS[i].Update();
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnGUI()
|
||||
{
|
||||
const float Y = 5.0f;
|
||||
const float SPACING = 8.0f;
|
||||
const float HEIGHT = 22.0f;
|
||||
const float PLAY_BUTTON_EXTENT = 48.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;
|
||||
|
||||
for (var i = 0; i < DRAWERS.Length; i++)
|
||||
{
|
||||
IToolbarDrawer drawer = DRAWERS[i];
|
||||
|
||||
if (!drawer.Visible)
|
||||
continue;
|
||||
|
||||
GUI.enabled = drawer.Enabled;
|
||||
float width = drawer.CalculateWidth();
|
||||
Rect rect;
|
||||
|
||||
if (drawer.Placement == EToolbarPlacement.Left)
|
||||
{
|
||||
rect = new Rect(xLeft - width, Y, width, HEIGHT);
|
||||
xLeft -= width + SPACING;
|
||||
}
|
||||
else
|
||||
{
|
||||
rect = new Rect(xRight, Y, width, HEIGHT);
|
||||
xRight += width + SPACING;
|
||||
}
|
||||
|
||||
drawer.Draw(rect, styles);
|
||||
}
|
||||
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue