Hi all,
how can I be notified when the mouse’s left button is released? (in editor mode)
Hi all,
how can I be notified when the mouse’s left button is released? (in editor mode)
It’s a negative answer? I know that some mouse events could be recognized…
You could try to use the Event class
if(Event.current.type == EventType.MouseUp)
//Do something
If you want mouse up events from the scene view try Editor.OnSceneGUI
I tried this but I don’t know why this method is never called:
public class Mio : Editor {
void OnSceneGUI () {
Debug.Log ("Hello");
}
}
So, Input.GetButtonUp () does not work? That is allI have ever used for anything like this. Unless you are working on a mobile game, I don’t see why that wouldn’t work. Well, that still might work even if you are working on a mobile game. I don’t make mobile games, so I wouldn’t know. Just trying to make some suggestions.
@frenk3D : You do know that the Editor class is for writing custom editors so the class you presented in this state will never be used anywhere. What exactly do you want to achieve?
@KyleStank he wants to have mouse event in the editor, the input class as far as I remember without trying only works during runtime.
More precisely, I want to be notified when the user has moved an object with the mouse. Not when the user is moving an object, but when the translation is terminated.
So I think that I should wait for the EventType.mouseUp event, and check if the pressed button was the left. If this condition is satisfied then I check if the selected object has moved. Here the only thing that I can’t do is recognizing the EventType.mouseUp event.
What do you mean?
You should be able to get a general solution using SceneView.onSceneGUIDelegate to register a callback that can process mouse events of the user in a scene.
Regarding your Editor Script:
For OnSceneGUI to be called in your example you would have to add a [CustomEditor(…)] attribute and select a GameObject with a component of this type to see “Hello”
Ok I think I resolved my issue. The following code works for me:
[CustomEditor(typeof(GameObject))]
public class Mio : Editor {
void OnEnable() {
// a new game object is selected
}
void OnSceneGUI () {
if ( Event.current.type == EventType.mouseUp)
Debug.Log( "up" );
}
}
Is there a way to intercept mouse events occurring out of the scene view?
Where exactly do you need mouse events?
Any other place you need?
Hi,
the answer of your question is everywhere. But more precisely I need to know it when the user stop dragging an object using the mouse.
So, when the user release the LMB, first I check if the selected object has moved. If the answer is yes, I do my jobs.
On my code, if the user release the LMB in the SceneView, the event is itercepted in the OnSceneGUI callback, and I’m fine. But if the user release the LMB out of the SceneView I don’t know how to intercept the event.
Would it suffice to just compare the position with a stored position inside your custom inspectors OnSceneGUI?
I did a little bit of testing and I can’t find/think of a way to detect the mouseup event over any window right now. Might be that you can experiment with the Handles and the Tools classes to get the right behaviour. Maybe handles themselves are what you need instead of detecting a position change of a certain object?
Necroing because I struggled for a few days with this problem - using unity 2019.1
If a drag was started within the sceneview, but ends outside of it, OnSceneGUI will run twice more as it registers 2 last events. One of type “ignore” (when the mouse button is released), directly followed by one of type “MouseLeaveWindow”.