TransWikia.com

Detecting the mouse releasing focus from Inspector in Unity

Stack Overflow Asked by Elighne on February 13, 2021

Do you see how, after editing a value on -say- an image asset and then clicking anywhere outside without first clicking on apply, makes a window appear to ask you if you want to save or discard changes?

So, I wanted to do pretty much that from an OnGUI() or OnSceneGUI(), and right after starting to write the MyClassEditor : Editor realized that I not only knew how to accomplish such a thing; but apparently I didn’t even know where to start searching on how to detect the mouse "entering" or "leaving" anything in the UI… if even possible.

This is what i found first when googling "detect mouse leaving inspector unity", and well as far as i understood, it is about detecting the edge of the screen boundaries, and the game window boundaries. So I went over the next result, which now looks promising at the beggining since it seems to describe my issue, but that is misleading since that solution applies to detect the mouse inside the scene view without loosing focus of the UI.. and i want to detect the focus lost so i head back to google only to stumble with a couple (more like several tbh) more of similar cases (like the unity reference to Monobehaviour.OnMouseEnter/Exit).

Which probably shows how lost I am, and I don’t mean to ask for anything solved, but maybe a little push in the right direction will do? I appreciate every little help.

Edit:
So I tried this inside a [CustomEditor(typeof(MyClass))] public class MyClassEditor : Editor:

public override void OnInspectorGUI()
        {
            Event e = Event.current;

            switch (e.type)
            {
                case EventType.MouseDown:
                    Debug.Log("mouse down");
                    break;
                case EventType.MouseEnterWindow:
                    Debug.Log("mouse left a window");
                    break;
                case EventType.MouseLeaveWindow:
                    Debug.Log("mouse entered a window");
                    break;
                default:
                    break;
            }

            base.OnInspectorGUI();

            var click = GUILayout.Button("Quick Fill");

            if (click)
            {
                MyClassEditorWindow.Open((MyClass)target);
            }   
        }

and even when the button works and the [mouse down] fires (only when clicking on top of what i think would be UIElements(?), tho -but not outside them, on the empty inspector area-),the other two ones don’t seem to be firing… pretty sure im doing more than one thing wrong, not a clue of what of all.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP