Gizmos 및 Handles 클래스를 사용하면 씬 뷰와 게임 뷰에 라인과 모양뿐만 아니라 인터랙티브 핸들과 컨트롤도 그릴 수 있습니다. 이 두 클래스를 함께 사용하면 이러한 뷰에 표시되는 요소를 확장하고, 원하는 방식으로 프로젝트를 편집할 수 있는 인터랙티브 툴을 빌드할 수 있습니다. 예를 들어 인스펙터에서 숫자를 입력하는 대신, 논플레이어 캐릭터(NPC) 주위에 드래그 가능한 원형 반지름 기즈모를 만들 수 있습니다. 이 기즈모는 플레이어를 보거나 플레이어의 소리를 들을 수 있는 영역을 나타냅니다.
이 페이지에서는 Gizmos 및 Handles 클래스에 대한 간단한 개요를 제공합니다. Gizmos 및 Handles 클래스의 모든 멤버에 대한 전체 문서와 레퍼런스는 Gizmos 및 Handles 스크립트 레퍼런스 페이지를 참조하십시오.
Gizmos 클래스를 사용하면 프로젝트를 개발하는 동안 디버깅, 설정 지원 또는 툴로 사용할 라인, 구체, 큐브, 아이콘, 텍스처, 메시를 씬 뷰에 그릴 수 있습니다.
예를 들어 게임 오브젝트 주의에 10단위 노란색 와이어 큐브를 그리려면 다음 코드를 사용할 수 있습니다.
using UnityEngine;
public class GizmosExample : MonoBehaviour
{
void OnDrawGizmosSelected()
{
// Draw a yellow cube at the transform position
Gizmos.color = Color.yellow;
Gizmos.DrawWireCube(transform.position, new Vector3(10, 10, 10));
}
}
다음은 방향 광원 게임 오브젝트에 배치한 큐브의 모습입니다.
전체 문서와 Gizmos 사용법은 Gizmos 스크립트 레퍼런스 페이지를 참조하십시오.
Gizmos와 유사하지만, 상호작용 및 조작 부문에서 더 많은 기능을 제공합니다. Unity가 씬 뷰에서 항목을 조작하기 위해 제공하는 3D 컨트롤은 Gizmos와 Handles의 조합입니다. Transform 컴포넌트를 통해 오브젝트를 배치, 스케일 및 회전시키는 기존의 익숙한 툴을 비롯하여 다양한 빌트인 핸들 GUI를 제공합니다. 하지만 커스텀 컴포넌트 에디터에서 사용할 고유한 핸들 GUI를 정의할 수 있습니다. 이러한 GUI는 절차적으로 생성된 씬 콘텐츠, 관련 오브젝트의 “보이지 않는” 항목 및 그룹(예: 웨이포인트, 위치 마커)을 편집할 때 매우 유용합니다.
예를 들어 다음은 화살표 모양 핸들을 사용하여 원호 영역을 생성하여 씬 뷰에서 “보호막 영역”을 수정하는 방법을 보여줍니다.
using UnityEditor;
using UnityEngine;
using System.Collections;
//this class should exist somewhere in your project
public class WireArcExample : MonoBehaviour
{
public float shieldArea;
}
// Create a 180 degrees wire arc with a ScaleValueHandle attached to the disc
// that lets you modify the "shieldArea" value in the WireArcExample
[CustomEditor(typeof(WireArcExample))]
public class DrawWireArc : Editor
{
void OnSceneGUI()
{
Handles.color = Color.red;
WireArcExample myObj = (WireArcExample)target;
Handles.DrawWireArc(myObj.transform.position, myObj.transform.up, -myObj.transform.right, 180, myObj.shieldArea);
myObj.shieldArea = (float)Handles.ScaleValueHandle(myObj.shieldArea, myObj.transform.position + myObj.transform.forward * myObj.shieldArea, myObj.transform.rotation, 1, Handles.ConeHandleCap, 1);
}
}
전체 문서와 Handles 사용법은 Handles 스크립트 레퍼런스 페이지를 참조하십시오.
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.