Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Multiple clicks on object inherited from ObjectField

Discussion in 'UI Toolkit' started by SigitasAmbrozaitis, Jun 28, 2019.

  1. SigitasAmbrozaitis


    Jun 17, 2019
    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(){}
    5.     protected override void ExecuteDefaultActionAtTarget(EventBase evt)
    6.     {
    7.         base.ExecuteDefaultActionAtTarget(evt);
    9.         if (evt == null)
    10.         {
    11.             return;
    12.         }
    14.         if ((evt as MouseDownEvent)?.button == (int)MouseButton.LeftMouse)
    15.             OnMouseDown(evt as MouseDownEvent);
    16.     }
    18.     private void OnMouseDown(MouseDownEvent evt)
    19.     {
    20.         Debug.Log("ClickCount::" + evt.clickCount);
    21.     }
    22. }
  2. patrickf


    Unity Technologies

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