> For the complete documentation index, see [llms.txt](https://docs.decentraland.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/advanced-button-events.md). Agents can also search and read this documentation through its [MCP server](https://docs.decentraland.org/~gitbook/mcp).

# 고급 버튼 이벤트

씬에서 사용자 클릭을 처리하는 방법을 알아봅니다.

씬의 상호작용이 다음과 호환되지 않는 사용자 지정 로직을 따라야 하는 경우 [콜백 등록](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/register-callback.md) 또는 [시스템 기반](https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/system-based-events.md) 방식과 호환되지 않는다면, 원시 입력 이벤트 데이터를 직접 처리할 수 있습니다. 이 방식은 가장 어렵지만 유연성은 가장 높습니다.

## PointerEventsResult 컴포넌트

엔진이 포인터 이벤트를 감지하면 클릭된 엔티티에 `PointerEventsResult` 컴포넌트가 할당됩니다. 이 컴포넌트에는 적중 이벤트에 대한 모든 원시 데이터가 포함되며, 이전 이벤트의 기록 데이터도 저장됩니다.

inputSystem `의 헬퍼`(예: `inputSystem.isTriggered` 및 `inputSystem.getInputCommand` )는 대부분의 간단한 시나리오에 적합합니다. 하지만 적중 이벤트에 대해 더 자세한 정보를 얻어야 한다면 `PointerEventsResult`.

의 `PointerEventsResult` 컴포넌트에는 포인터 이벤트 목록이 있으며, 각 이벤트는 하나의 객체로 저장됩니다. 이벤트는 최대 100개까지 저장되고, 새 이벤트는 목록의 끝에 추가됩니다. 목록 길이가 100에 도달하면 새 이벤트가 들어올 때마다 가장 오래된 이벤트가 삭제됩니다.

목록의 각 이벤트에는 다음 데이터가 포함됩니다.

* `analog`: 선택적 숫자 값입니다. 조이스틱과 같은 아날로그 입력에서 발생한 이벤트에만 있으며, 입력의 아날로그 값을 저장합니다.
* `button`: 눌린 버튼의 ID입니다. 이 숫자는 사용 가능한 모든 버튼을 나열하는 `InputAction` 열거형의 값에 해당합니다.
* `state`: 포인터 이벤트의 유형입니다. 다음 열거형에 정의되어 있습니다. `PointerEventType`. *0* 은 다음을 나타냅니다. `PointerEventType.PET_UP`, *1* 부터 `PointerEventType.PET_DOWN`, *2* 부터 `PointerEventType.PET_HOVER_ENTER`, *3* 부터 `PointerEventType.PET_HOVER_LEAVE`, *4* 부터 `PointerEventType.PET_PROXIMITY_ENTER`, *5* 부터 `PointerEventType.PET_PROXIMITY_LEAVE`
* `timestamp`: 버튼 이벤트를 각각 식별하는 [Lamport 타임스탬프](https://en.wikipedia.org/wiki/Lamport_timestamp) 입니다.

  > 참고: 이 타임스탬프는 현재 시간을 기준으로 번호를 매기지 않습니다. 0에서 시작해 이벤트가 발생할 때마다 1씩 증가하는 카운터라고 생각하면 됩니다.
* `hit`: 적중 이벤트에 대한 다음 데이터가 포함된 객체입니다.
  * `entityId`: 레이가 충돌한 엔티티의 ID 번호입니다.
  * `meshName`: *문자열* 적중한 3D 모델의 특정 메시 내부 이름입니다. 3D 모델이 여러 메시로 구성된 경우 유용합니다.
  * `globalOrigin`: *Vector3* 광선이 시작되는 위치(씬 기준)
  * `direction`: *Vector3* 전역 좌표계에서 광선의 방향 벡터를 나타냅니다.
  * `position`: *Vector3* 광선이 적중한 엔터티와 교차한 위치(장면 기준)입니다.
  * `length`: 광선의 원점에서 엔터티와 충돌한 위치까지의 길이입니다.
  * `normalHit`: *Vector3* 정규화된 방향 벡터와 함께, 월드 공간에서 충돌 지점의 법선이 이루는 각도를 설명합니다.

```ts
import { engine, PointerEventsResult } from '@dcl/sdk/ecs'

function PointerReadingSystem() {
  for (const [entity] of engine.getEntitiesWith(PointerEventsResult)) {
    const events = PointerEventsResult.get(entity)
    for (const event of events) {
      console.log('POINTER EVENT DATA:', event)
    }
  }
}

engine.addSystem(PointerReadingSystem)
```

## 플레이어의 움직임 추적

플레이어의 움직임 타이밍이 중요한 실시간 멀티플레이어 게임에서는 제3자 서버를 단일 정보 출처로 삼아 각 플레이어의 위치를 추적하고 싶을 수 있습니다. 버튼 입력을 미리 감지하고 아바타가 위치를 바꾸기 전에 서버에서 그 영향을 예측하면 응답 시간을 단축할 수 있습니다.

이 접근 방식은 네트워크 지연을 보완하는 데 도움이 되지만, 불일치가 발생할 수밖에 없습니다. 따라서 플레이어의 현재 위치를 정기적으로 확인해 수정해야 합니다. 이러한 예측과 수정 사이의 균형을 맞추려면 충분한 미세 조정이 필요할 수 있습니다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.decentraland.org/creator/content-creator-ko/sdk7/interactivity/button-events/advanced-button-events.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
