Closed marijnz closed 5 years ago
Yeah, I got that too. It went a bit further in my case and made Windows itself break in a very interesting way. As I reload over and over to try and modify this, eventually all icons on my taskbar would "open". I say "open" because they didn't really. It was the window handler for icon itself that suddenly got huge.
I skipped a beat the first time I saw dozens of windows opening at once, but quickly nailed down to the way this extension attaches itself to the window. I have a screenshot but since it opens so much stuff, there's too much info to share!
Under certain circumstances, it seems that getting the RootView and dealing with a UnityEditor.View results in Unity "bleeding out" whatever window you're trying to attach and, instead, attaching it randomly to something outside.
This is such an absurd thing that it is absurd even to type it. It's also so hard to reproduce that I restored a backup on my machine thinking I had broken Windows. After a while I found a way to trigger it immediately, but didn't play much more with it because the only way to revert what it was doing was to reboot.
In the end, I think it's best to "fake" attaching. Instead of actually playing with that internal stuff, you get the actual position of that region and display your window there. It's much safer. That's what I'm doing right now.
To do this, store the internal type UnityEditor.ContainerWindow
and do a Resources.FindObjectsOfTypeAll
on that type.
iterate each and query its internal method ShowMode
, which returns the internal enum *UnityEditor.ShowMode
(just cast the return value to int)
The main window is the one with showMode = UnityEditor.ShowMode.MainWindow
These are the current values of that enum
namespace UnityEditor
{
internal enum ShowMode
{
NormalWindow,
PopupMenu,
Utility,
NoShadow,
MainWindow,
AuxWindow,
PopupMenuWithKeyboardFocus,
}
}
With the MainWindow in your possession, you can attach your window to the EditorApplication.update
loop and position your editor window relative to the main window's position.
The MainWindow's y position begins just after the menu bar, so you just have to determine the x offsets considering the current width of the main window.
Hey,
that’s an interesting approach, let me try it out. It’s definitely less intrusive.
On 30. Aug 2018, at 17:47, SugoiDev notifications@github.com wrote:
The
I basically got it working. I only can't straight away find a way to show the window without any close/hide bar and without any shadow. There's the option NoShadow, which I tried but it has slightly weird behaviour.
Created a branch for it: https://github.com/marijnz/unity-toolbar-extender/tree/experimental_no_reparenting
Doesn't just window.ShowPopup()
in your window work?
So that's the best of options, but has the border black line and a slight shadow. Which kinda ruins it.
Ah, I think I understand. You need to draw over it with the style of that region.
You draw a rect
if (Event.current.type == EventType.Repaint) {
EditorGUI.DrawRect(new Rect(0F, 0F, this.position.width, this.position.height), bgColor)
}
where bgColor
is the color of that region on the screen (you'll probably want to use an if to draw for pro skin and normal skin). Then you can get it any color you want.
Look at it here, all solid and green
Hey, I this is how it then looks for me: (Yes colors are a bit off, but note the black border + slight shadows) On another note, one downside is that the buttons now disappear when having another application focused. Like this:
Colors I used just so you can try out:
Color backgroundColor = EditorGUIUtility.isProSkin
? new Color(1 * .16f, 1 * .16f, 1 * .16f)
: new Color(1 * .64f, 1 * .64f, 1 * .64f);
Ah, I think that's a mac thing!
I wonder if there's a solution?
I see that the m_parent
field (a HostView) has the RectOffset borderSize
internal
property, but it is readonly
, so you'll need to do borderSize.Remove(someRect)
instead of setting it to something.
Maybe you could try playing with that m_parent.borderSize
, then calling the internal
method window.MakeParentsSettingsMatchMe
(on your window) to "commit" the changes.
Set it to 0 to see what happens.
I don't have a mac around to test, so I'll be watching your progress here!
Hmm.. it's not the borderSize as this:
var parent = GetField(GetType(), "m_Parent").GetValue(this);
var prop = GetProperty(parent.GetType(), "borderSize");
RectOffset offset = (RectOffset) prop.GetValue(parent, null);
Debug.Log(offset);
returns:
RectOffset (l:0 r:0 t:0 b:0)
Damn.
I'm looking at the docs, and I can see the popups have a shadow. On Windows they don't. Maybe there's no way around this?
I'm not sure if there is.. no. And even then, the buttons disappearing when another window is focused above, also is not so nice. It distracts. Not sure if this is a way to go. Maybe one step back and see what goes wrong in the parenting. (and how maybe that can be simplified).
Yeah, I think so too.
I don't get the buttons disappearing on Windows either, so it seems there's a lot of non-trivial differences with those kind of windows between the two systems.
Did you ever solve this issue? I just downloaded the scripts and tried the examples, but Unity only shows gray boxes. If I click on them, nothing happens. Have tried restarting Unity and reverted back to factory layout settings.
Using Windows 10 and Unity 2018.1.1f1
No sadly not. There's small differences and it would cost me some time to dig into it (have to do it in a virtual box). If you feel adventurous, you're very welcome to play around and maybe discover the issue..
No problem. I don't think I'm qualified to do that, but I hope someone eventually will find a solution, since it's a really neat idea. Unity should allow custom shortcut buttons like this out of the box!
Hey, could any of you (@Wikzo @SugoiDev) try out https://github.com/marijnz/unity-toolbar-extender/tree/potential_windows_fix? In my VM it works, but often flickers.
Fixed in https://github.com/marijnz/unity-toolbar-extender/pull/7 which got merged to master. So closing this. @SugoiDev I see you already saw the other thread, you should be happy too! :)
@marijnz yup, looks nice! I didn't have the chance to play around with UI elements just yet, but looks like a general improvement compared to normal IMGUI we had until now.
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.