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
27
Editor/Toolbar/Utilities/Styles.cs
Normal file
27
Editor/Toolbar/Utilities/Styles.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Game.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
public sealed class Styles
|
||||
{
|
||||
public GUIStyle popup;
|
||||
public GUIStyle button;
|
||||
public GUIStyle slider;
|
||||
|
||||
private GUISkin skin;
|
||||
|
||||
public void Initialize(GUISkin skin)
|
||||
{
|
||||
if (this.skin == skin)
|
||||
return;
|
||||
|
||||
this.skin = skin;
|
||||
popup = skin.FindStyle("ToolbarPopup");
|
||||
button = skin.FindStyle("ToolbarButtonFlat");
|
||||
slider = skin.FindStyle("ToolbarSlider");
|
||||
|
||||
// Available: ToolbarBoldLabel, ToolbarBottom, ToolbarButtonLeft, ToolbarButtonRight, ToolbarDropDown,
|
||||
// ToolbarLabel, ToolbarTextField, ...
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Editor/Toolbar/Utilities/Styles.cs.meta
Normal file
3
Editor/Toolbar/Utilities/Styles.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 179c3a6025164e1f94a944b7b903dd23
|
||||
timeCreated: 1615459188
|
||||
84
Editor/Toolbar/Utilities/ToolbarUtility.cs
Normal file
84
Editor/Toolbar/Utilities/ToolbarUtility.cs
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
#if UNITY_2019_1_OR_NEWER
|
||||
using UnityEngine.UIElements;
|
||||
#else
|
||||
using UnityEngine.Experimental.UIElements;
|
||||
#endif
|
||||
|
||||
namespace Game.NavigationTool.Editor.Toolbar
|
||||
{
|
||||
internal static class ToolbarUtility
|
||||
{
|
||||
public static void AddGuiListener(Action action)
|
||||
{
|
||||
Assembly assembly = typeof(UnityEditor.Editor).Assembly;
|
||||
Type typeToolbar = assembly.GetType("UnityEditor.Toolbar");
|
||||
Object[] toolbars = Resources.FindObjectsOfTypeAll(typeToolbar);
|
||||
ScriptableObject so = toolbars.Length > 0 ? (ScriptableObject)toolbars[0] : null;
|
||||
|
||||
if (so == null)
|
||||
return;
|
||||
|
||||
Type typeGuiView = assembly.GetType("UnityEditor.GUIView");
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
Type typeWindowBackend = assembly.GetType("UnityEditor.IWindowBackend");
|
||||
PropertyInfo piWindowBackend = typeGuiView.GetProperty("windowBackend", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
PropertyInfo piVisualTree = typeWindowBackend.GetProperty("visualTree", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
#else
|
||||
PropertyInfo piVisualTree = typeGuiView.GetProperty("visualTree", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
#endif
|
||||
|
||||
if (piVisualTree == null)
|
||||
return;
|
||||
|
||||
FieldInfo fiImguiContainer = typeof(IMGUIContainer).GetField("m_OnGUIHandler", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
|
||||
if (fiImguiContainer == null)
|
||||
return;
|
||||
|
||||
#if UNITY_2020_1_OR_NEWER
|
||||
var windowBackend = piWindowBackend.GetValue(so);
|
||||
var visualTree = (VisualElement)piVisualTree.GetValue(windowBackend, null);
|
||||
#else
|
||||
var visualTree = (VisualElement)piVisualTree.GetValue(so, null);
|
||||
#endif
|
||||
|
||||
var container = (IMGUIContainer)visualTree[0];
|
||||
var handler = (Action)fiImguiContainer.GetValue(container);
|
||||
handler -= action;
|
||||
handler += action;
|
||||
fiImguiContainer.SetValue(container, handler);
|
||||
}
|
||||
|
||||
public static IToolbarDrawer[] GetAllDrawers()
|
||||
{
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
Type iType = typeof(IToolbarDrawer);
|
||||
|
||||
var list = new List<IToolbarDrawer>(8);
|
||||
|
||||
for (var i = 0; i < assemblies.Length; i++)
|
||||
{
|
||||
Assembly assembly = assemblies[i];
|
||||
Type[] types = assembly.GetTypes();
|
||||
|
||||
for (var j = 0; j < types.Length; j++)
|
||||
{
|
||||
Type type = types[j];
|
||||
|
||||
if (!type.IsAbstract && iType.IsAssignableFrom(type))
|
||||
list.Add((IToolbarDrawer)FormatterServices.GetUninitializedObject(type));
|
||||
}
|
||||
}
|
||||
|
||||
return list.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Toolbar/Utilities/ToolbarUtility.cs.meta
Normal file
11
Editor/Toolbar/Utilities/ToolbarUtility.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a557eb0c4731f0e4b93d7d9381f003c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue