Search
Light Mode
Contact Us

Contact us

No results for your search.
Sorry, an unexpected error occurred

Some events are more complex than the others and strongly depend on passed parameters, which UI Events Selector simply discards with its generic approach, and treats them more like a trigger to invoke given callbacks, and for that reason some events (like ContextClickEvent for example) don't work, and callbacks don't have access to event data. To work around this issue there is a special class allowing you to extract additional information from an event and create your own pseudo-event that UI Events Selector can use.

Simply declare class deriving from CustomUIEventBase<T> where T is event type that you want extract information from,

public class CustomPointerMoveEvent : CustomUIEventBase<PointerMoveEvent>






provide a constructor, from which if you need to, you can also extract information about visual element that given callback will be registered to,

VicualElement element;
public CustomPointerMoveEvent(Action callback, VisualElement element) : base(callback, element)
{ 
  this.element = element;
}






and implement ExtractInfo method specifying when this event should trigger invoking its callback.

protected override bool ExtractInfo(PointerMoveEvent eventType)
{
  return element.childCount > 0 && eventType.deltaTime > 1;
}






In this example callback will be invoked only if visual element has any children and pointer moved after being idle for at least 1 second.


Here are examples of declaring custom events for mouse right button double click and keyboard space key press.

public class MouseDoubleRightClickEvent : CustomUIEventBase<MouseDownEvent>
{
  public MouseDoubleRightClickEvent(Action callback, VisualElement element) : base(callback, element) { }

  protected override bool ExtractInfo(MouseDownEvent eventType)
  {
    return eventType.button == 1 && eventType.clickCount == 2;
  }
}
public class Key_Space_PressedEvent : CustomUIEventBase<KeyDownEvent>
{
  public Key_Space_PressedEvent(Action callback, VisualElement element) : base(callback, element) { }

  protected override bool ExtractInfo(KeyDownEvent eventType)
  {
    return eventType.keyCode == KeyCode.Space;
  }
}







Created with Notice