Unity Engine 에디터 내에 Scene View 를 활용해서 툴을 만들 때, 마우스 좌클릭을 기본 도구에서의 선택 도구 외에 다른 용도로 사용하려고 하면 Unity Engine 의 Event 를 핸들링 할 필요가 있다.
Event.current 가 에디터의 UnityGUI 이벤트가 되는데, 이 이벤트가 마우스 좌클릭일 때 Use() 를 호출해서 사용처리 해버리면 선택 도구로 작동하는 것을 후킹할 수 있다.
if (Event.current.type != EventType.MouseDown)
return;
if (Event.current.button != 0)
return;
Event.current.Use();
// 툴에서 원하는 동작 처리.
Event.current.button 의 값은 마우스 버튼
// button 0 좌클릭
// button 1 우클릭
// button 2 미들클릭
참조 : https://docs.unity3d.com/ScriptReference/Event-button.html
아래는 UnityEngine의 EventType 공식 문서.
https://docs.unity3d.com/2019.4/Documentation/ScriptReference/EventType.html
Unity - Scripting API: EventType
Use this to tell which type of event has taken place in the GUI. Types of Events include mouse clicking, mouse dragging, button pressing, the mouse entering or exiting the window, and the scroll wheel as well as others mentioned below. See Also: Event.type
docs.unity3d.com
아래 코드를 추가하면 Editor 에 열려있는 씬에서 오브젝트를 선택되지 않게 할 수 있다.
private void OnSceneGUI()
{
HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
}
'유니티 엔진 (Unity Engine)' 카테고리의 다른 글
[Unity] 2D Animation Package Sample 의 Missing Prefab 문제 (0) | 2024.04.02 |
---|---|
[Unity] 모바일 최적화 2022LTS 자료 모음 (0) | 2024.03.29 |
[Unity] 시네머신을 활용해 쉽고 간편하게 카메라 이동 영역 제한 (0) | 2024.03.29 |
[Unity] Texture2D와 RenderTexture의 핵심 차이 (2) | 2024.03.20 |
[Unity] 최초 실행되는 UnityMain 함수 만들기 (RuntimeInitializeOnLoadMethod 상세 순서 설명) (0) | 2024.03.19 |
[Unity] 유니티 셰이더 코드에서 _MainTex_TexelSize 변수의 정체는? (0) | 2024.03.19 |
[Unity] 셰이더 처리 후 텍스처 테두리가 번져 보이는 문제 (0) | 2024.03.19 |