Search Unity

[Resolved]Event.current.mousePosition returns different value at same point

Discussion in 'Editor & General Support' started by NoobCoderFake, Aug 13, 2018.

  1. NoobCoderFake

    NoobCoderFake

    Joined:
    Nov 24, 2015
    Posts:
    42
    code like this:
    Code (CSharp):
    1. Rect rect;
    2.  
    3. void OnGUI()
    4. {
    5.     //...draw some other things...
    6.    
    7.     if (Event.current.type == EventType.Repaint)
    8.     {
    9.         rect = GUILayoutUtility.GetLastRect();
    10.         if (rect.Contains(Event.current.mousePosition))
    11.         {
    12.             Debug.Log("mouse over, pos: " + Event.current.mousePosition + " rect: " + rect);
    13.         }
    14.     }
    15.     else if (Event.current.type == EventType.MouseDown)
    16.     {
    17.         Debug.Log("mouse down, pos: " + Event.current.mousePosition);
    18.     }
    19. }
    Output in Log:
    mouse over, pos: (48.0, 27.0) rect: (x:4.00, y:20.00, width:930.00, height:137.00) //Y-aixs value seems incorrect, as there's three lines of text above.
    mouse down, pos: (47.0, 64.0)

    It's almost the same point in screen, but the Y-aixs value is different. Is there something wrong with my code?
     
  2. NoobCoderFake

    NoobCoderFake

    Joined:
    Nov 24, 2015
    Posts:
    42
    Seems it starts at scroll area of EditorGUILayout.BeginScrollView when "mouse over", somehow starts from editor window's left top when "mouse down". Height of Contents above this ScrollView is just 37.0