140 lines
4.5 KiB
C#
140 lines
4.5 KiB
C#
using System.Collections;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Streamingle.Contents.BossRaid
|
|
{
|
|
/// <summary>
|
|
/// GAME OVER 화면. 유저 HP 0 시 표시됩니다.
|
|
/// </summary>
|
|
public class GameOverScreen : MonoBehaviour
|
|
{
|
|
#region Fields
|
|
|
|
[Header("비주얼")]
|
|
[SerializeField] private Color titleColor = new Color(0.9f, 0.15f, 0.1f);
|
|
[SerializeField] private Color bgColor = new Color(0f, 0f, 0f, 0.6f);
|
|
|
|
private Canvas _canvas;
|
|
private CanvasGroup _canvasGroup;
|
|
private Text _titleText;
|
|
private Coroutine _showCoroutine;
|
|
private Font _font;
|
|
|
|
#endregion
|
|
|
|
#region Unity Messages
|
|
|
|
private void Awake()
|
|
{
|
|
_font = BossRaidFontLoader.Load();
|
|
CreateUI();
|
|
_canvasGroup.alpha = 0f;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Public Methods
|
|
|
|
public void Show()
|
|
{
|
|
if (_showCoroutine != null) StopCoroutine(_showCoroutine);
|
|
_showCoroutine = StartCoroutine(ShowCoroutine());
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
if (_showCoroutine != null)
|
|
{
|
|
StopCoroutine(_showCoroutine);
|
|
_showCoroutine = null;
|
|
}
|
|
_canvasGroup.alpha = 0f;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private Methods
|
|
|
|
private IEnumerator ShowCoroutine()
|
|
{
|
|
_titleText.text = "";
|
|
_canvasGroup.alpha = 0f;
|
|
|
|
// 페이드 인
|
|
float elapsed = 0f;
|
|
while (elapsed < 0.5f)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
_canvasGroup.alpha = elapsed / 0.5f;
|
|
yield return null;
|
|
}
|
|
_canvasGroup.alpha = 1f;
|
|
|
|
// 텍스트 등장 (펀치 스케일)
|
|
_titleText.text = "GAME OVER";
|
|
var rect = _titleText.rectTransform;
|
|
rect.localScale = Vector3.one * 2f;
|
|
|
|
elapsed = 0f;
|
|
while (elapsed < 0.4f)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
float t = elapsed / 0.4f;
|
|
float ease = 1f + 2.7f * Mathf.Pow(t - 1f, 3f) + 1.7f * Mathf.Pow(t - 1f, 2f);
|
|
rect.localScale = Vector3.one * Mathf.LerpUnclamped(2f, 1f, ease);
|
|
yield return null;
|
|
}
|
|
rect.localScale = Vector3.one;
|
|
}
|
|
|
|
private void CreateUI()
|
|
{
|
|
var canvasObj = new GameObject("BossRaid_GameOver");
|
|
canvasObj.transform.SetParent(transform);
|
|
_canvas = canvasObj.AddComponent<Canvas>();
|
|
_canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
|
_canvas.sortingOrder = 201;
|
|
_canvasGroup = canvasObj.AddComponent<CanvasGroup>();
|
|
_canvasGroup.interactable = false;
|
|
_canvasGroup.blocksRaycasts = false;
|
|
var scaler = canvasObj.AddComponent<CanvasScaler>();
|
|
scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
|
scaler.referenceResolution = new Vector2(1920, 1080);
|
|
|
|
// 배경
|
|
var bgObj = new GameObject("BG");
|
|
bgObj.transform.SetParent(canvasObj.transform, false);
|
|
var bgRect = bgObj.AddComponent<RectTransform>();
|
|
bgRect.anchorMin = Vector2.zero;
|
|
bgRect.anchorMax = Vector2.one;
|
|
bgRect.offsetMin = Vector2.zero;
|
|
bgRect.offsetMax = Vector2.zero;
|
|
var bgImg = bgObj.AddComponent<Image>();
|
|
bgImg.color = bgColor;
|
|
bgImg.raycastTarget = false;
|
|
|
|
// 타이틀
|
|
var titleObj = new GameObject("Title");
|
|
titleObj.transform.SetParent(canvasObj.transform, false);
|
|
var titleRect = titleObj.AddComponent<RectTransform>();
|
|
titleRect.anchorMin = new Vector2(0.1f, 0.3f);
|
|
titleRect.anchorMax = new Vector2(0.9f, 0.7f);
|
|
titleRect.offsetMin = Vector2.zero;
|
|
titleRect.offsetMax = Vector2.zero;
|
|
_titleText = titleObj.AddComponent<Text>();
|
|
_titleText.fontSize = 90;
|
|
_titleText.color = titleColor;
|
|
_titleText.alignment = TextAnchor.MiddleCenter;
|
|
_titleText.fontStyle = FontStyle.Bold;
|
|
_titleText.raycastTarget = false;
|
|
if (_font != null) _titleText.font = _font;
|
|
var outline = titleObj.AddComponent<Outline>();
|
|
outline.effectColor = Color.black;
|
|
outline.effectDistance = new Vector2(3f, -3f);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|