Unity

[Unity] Debug 로 DrawCircle 만들기

라뷰 2025. 6. 12. 17:36
왜 없어 왜~ 

 

 

이번 작업 중 CircleCast 를 사용 중이다.

Line 과 Ray 는 Unity 에서 제공하는 Debug.Line 함수로 Scene 뷰에서 확인이 가능하다

 

Debug.DrawLine(pos, pos + (rot * Vector2.right * length*2f), Color.red, 3f );

 

얇은 빨간색 라인을 Scene 에서 확인 가능하다.

 

하지만 CircleCast 영역을 debug를 통해 육안으로 확인이 불가능하다!

그럼 직접... 만들어야 한다...

 


 

Debug.DrawLine 으로 직접 그릴게...

 

public static class DebugCustomUtil
{
    public static void DrawCircle(Vector3 pos, float radius, float duration=0, Color? color =null, int segments = 32)
    {   
        // 원 나누기. 라인으로 그리니까 라인을 몇번 그릴 건지.
        // segments 가 크면 부드러운 원이 됨.
        float angleStep = 360f / segments;
        
        // 색 기본 설정
        Color drawColor = color ?? Color.red;
        
        // 처음 그릴 라인의 시작 점
        Vector3 prePoint = pos + new Vector3(Mathf.Cos(0), Mathf.Sin(0), 0) * radius;

        for (int i = 1; i <= segments; ++i)
        {
            // 각도를 라디안으로 변환해서 써야함
            float angle = angleStep * i * Mathf.Deg2Rad;
            
            // 라인이 prePoint 부터 nextPoint 까지 그려짐.
            // 다음 라인을 위해 prePoint = nextPoint
            Vector3 nextPoint = pos + new Vector3(Mathf.Cos(angle), Mathf.Sin(angle), 0) * radius;

            Debug.DrawLine(prePoint, nextPoint, drawColor, duration);
            prePoint = nextPoint;
        }
    }
}

 

맞아 이게 필요했어~

 

n년 전...

CircularMovement 라고 만들어 두었던 기능이 있으니 그게 딱 생각 났다.