Search Unity

Resolved Detect raw mouse events

Discussion in 'UI Toolkit' started by Rukas90, Aug 18, 2021.

  1. Rukas90

    Rukas90

    Joined:
    Sep 20, 2015
    Posts:
    169
    Hello everyone,
    I am working on an eyedropper and ran into an issue. How can I detect raw mouse events, such as mouse down, move, and up? I want to be able to detect these events even when outside the editor window. I am not using Unity's old GUI system but instead a new UI system. In the OnGUI method when I check the current event the type is always either Repaint or Layout. It doesn't fire mouse events.

    Code (CSharp):
    1. private void OnGUI()
    2. {
    3.     var ve = rootVisualElement.Q<VisualElement>(null, "color-picker-window-container");
    4.     if (ve != null)
    5.     {
    6.         ve.style.height = new StyleLength(position.height);
    7.     }
    8.     Event e = Event.current;
    9.     if (sampleEyedropper)
    10.     {
    11.         if (e.rawType == EventType.Repaint)
    12.         {
    13.             colorPicker.SampleColor(e.mousePosition);
    14.         }
    15.     }
    16.     if (e.rawType == EventType.MouseDown) //<-- Doesn't detect
    17.     {
    18.         Debug.Log("Down");
    19.         sampleEyedropper = false;
    20.     }
    21. }
     
  2. Rukas90

    Rukas90

    Joined:
    Sep 20, 2015
    Posts:
    169
    PutridEx likes this.