105 lines
3.3 KiB
C#
105 lines
3.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace UVC.Util
|
|
{
|
|
/// <summary>
|
|
/// GizmoDraw 클래스는 Unity의 Gizmo를 사용하여 Sphere, Box, 또는 Mesh를 그리는 기능을 제공합니다.
|
|
/// </summary>
|
|
public class GizmoDraw : MonoBehaviour
|
|
{
|
|
/// <summary>
|
|
/// Gizmo의 타입을 정의합니다. Sphere, Box, 또는 Mesh 중 하나를 선택할 수 있습니다.
|
|
/// </summary>
|
|
public enum GizmoType
|
|
{
|
|
Sphere,
|
|
Box,
|
|
Mesh
|
|
}
|
|
|
|
/// <summary>
|
|
/// 현재 Gizmo의 타입을 설정합니다.
|
|
/// </summary>
|
|
public GizmoType gizmoType;
|
|
|
|
/// <summary>
|
|
/// Gizmo를 화면에 표시할지 여부를 설정합니다.
|
|
/// </summary>
|
|
public bool show = true;
|
|
|
|
/// <summary>
|
|
/// Gizmo를 와이어프레임으로 그릴지 여부를 설정합니다.
|
|
/// </summary>
|
|
public bool wire = false;
|
|
|
|
/// <summary>
|
|
/// Gizmo의 색상을 설정합니다.
|
|
/// </summary>
|
|
[SerializeField]
|
|
private Color color = Color.yellow;
|
|
|
|
/// <summary>
|
|
/// Sphere Gizmo의 반지름을 설정합니다.
|
|
/// </summary>
|
|
[SerializeField]
|
|
private float radius = 1f;
|
|
|
|
/// <summary>
|
|
/// Box Gizmo의 경계(Bounds)를 설정합니다.
|
|
/// </summary>
|
|
public Bounds bounds = new Bounds(Vector3.zero, Vector3.one);
|
|
|
|
/// <summary>
|
|
/// Mesh Gizmo를 그릴 때 사용할 Mesh를 설정합니다.
|
|
/// </summary>
|
|
public Mesh mesh;
|
|
|
|
/// <summary>
|
|
/// Mesh Gizmo의 스케일을 설정합니다.
|
|
/// </summary>
|
|
public float scale = 1f;
|
|
|
|
/// <summary>
|
|
/// Unity의 Gizmo를 그리는 메소드입니다. Unity 에디터에서만 동작합니다.
|
|
/// </summary>
|
|
/// <example>
|
|
/// GizmoDraw 컴포넌트를 사용하여 Sphere를 그리는 예제:
|
|
/// <code>
|
|
/// var gizmoDraw = gameObject.AddComponent<GizmoDraw>();
|
|
/// gizmoDraw.gizmoType = GizmoDraw.GizmoType.Sphere;
|
|
/// gizmoDraw.show = true;
|
|
/// gizmoDraw.wire = false;
|
|
/// gizmoDraw.radius = 2f;
|
|
/// </code>
|
|
/// </example>
|
|
void OnDrawGizmos()
|
|
{
|
|
if (this.show)
|
|
{
|
|
Gizmos.color = color;
|
|
|
|
if (gizmoType == GizmoType.Sphere)
|
|
{
|
|
if (wire)
|
|
Gizmos.DrawWireSphere(transform.position, radius);
|
|
else
|
|
Gizmos.DrawSphere(transform.position, radius);
|
|
}
|
|
else if (gizmoType == GizmoType.Box)
|
|
{
|
|
if (wire)
|
|
Gizmos.DrawWireCube(transform.position + bounds.center, bounds.size);
|
|
else
|
|
Gizmos.DrawCube(transform.position + bounds.center, bounds.size);
|
|
}
|
|
else
|
|
{
|
|
if (wire)
|
|
Gizmos.DrawWireMesh(mesh, transform.position, Quaternion.identity, new Vector3(scale, scale, scale));
|
|
else
|
|
Gizmos.DrawMesh(mesh, transform.position, Quaternion.identity, new Vector3(scale, scale, scale));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |