Project_WL/Assets/WL/Scripts/UI/CameraModeButton.cs

63 lines
2.3 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using WL.Player;
namespace WL.UI
{
/// <summary>
/// 우측 상단 시야 모드 토글 버튼. 탭할 때마다 1 숄더뷰 → 2 근거리 → 1 순환 (PD 지시 ⑦ 로 모드 3 제거).
/// 아이콘은 더미(기본 UI 스프라이트 단색)이며, 라벨에 현재 모드 번호를 표시한다.
/// </summary>
[RequireComponent(typeof(Button))]
public class CameraModeButton : MonoBehaviour
{
[Header("참조")]
[SerializeField] private FollowCamera followCamera;
[Tooltip("현재 모드 번호를 표시할 텍스트")]
[SerializeField] private Text label;
[Tooltip("더미 아이콘 이미지 — 모드마다 색을 바꾼다")]
[SerializeField] private Image icon;
[Header("모드별 더미 아이콘 색 (임시)")]
[SerializeField] private Color[] modeColors = new Color[]
{
new Color(0.98f, 0.55f, 0.25f, 1f), // 1 숄더뷰
new Color(0.30f, 0.72f, 0.98f, 1f) // 2 근거리
};
private Button _button;
private void Awake()
{
_button = GetComponent<Button>();
_button.onClick.AddListener(OnClick);
if (followCamera == null && Camera.main != null) followCamera = Camera.main.GetComponent<FollowCamera>();
}
private void Start() { Refresh(); }
private void OnDestroy()
{
if (_button != null) _button.onClick.RemoveListener(OnClick);
}
private void OnClick()
{
if (followCamera == null && Camera.main != null) followCamera = Camera.main.GetComponent<FollowCamera>();
if (followCamera == null) return;
int idx = followCamera.CycleMode();
Refresh();
Debug.Log("[CameraModeButton] 시야 모드 -> " + (idx + 1) + " (" + followCamera.CurrentModeLabel + ")");
}
public void Refresh()
{
if (followCamera == null) return;
int idx = followCamera.ModeIndex;
if (label != null) label.text = (idx + 1).ToString();
if (icon != null && modeColors != null && modeColors.Length > 0)
icon.color = modeColors[Mathf.Clamp(idx, 0, modeColors.Length - 1)];
}
}
}