110 lines
2.4 KiB
C#
110 lines
2.4 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
|
|
public class ConfirmPopupUI : MonoBehaviour
|
|
{
|
|
[Header("UI Components")]
|
|
public CanvasGroup canvasGroup;
|
|
public RectTransform popupBox;
|
|
public TextMeshProUGUI titleText;
|
|
public TextMeshProUGUI messageText;
|
|
|
|
[Header("Animation Settings")]
|
|
public float animDuration = 0.2f;
|
|
public float startScale = 0.85f;
|
|
|
|
private bool isAnimating = false;
|
|
|
|
void Awake()
|
|
{
|
|
HideInstant();
|
|
}
|
|
|
|
public void Show(string title, string message)
|
|
{
|
|
if (isAnimating) return;
|
|
|
|
titleText.text = title;
|
|
messageText.text = message;
|
|
|
|
gameObject.SetActive(true);
|
|
StartCoroutine(ShowAnim());
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
if (isAnimating) return;
|
|
StartCoroutine(HideAnim());
|
|
}
|
|
|
|
public void HideInstant()
|
|
{
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 0;
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}
|
|
|
|
if (popupBox != null)
|
|
popupBox.localScale = Vector3.one * startScale;
|
|
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
IEnumerator ShowAnim()
|
|
{
|
|
isAnimating = true;
|
|
|
|
canvasGroup.blocksRaycasts = true;
|
|
canvasGroup.interactable = true;
|
|
|
|
float t = 0f;
|
|
canvasGroup.alpha = 0f;
|
|
popupBox.localScale = Vector3.one * startScale;
|
|
|
|
while (t < animDuration)
|
|
{
|
|
t += Time.unscaledDeltaTime;
|
|
float p = t / animDuration;
|
|
|
|
canvasGroup.alpha = Mathf.Lerp(0f, 1f, p);
|
|
popupBox.localScale = Vector3.Lerp(Vector3.one * startScale, Vector3.one, p);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
canvasGroup.alpha = 1f;
|
|
popupBox.localScale = Vector3.one;
|
|
|
|
isAnimating = false;
|
|
}
|
|
|
|
IEnumerator HideAnim()
|
|
{
|
|
isAnimating = true;
|
|
|
|
float t = 0f;
|
|
float endScale = startScale;
|
|
|
|
while (t < animDuration)
|
|
{
|
|
t += Time.unscaledDeltaTime;
|
|
float p = t / animDuration;
|
|
|
|
canvasGroup.alpha = Mathf.Lerp(1f, 0f, p);
|
|
popupBox.localScale = Vector3.Lerp(Vector3.one, Vector3.one * endScale, p);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
canvasGroup.alpha = 0f;
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
isAnimating = false;
|
|
}
|
|
} |