- Home /
The ‘ContextClick’ event of the ‘TreeView’ class does not fire from a custom inspector; but if you do it from an editor window it fires.
Hi, Im working in MacOs.
In both cases it is implemented in the same way (editor window and custom inspector). From the custom inspector you can see that the event is only fired when you press inside the red area, this rect is obtained using EditorGUILayout.GetControlRect.
If the TreeView rect is calculated using the same function, the event is fired. Another curious thing is that the event is fired in the custom inspector if you press ’Ctrl + Left Click’, but not when you do it with the right click.
The drawback is that I am obliged to calculate the rects manually, since the inspectors that I usually implement are for tools that we use in my work and are quite complex, therefore I need to have more control over how each one behaves, that is why I am not using the automatic layout functions provided by Unity.
I would like to know what mistake I am making, or what it does internally, ‘EditorGUILayout.GetControlRect ’so that when using it if the event works, since I have been researching this for a long time and I can't find a solution.
It should be mentioned that this also happens in the TreeView examples provided from the Unity manual.
I attach a Unity package with the examples described above.
Im using the Unity Version: 2018.4.16f1
Thanks in advance!
You can see in the console when the event is fired.
Reproduction steps:
Click on Assets/ExampleScriptableObject in the Project Window
Right click in any item outside the red rectangle - The ContextClick event isn’t fired - Note that the tree view is unfocused too
Right click in any item inside the red rectangle - The ContextClick event is fired
‘Ctrl + Left Click’ in any item inside or outside de red rectangle - The ContextClick event is fired
Click on Window/Example in the Window menu
Right click in any item - The ContextClick event is fired
‘Ctrl + Left Click’ in any item - The ContextClick event is fired
[1]: /storage/temp/156750-treeview-contextclickunitypackage.zip