65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
{
|
|
/// <summary>
|
|
/// Draw BoxCollider or SphereCollider gizmos.
|
|
/// </summary>
|
|
public class DrawGizmos : MonoBehaviour
|
|
{
|
|
public enum ColliderType { BoxCollider, SphereCollider }
|
|
|
|
public ColliderType type = ColliderType.BoxCollider;
|
|
|
|
public bool drawGizmos = true;
|
|
public bool drawWire = true;
|
|
public Color color = Color.white;
|
|
public Color colorWire = Color.white;
|
|
[Space]
|
|
[SerializeField]
|
|
private Vector3 size = new Vector3(0.1f, 0.1f, 0.1f);
|
|
[SerializeField]
|
|
private float radius = 0.1f;
|
|
|
|
public Vector3 Size { get => size; set => size = value; }
|
|
public float Radius { get => radius; set => radius = value; }
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
if (drawGizmos)
|
|
{
|
|
Gizmos.color = color;
|
|
|
|
if (type == ColliderType.BoxCollider)
|
|
{
|
|
Vector3 boxSize = new Vector3(size.x, size.y, size.z);
|
|
GizmosExtensions.DrawCube(transform.position, boxSize, transform.rotation);
|
|
}
|
|
|
|
if (type == ColliderType.SphereCollider)
|
|
{
|
|
Gizmos.DrawSphere(transform.position, radius);
|
|
}
|
|
}
|
|
|
|
if (drawWire)
|
|
{
|
|
Gizmos.color = colorWire;
|
|
|
|
if (type == ColliderType.BoxCollider)
|
|
{
|
|
Vector3 boxSize = new Vector3(size.x, size.y, size.z);
|
|
GizmosExtensions.DrawWireCube(transform.position, boxSize, transform.rotation);
|
|
}
|
|
|
|
if (type == ColliderType.SphereCollider)
|
|
{
|
|
Gizmos.DrawWireSphere(transform.position, radius);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|