창 올라타기
This commit is contained in:
73
Assets/02_Scripts/Desktop/PlatformDebugOverlay.cs
Normal file
73
Assets/02_Scripts/Desktop/PlatformDebugOverlay.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// 탐지된 발판을 화면에 선으로 그린다.
|
||||
///
|
||||
/// 상태머신을 얹기 전에 좌표가 맞는지 눈으로 확인하기 위한 것이다. 물리부터
|
||||
/// 붙이면 "캐릭터가 이상한 데 선다"가 좌표 문제인지 물리 문제인지 구분되지 않는다.
|
||||
/// 검증이 끝나면 꺼두면 된다.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(DesktopPlatformScanner))]
|
||||
public class PlatformDebugOverlay : MonoBehaviour
|
||||
{
|
||||
[SerializeField] bool show = true;
|
||||
[SerializeField] float lineThickness = 3f;
|
||||
[SerializeField] Color windowColor = new Color(0.2f, 0.9f, 1f, 0.85f);
|
||||
[SerializeField] Color floorColor = new Color(1f, 0.8f, 0.2f, 0.85f);
|
||||
|
||||
[Tooltip("각 발판에 창 제목을 함께 표시")]
|
||||
[SerializeField] bool showTitles = true;
|
||||
|
||||
DesktopPlatformScanner scanner;
|
||||
Texture2D pixel;
|
||||
GUIStyle labelStyle;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
scanner = GetComponent<DesktopPlatformScanner>();
|
||||
|
||||
pixel = new Texture2D(1, 1);
|
||||
pixel.SetPixel(0, 0, Color.white);
|
||||
pixel.Apply();
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (pixel != null) Destroy(pixel);
|
||||
}
|
||||
|
||||
void OnGUI()
|
||||
{
|
||||
if (!show || scanner == null) return;
|
||||
|
||||
labelStyle ??= new GUIStyle(GUI.skin.label) { fontSize = 11 };
|
||||
|
||||
var platforms = scanner.Platforms;
|
||||
|
||||
for (int i = 0; i < platforms.Count; i++)
|
||||
{
|
||||
var p = platforms[i];
|
||||
|
||||
// OnGUI 는 좌상단 원점이라 Y 를 뒤집는다.
|
||||
float guiY = Screen.height - p.Y;
|
||||
|
||||
GUI.color = p.IsFloor ? floorColor : windowColor;
|
||||
GUI.DrawTexture(new Rect(p.XMin, guiY - lineThickness * 0.5f, p.Width, lineThickness), pixel);
|
||||
|
||||
// 구간 양끝을 세로 눈금으로 표시해 어디서 끊겼는지 보이게 한다.
|
||||
GUI.DrawTexture(new Rect(p.XMin, guiY - 8f, 2f, 16f), pixel);
|
||||
GUI.DrawTexture(new Rect(p.XMax - 2f, guiY - 8f, 2f, 16f), pixel);
|
||||
|
||||
if (showTitles)
|
||||
{
|
||||
GUI.color = Color.black;
|
||||
GUI.Label(new Rect(p.XMin + 5f, guiY + 2f, 400f, 18f), p.Title, labelStyle);
|
||||
GUI.color = p.IsFloor ? floorColor : windowColor;
|
||||
GUI.Label(new Rect(p.XMin + 4f, guiY + 1f, 400f, 18f), p.Title, labelStyle);
|
||||
}
|
||||
}
|
||||
|
||||
GUI.color = Color.white;
|
||||
GUI.Label(new Rect(14f, 190f, 500f, 20f), $"발판 {platforms.Count}개", labelStyle);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user