Version: 2020.3
Handling events
Event reference

이벤트 합성

커스텀 이벤트를 합성하고 전송하기 전에 UI 툴킷 이벤트 시스템이 운영체제 이벤트를 할당하고 전송하는 방식을 이해해야 합니다.

UI 툴킷 이벤트 시스템은 이벤트 풀을 사용하여 이벤트 오브젝트의 반복 할당을 방지합니다. 고유한 이벤트를 합성하고 전송하려면 다음의 동일한 단계에 따라 이벤트를 할당하고 전송해야 합니다.

  1. 이벤트 풀에서 이벤트 오브젝트를 가져옵니다.
  2. 이벤트 프로퍼티를 채웁니다.
  3. Enclose the event in a using block to ensure it’s returned to the event pool.
  4. 이벤트를 element.SendEvent()로 전달합니다.

If you want to send events that come from the operating system, such as keyboard events and some mouse events, use a UnityEngine.Event to initialize the UI Toolkit event.

다음 예제는 이벤트를 합성하고 전송하는 방식을 보여줍니다.

void SynthesizeAndSendKeyDownEvent(IPanel panel, KeyCode code,
     char character = '\0', EventModifiers modifiers = EventModifiers.None)
{
    // Create a UnityEngine.Event to hold initialization data.
    // Also, this event will be forwarded to IMGUIContainer.m_OnGUIHandler
    var evt = new Event() {
        type = EventType.KeyDownEvent,
        keyCode = code,
        character = character,
        modifiers = modifiers
    };

    using (KeyDownEvent keyDownEvent = KeyDownEvent.GetPooled(evt))
    {
        panel.SendEvent(keyDownEvent);
    }
}


  • 2018–11–02 페이지 수정됨
Handling events
Event reference
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961