Left Click Up Event in Editor

The EventType.MouseUp type of event only seems to call if I click on a handle. This only seems to happen for the left mouse button. (like after clicking an object and I also happen to have the mouse over the Movement x-axis handle, the event is called)

This is different from if I click the right mouse button, which seems to call the MouseUp event every time the right mouse is clicked.

I'm wondering how to fix this so the MouseUp event is called every time I click the left mouse; like the right mouse button.

http://answers.unity3d.com/questions/9898/making-a-tilemap-editor-within-the-unity-editor

The answer to that question seems to be an answer for me but I'm having problems understanding it if anybody can explain it to me, it being in boo makes it harder for me to understand.

This is what I played with to know when the events are called:

void OnSceneGUI()
    {
        if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
        {
          Debug.Log("Left-Mouse Down");
        }
        if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
        {
          Debug.Log("Left-Mouse Up");
        }
        if (Event.current.type == EventType.MouseUp && Event.current.button == 1)
        {
          Debug.Log("Right-Click Up");
        }
    }

Try it this way and you should be able to access all the clicks you want:

void OnSceneGUI (){

	Event e = Event.current;
	int controlID = GUIUtility.GetControlID (FocusType.Passive);

	switch (e.GetTypeForControl (controlID)) {

	case EventType.MouseDown:
		GUIUtility.hotControl = controlID;
	
		CheckForPositions(e.mousePosition);
		e.Use ();

		break;

	case EventType.MouseUp:
		GUIUtility.hotControl = 0;
		e.Use();
		break;

	case EventType.MouseDrag:
		GUIUtility.hotControl = controlID;
		CheckForPositions(e.mousePosition);

		e.Use ();
		break;

	case EventType.KeyDown:
		if( e.keyCode == KeyCode.Escape ){
			// Do something on pressing Escape
		}

		if( e.keyCode == KeyCode.Space ){
			// Do something on pressing Spcae
		}

		if( e.keyCode == KeyCode.S ){
			// Do something on pressing S
		}

		break;
	}

	AllDrawingStuff();
}

And here the drawing if you want

void AllDrawingStuff(){
	Handles.BeginGUI();

	DrawCircleOnMousePositions();
	DrawLine();

	Handles.EndGUI();
}

Here is a small tutorial which helped me to understand all the stuff!

No the answer to that question won't help you, that's concerning how to stop the editor screen window from doing things when you click inside it ( for instance select the object you clicked on ), but that's irrelevant here.

Your problem here seems strange though, have you tried using Input.GetMouseButtonUp(0) and Input.GetMouseButtonDown(0) instead? Because those have always worked to me like you described, get called if your button goes up regardless of mouse position.


Okay so if you cannot get the mouseUp event to be registered, fake it:

var wasMouseDown : boolean = false;

if(Event.current.type == EventType.MouseDown && Event.current.button == 0) {

    Debug.Log("Left-Mouse Down");

    wasMouseDown = true;
}

else if (wasMouseDown) {

    Debug.Log("Left-Mouse Up");

    wasMouseDown = false;
}

This may also be of use:

"If call Event.current.Use(), the event will be "eaten" by the editor and not be used by the scene view its using"

after reading this, this is the solution I’ve came up with( works on 2019.4.18f1)

if(Event.current.type == EventType.Layout) return; 

// Without this you cant get mouse up events dont know why, it also prevents unity to handle some inputs so dont handle layout events otherwise you can move the selected object but cant select a different one
HandleUtility.AddDefaultControl(-1);

var e = Event.current;

// Prevents duplicate key and mouse events
if (e.isMouse || e.isKey)
{
    if (e.commandName == "Used")
    {
        return;
    }
    e.commandName = "Used";
}


if (e.type == EventType.MouseDown)
{
    Debug.Log("Down");
}

if (e.type == EventType.MouseUp)
{
    Debug.Log("Mouse Up");
}

If you don’t want to interfere with editor events and be able to select objects and just be notified about MouseUp event, you can check it this way:

Event current = Event.current;
if (current.type == EventType.MouseUp && current.button == 0)
{
Debug.Log("LMB up");
}
else if (current.type == EventType.Used && current.button == 0 && current.pointerType == PointerType.Mouse)
{
Debug.Log("LMB up used");
}