Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Multiple clicks on object inherited from ObjectField

Discussion in 'UIElements' started by SigitasAmbrozaitis, Jun 28, 2019.

  1. SigitasAmbrozaitis

    SigitasAmbrozaitis

    Joined:
    Jun 17, 2019
    Posts:
    1
    I want to implement double click to MouseDownEvent. I have inherited ObjectField and overloaded
    ExecuteDefaultActionAtTarget, then i check if recieved event is MouseDownEvent and if its is i cast it and try to give different behavior depenging on MouseDownEvent.eventCount.

    The problem is that when i double click on object, i receive only one event, but its eventCount is always 1. I tried to implement this behavior looking at ObjectField source code. Also looking at the timing of Debug.Log, it is printed after first click, and second click is skipped.

    So the question is, am i doing something wrong, or is this a bug?

    Code (CSharp):
    1. public class PlayerField : ObjectField
    2. {
    3.     public PlayerField(){}
    4.  
    5.     protected override void ExecuteDefaultActionAtTarget(EventBase evt)
    6.     {
    7.         base.ExecuteDefaultActionAtTarget(evt);
    8.  
    9.         if (evt == null)
    10.         {
    11.             return;
    12.         }
    13.  
    14.         if ((evt as MouseDownEvent)?.button == (int)MouseButton.LeftMouse)
    15.             OnMouseDown(evt as MouseDownEvent);
    16.     }
    17.  
    18.     private void OnMouseDown(MouseDownEvent evt)
    19.     {
    20.         Debug.Log("ClickCount::" + evt.clickCount);
    21.     }
    22. }
     
  2. patrickf

    patrickf

    Unity Technologies

    Joined:
    Oct 24, 2016
    Posts:
    43
    This looks like a bug. Would you please fill a bug report including Unity version and OS you are working with? Thanks!