#InspectorWindow & Editor instance
1 messages · Page 1 of 1 (latest)
@prisma crown @untold robin ah! found a solution!
Don't know how robust this is, but seems to do the trick
[CustomEditor(typeof(SomeMono))]
public class SomeMonoEditor : Editor
{
private void OnEnable()
{
EditorWindow ownerInspector = GetOwnerInspector();
if (ownerInspector == null)
{
Debug.Log($"Couldn't find owner inspector for SomeMonoEditor with ID {this.GetInstanceID()}. This happens when the owner inspector of an Editor instance is locked inspecting a different target object");
}
else
{
Debug.Log($"SomeMonoEditor ({this.GetInstanceID()}) owner inspector InstanceID: {ownerInspector.GetInstanceID()}");
Debug.Log($"SomeMonoEditor ({this.GetInstanceID()}) owner inspector rect: {ownerInspector.position}");
}
}
private EditorWindow GetOwnerInspector()
{
List<EditorWindow> inspectorsWindows = InspectorWindowAccessor.GetInspectors();
foreach (EditorWindow inspector in inspectorsWindows)
{
InspectorWindowAccessor accessor = new InspectorWindowAccessor(inspector);
ActiveEditorTracker tracker = accessor.Tracker;
for (int i = 0; i < tracker.activeEditors.Length; i++)
{
if (tracker.activeEditors[i].GetInstanceID() == this.GetInstanceID())
{
return inspector;
}
}
}
return null;
}
}
Will break if the editor is shown in a custom editor window
oh...
hmmm
yeah just tried it with an Editor in an EditorWindow by using CreateEditor
OnEnable doesn't get called
ah sorry, it gets called
it just doesn't find the "InspectorWindow" because there's none
Of course, as we said, Editor != Inspector
yeah 😅
I mean currently the tool that I'm making is just to check whether or not a vertical scrollbar exists in an Inspector
yeah I will check it out later
Check the guiview
ok brb
maybe this?
my knowledge of the whole View, GUIView, etc classes is very limited
so I'm a little bit lost
Strange... I know View contain the information somewhere of its window
I cant find it
View doesn't, HostView does though
And DockView
But it inherits from HostView
aaaaah probably why
Hell yeah
Thanks @untold robin for the reminder, I was lost into fucking View "the hell am I looking at O_o"
the View classes are a little bit obfuscated lmao
i had to make that example to remind myself of all of them
Haha no problem, I have been playing a lot with the View api recently
var GUIView = typeof(Editor).Assembly.GetType("UnityEditor.GUIView");
var current = GUIView.GetProperty("current", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
object currentView = current.GetValue(null);
var HostView = typeof(Editor).Assembly.GetType("UnityEditor.HostView");
var actualView = HostView.GetField("m_ActualView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
EditorWindow editorWindow = (EditorWindow)actualView.GetValue(currentView);
Try that @gleaming tiger
I got tired of reflection so I just made a wrapper class for each View class with the same inheritance so I can basically use them like they do internally. Saved me so much time and the code is so much cleaner
Yeah, got the utilities, but not here at this moment 😄
And obviously MadLed would not have them under his hand
In normal time I got this to fast prototype CSharpMeta.Resolve<Rect>(Resources.FindObjectsOfTypeAll<EditorWindow>()[0], "rootVisualContainer.worldClip");
hmm, error
ArgumentException: Field m_ActualView defined on type UnityEditor.HostView is not a field on the target object which is of type System.Reflection.MonoProperty.
i've never encountered this error, i don't even know how to interpret it
In his case I would simply call : CSharpMeta.Resolve<EditorWindow>("UnityEditor.GUIView.current.m_ActualView");
@prisma crown ah I'm dumb, I was getting the error on the Inspectors
not on the EditorWindow that has the created Editor
🙃 stupid brain
Both should work seamlessly
I mean, EditorWindow are in DockArea (inherit from HostView)
InspectorWindow I don't know who hosts it
i get a null value here ```cs
object currentView = current.GetValue(null);
Debug.Log($"currentView: {currentView.GetType()}");
with the Inspector
@prisma crown ah I know why
i was doing it on OnEnable
I guess the View is not fully initialized or something
I would have hope OnEnable would work as well
i guess I just make an initialization method and run it once on OnInspectorGUI
seems to work fine, and it's compatible with regular Editor instances and created Editor instances in EditorWindows
thanks a lot @prisma crown @untold robin !!! 😋
i would have struggled so much with this lol
🙏
@untold robin hey, would it be much to ask if you could share your wrapper classes for the View API stuff?
i just recently started learning about this topic and it's a little bit too cumbersome
I use a number of internal tools for it so it would be a bit difficult
It really is a bit of a pain. Its almost like they didn't design the API to be used by the other people
ah it's fine then, no worries. It can be a good learning experience to untangle this whole thing poking around anyways hehe
yeah, at this point I understand why they almost never improve basic quality of life stuff for a lot of the Unity editor features
it seems like there's so many messy APIs inside their internal code
Be carful when starting out because it is possible to do bad things - The guy who corrupted a whole Unity install version
💀 ouch
i'll keep it in mind
Yeah...
so far the only thing I want to learn how to do with the View API is to dock windows
the EditorWindow.GetWindow method has the desiredDockNextTo
but that just makes the window become a tab of the target, not dock
Something to keep in mind is that the position in View is the equivalent of the GUI API where the .position in EditorWindow is like the GUILayout API
So when positioning Views, you need to also update the position/size of the other views to accommodate it.
i see, thanks for the tip!
I can't give you all the code. But this is the bare minimum of how to split the inspector. Might be helpful.
https://gdl.space/yayuzavexi.php
god bless you!
🧙
it's so hard to find examples for this stuff so anything I can get is like a gift from the gods
Tbh I don't think I have seen anything on github or the asset store that uses the View API, I can't imagine why though... ( 😛 )