155 lines
3.8 KiB
C#
155 lines
3.8 KiB
C#
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FishingGaugeUI : MonoBehaviour
|
|
{
|
|
[Header("Panel UI")]
|
|
[SerializeField] private GameObject counterPanel;
|
|
[SerializeField] private GameObject finalResultPanel;
|
|
|
|
[Header("Gauge UI")]
|
|
[SerializeField] private RectTransform pointerPivot;
|
|
[SerializeField] private Image successZone;
|
|
|
|
[Header("Text UI")]
|
|
[SerializeField] private TMP_Text successText;
|
|
[SerializeField] private TMP_Text failText;
|
|
[SerializeField] private TMP_Text resultText;
|
|
[SerializeField] private TMP_Text finalResultText;
|
|
|
|
[Header("Zone Visual Correction")]
|
|
[Tooltip("성공 구간 이미지가 판정 위치와 어긋나면 이 값을 조정하세요.")]
|
|
[SerializeField] private float zoneVisualOffset = 0f;
|
|
|
|
[Header("Result Settings")]
|
|
[SerializeField] private float resultShowTime = 1f;
|
|
[SerializeField] private bool hideCounterOnFinalResult = true;
|
|
|
|
private Coroutine resultRoutine;
|
|
|
|
private void Awake()
|
|
{
|
|
HideRoundResult();
|
|
HideFinalResult();
|
|
ShowCounter();
|
|
}
|
|
|
|
public void SetPointerRotation(float angle)
|
|
{
|
|
if (pointerPivot == null)
|
|
return;
|
|
|
|
pointerPivot.localEulerAngles = new Vector3(0f, 0f, -angle);
|
|
}
|
|
|
|
public void SetZone(float centerAngle, float size)
|
|
{
|
|
SetZoneSize(size);
|
|
SetZoneRotation(centerAngle, size);
|
|
}
|
|
|
|
public void SetZoneSize(float size)
|
|
{
|
|
if (successZone == null)
|
|
return;
|
|
|
|
successZone.fillAmount = Mathf.Clamp01(size / 360f);
|
|
}
|
|
|
|
public void SetZoneRotation(float centerAngle, float size)
|
|
{
|
|
if (successZone == null)
|
|
return;
|
|
|
|
float startAngle = centerAngle - size * 0.5f + zoneVisualOffset;
|
|
successZone.rectTransform.localEulerAngles =
|
|
new Vector3(0f, 0f, -startAngle);
|
|
}
|
|
|
|
public void UpdateCounter(int success, int successTarget, int fail, int failTarget)
|
|
{
|
|
ShowCounter();
|
|
|
|
if (successText != null)
|
|
successText.text = $"성공 {success}/{successTarget}";
|
|
|
|
if (failText != null)
|
|
failText.text = $"실패 {fail}/{failTarget}";
|
|
}
|
|
|
|
public void ShowCounter()
|
|
{
|
|
if (counterPanel != null)
|
|
counterPanel.SetActive(true);
|
|
}
|
|
|
|
public void HideCounter()
|
|
{
|
|
if (counterPanel != null)
|
|
counterPanel.SetActive(false);
|
|
}
|
|
|
|
public void ShowResult(string text)
|
|
{
|
|
if (resultText == null)
|
|
return;
|
|
|
|
if (resultRoutine != null)
|
|
StopCoroutine(resultRoutine);
|
|
|
|
resultRoutine = StartCoroutine(ResultRoutine(text));
|
|
}
|
|
|
|
private IEnumerator ResultRoutine(string text)
|
|
{
|
|
resultText.gameObject.SetActive(true);
|
|
resultText.text = text;
|
|
|
|
yield return new WaitForSeconds(resultShowTime);
|
|
|
|
resultText.gameObject.SetActive(false);
|
|
resultRoutine = null;
|
|
}
|
|
|
|
public void HideRoundResult()
|
|
{
|
|
if (resultRoutine != null)
|
|
{
|
|
StopCoroutine(resultRoutine);
|
|
resultRoutine = null;
|
|
}
|
|
|
|
if (resultText != null)
|
|
resultText.gameObject.SetActive(false);
|
|
}
|
|
|
|
public void ShowFinalResult(string text)
|
|
{
|
|
HideRoundResult();
|
|
|
|
if (hideCounterOnFinalResult)
|
|
HideCounter();
|
|
|
|
if (finalResultPanel != null)
|
|
finalResultPanel.SetActive(true);
|
|
|
|
if (finalResultText != null)
|
|
{
|
|
finalResultText.gameObject.SetActive(true);
|
|
finalResultText.text = text;
|
|
}
|
|
}
|
|
|
|
public void HideFinalResult()
|
|
{
|
|
if (finalResultPanel != null)
|
|
finalResultPanel.SetActive(false);
|
|
|
|
if (finalResultText != null)
|
|
finalResultText.gameObject.SetActive(false);
|
|
|
|
ShowCounter();
|
|
}
|
|
} |