marijnz / unity-toolbar-extender Goto Github PK
View Code? Open in Web Editor NEWExtend the Unity Toolbar with your own Editor UI code.
License: MIT License
Extend the Unity Toolbar with your own Editor UI code.
License: MIT License
When switching to a different layout the button disappears, this is related to a known issue that Unity isn't worried about fixing.
Hey, I was thinking about different approach:
Sounds impossible, but it actually isn't.
To derive from Toolbar, you'll have to do it in IL, because it's internal. See attached IL file. You can ignore GameObjectEditor that's something else :)
I've also attached mockup of classes, which I compile and then disassemble into IL
UnityIL.Editor.il.txt
Mockup.cs.txt
There's internal ToolbarWrapper
and static class ToolbarExtension
which exposes callbacks and other useful methods (see mockups)
Create wrapper, copy all serialized properties, replace it
MainView.children[0]
is always Toolbar, just replace it
There's also Toolbar.get
(field surprisingly), which is probably a good idea to replace
ToolbarExtension.cs.txt
IL compilation command:
c:\Windows\Microsoft.NET\Framework\v2.0.50727\ilasm UnityIL.Editor.il /dll /OUTPUT=%~dp0UnityIL.Editor.dll
Simple case works, see screenshot below.
I've encountered some issues when switching layout (not sure why).
Done on Unity 2018.2.10f1
Hi, Unity just releases 2020.2.0f1,
and unfortunately your hack fails now, it seems that some modifications have changed in that UI.
(m_viewVisualTree is null now)
Do you think you can find a way to still find the toolbar ?
Your plugin is sooo helpful !
The UI debugger works with the toolbar, if that can help you:
Thank you^^
The IMGUI Container doesn't have flex grow, and thus "flexible space" doesn't work. All elements will left align.
Unity 2021.1.18f1, reproduced with scene selector sample.
The code should be working on any of the latest Unity releases, however some people note that only two grey boxes appear. https://www.reddit.com/r/Unity3D/comments/96zqv9/extend_the_unity_toolbar_with_your_own_editor_ui
I'm investigating if it's a Windows/Mac thing or other work system / setup related things.
I've noticed the following on https://openupm.com/packages/com.marijnzwemmer.unity-toolbar-extender/
#20 might fix it, or maybe a new release (possibly with bump to 1.3.1) might be required, I'm not familiar with how it works.
It properly draw GUI but it doesn't handle mouse events properly... drop-down doesn't open, etc.
In Unity 2020.1 UnityEditor.GUIView doesn't have a "visualTree" property animore. This results in a Null reference exception on line 46 in ToolbarCallback
Hello!
Windows allows you to change the scaling settings for a display by right-clicking the desktop and selecting "Display settings." It's possible to set different displays to different scales; for example, one monitor could have 100% scale, and another could have 150% scale.
If the main Unity Editor window is dragged from one monitor to another, and if the two monitors have different scaling settings in Windows, any custom content added to the toolbar using unity-toolbar-extender will disappear. It will reappear if Unity enters or exits Play Mode, if the Editor layout is changed, or if script compilation occurs.
It appears that changing the main editor's DPI causes the toolbar to be visually reset (which wipes out custom UI), but does not delete the toolbar's ScriptableObject (which is what unity-toolbar-extender checks to trigger re-adding the custom UI:
unity-toolbar-extender/Editor/ToolbarCallback.cs
Lines 47 to 48 in dbd76ed
I tried also re-adding the buttons in response to any change in Screen.dpi or EditorGUIUtility.pixelsPerPoint. This fixed the dragging issue if just one window was open, but it had a side effect: if the Editor had multiple windows open, and they were on different DPI windows, moving the mouse from one window to another would cause many duplicate copies of the custom UI to be added to the toolbar.
Can anyone confirm if it works in 2019.2 a13
It does not work for me.
It does work in 2018.3
GUILayout.FlexibleSpace() doesn't work.
Hi, love this asset!
Is there a way to force a repaint? to let's say show a timer.
I didn't find any. I can register a callback on EditorApplication.update
but I didn't find what to call..
I'm not sure how to do it but I would like to make 4 buttons for the different editor layouts so I can quickly switch between them.
Can you help me out?
It seems that the current way is to inject IMGUIContainer, maybe it would be possible to allow us to use just UIToolkit? It would make styling consistent with the existing UI a lot easier
Hey, I'm working on a fix for the buttons which seems to be off center in 2019. I'm following the same math in the Toolbar.cs file and I'll pull a new request afterwards.
I wanted to make sure that I was making it compatible with older version, so I wanted to ask if the position was calculated like this in 2018 and earlier:
float playButtonsPosition = (EditorGUIUtility.currentViewWidth - 100) / 2;
because now it's like the following:
float playButtonsPosition = Mathf.RoundToInt ((EditorGUIUtility.currentViewWidth - 140) / 2);
if it is, I'll use an #if and #else for the different versions, otherwise I'll just replace it :)
Hey! I just wanted to say that in the last LTS update 2021.3.0 LTS, the toolbar is shown, but it's "disabled", we can hover stuffs, tooltips are shown if any, but left or right click doesn't work on any buttons.
Thanks for the 2021 fix, I noticed the package.json verison is still at 1.4.1 which made me question if I got the update. Thanks!
It would be cool if the project would support the Unity Package Manager.
I have made a start to this in my fork if you wanted to check it out.
The only major thing is I removed the examples as the developer can't remove them if they want because packages are immutable. I'm not really sure how to handle that.
If you want to go down this route I can make a way to turn off examples so developer doesn't need to see them.
Thanks for this code, it is very handy :)
By taking advantage of UIElements, we can attach drawing handler right AFTER the toolbar.
This works well when resizing window and changing layouts. Tested on Unity 2018.2.10f1.
Implementation could be probably improved:
IMGUIContainer
try adding a new one (visualTree.Add
)using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEditor;
using System.Reflection;
using UnityEngine.Experimental.UIElements;
[InitializeOnLoad]
public static class ToolbarExtension
{
static Type m_toolbarType = typeof(Editor).Assembly.GetType("UnityEditor.Toolbar");
static Type m_guiViewType = typeof(Editor).Assembly.GetType("UnityEditor.GUIView");
static PropertyInfo m_viewVisualTree = m_guiViewType.GetInstanceProperty("visualTree");
static FieldInfo m_imguiContainerOnGui = typeof(IMGUIContainer).GetInstanceField("m_OnGUIHandler");
static ToolbarExtension()
{
EditorApplication.update -= OnUpdate;
EditorApplication.update += OnUpdate;
}
private static void OnUpdate()
{
// Find toolbar
var toolbar = (ScriptableObject)Resources.FindObjectsOfTypeAll(m_toolbarType).FirstOrDefault();
// Get it's visual tree
var visualTree = (VisualElement)m_viewVisualTree.GetValue(toolbar);
// Get first child which 'happens' to be toolbar IMGUIContainer
var container = (IMGUIContainer)visualTree.Children().First();
// Attach our handler
var handler = (Action)m_imguiContainerOnGui.GetValue(container);
handler -= OnGUI;
handler += OnGUI;
m_imguiContainerOnGui.SetValue(container, handler);
}
private static void OnGUI()
{
var buttonRect = new Rect(Screen.width / 2 + 50, 0, 100, 30);
buttonRect.y = 4;
if (GUI.Button(buttonRect, "TestButton"))
{
Debug.Log("Pressed");
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.