드래그 이벤트는 시각적 요소에 드래그 앤 드롭 동작이 있는 작업 중 전송됩니다. 에디터 전용 이벤트입니다.
드래그 앤 드롭 기능을 구현하려면 시각적 요소가 특정 이벤트에 콜백을 등록했는지 확인하십시오.
드래그 작업을 지원하는 시각적 요소는 다음 두 가지 타입으로 분리됩니다.
드래그 가능한 시각적 요소를 선택하여 드롭 가능한 시각적 요소로 드래그하고, 요소를 놓아 드롭할 수 있습니다.
모든 드래그 앤 드롭 이벤트의 기본 클래스는 DragAndDropEventBase입니다.
이벤트 | 설명 | 트리클다운 | 버블업 | 취소 가능 |
---|---|---|---|---|
DragExitedEvent | 드래그 앤 드롭 프로세스가 종료될 때 전송됩니다. | ✔ | ✔ | |
DragUpdatedEvent | 드래그한 요소가 드롭 타겟 위로 이동할 때 전송됩니다. | ✔ | ✔ | ✔ |
DragPerformEvent | 드래그한 요소가 타겟 위로 드롭될 때 전송됩니다. | ✔ | ✔ | ✔ |
DragEnterEvent | 드래그한 요소가 새 VisualElement 에 들어갈 때 전송됩니다. |
✔ | ||
DragLeaveEvent | 드래그한 요소가 현재의 드롭 타겟에서 나갈 때 전송됩니다. | ✔ |
시각적 요소를 드래그 가능하도록 만들려면 다음 세 가지 이벤트 타입에 대한 콜백을 등록해야 합니다:
드래그 작업을 위해 다음 단계를 따르십시오.
DragAndDrop
에 추가합니다.DragAndDrop.StartDrag()
를 호출합니다.DragPerformEvent
또는 DragExitedEvent
를 수신하면 드롭 영역 시각적 요소는 이 피드백을 제거해야 합니다.사용자가 드래그 가능한 오브젝트를 시각적 요소 위로 드래그하고 마우스 포인터를 놓으면 DragExitedEvent
가 전송됩니다. DragExitedEvent
를 수신하면 드롭 영역 시각적 요소는 드래그 작업의 모든 피드백을 제거해야 합니다.
사용자가 드래그 가능한 오브젝트를 이동할 때 포인터가 시각적 요소 위에 놓이면 DragUpdatedEvent
가 전송됩니다.
드롭 영역 시각적 요소가 DragUpdatedEvent
를 수신하면 드롭 피드백을 업데이트해야 합니다. 예를 들어, 드래그한 오브젝트가 마우스 포인터 아래에 머무르도록 드래그한 오브젝트의 “고스트”를 이동할 수 있습니다.
또한 드롭 영역 시각적 요소는 DragAndDrop
프로퍼티를 검사하고 DragAndDrop.visualMode
를 설정하여 드롭 동작의 효과를 표시해야 합니다. 예를 들어 드롭 동작을 통해 새 오브젝트를 생성하거나, 기존 오브젝트를 이동시키거나, 드롭 동작을 거부할 수 있습니다.
사용자가 드래그 가능한 오브젝트를 드래그한 후 시각적 요소 위에 마우스 포인터 커서를 놓으면 DragPerformEvent
가 전송됩니다. 이 동작은 시각적 요소가 DragAndDrop.visualMode
를 DragAndDropVisualMode.None
또는 DragAndDropVisualMode.Rejected
이외의 것으로 설정하여 드래그한 오브젝트를 허용할 수 있다고 표시할 경우에만 발생합니다.
드롭 영역 시각적 요소가 DragPerformEvent
를 수신하면 DragAndDrop.objectReferences
, DragAndDrop.paths
또는 DragAndDrop.GetGenericData()
에 저장된 드래그한 오브젝트에 대해 동작해야 합니다.
예를 들어 사용자가 오브젝트를 드롭한 위치에 새로운 시각적 요소를 추가할 수 있습니다.
드래그 작업 중 포인터가 시각적 요소에 들어가면 DragEnterEvent
가 전송됩니다.
드롭 영역 시각적 요소가 DragEnterEvent
를 수신하면 해당 요소 또는 요소의 자식이 잠재적 드롭 작업의 타겟이라는 사실을 사용자에게 알리는 피드백을 제공해야 합니다. 예를 들어, USS 클래스를 타겟 요소에 추가하고 드래그한 오브젝트의 “고스트”를 마우스 포인터 아래에 표시할 수 있습니다.
사용자가 드래그 가능한 오브젝트를 이동할 때 포인터가 시각적 요소에서 나가면 DragLeaveEvent
가 전송됩니다.
드롭 영역 시각적 요소가 DragLeaveEvent
를 수신하면 드롭 피드백 제공을 멈춰야 합니다. 예를 들어, 타겟 요소가 DragEnterEvent
를 수신했을 때 추가한 USS 클래스를 제거하고 드래그한 오브젝트의 “고스트”를 더 이상 표시하지 않을 수 있습니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.