HeavenStudioPlus/Assets/Scripts/UI/Rating.cs

145 lines
4.1 KiB
C#
Raw Normal View History

2021-12-19 04:10:43 +00:00
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using DG.Tweening;
2022-03-14 14:21:05 +00:00
using HeavenStudio.Util;
2021-12-19 04:10:43 +00:00
2022-03-14 14:21:05 +00:00
namespace HeavenStudio
2021-12-21 01:10:49 +00:00
{
public class Rating : MonoBehaviour
{
public GameObject Title;
public GameObject Desc;
public GameObject Rank;
public GameObject Epilogue;
public GameObject Perfect;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public GameObject RankingHolder;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public GameObject Fade;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
private string rank;
private int rankId;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public Sprite[] epilogueSprites;
public Image epilogueImage;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public TMP_Text epilogueText;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
private void Start()
2021-12-19 04:10:43 +00:00
{
2021-12-21 01:10:49 +00:00
float score = GameProfiler.instance.score;
TMP_Text desc = Desc.GetComponent<TMP_Text>();
if (GameProfiler.instance.perfect)
2021-12-19 04:10:43 +00:00
{
2021-12-21 01:10:49 +00:00
Perfect.SetActive(true);
Jukebox.PlayOneShot("Rankings/ranking_perfect");
StartCoroutine(PerfectIE());
2021-12-19 04:10:43 +00:00
}
2021-12-21 01:10:49 +00:00
else
2021-12-19 04:10:43 +00:00
{
2021-12-21 01:10:49 +00:00
if (score < 59)
{
// try again
desc.text = "Your fork technique was rather uncouth. \nYour consecutive stabs needed work.";
rank = "Rankings/ranking_tryagain";
rankId = 2;
}
else if (score >= 59 && score < 79)
{
// ok
desc.text = "Eh. Good enough.";
rank = "Rankings/ranking_ok";
rankId = 1;
}
else if (score >= 79)
{
// superb
desc.text = "Your fork technique was quite elegant. \nYour consecutive stabs were excellent. \nYour triple-stab technique was sublime.";
rank = "Rankings/ranking_superb";
rankId = 0;
}
StartCoroutine(ShowRank());
2021-12-19 04:10:43 +00:00
}
}
2021-12-21 01:10:49 +00:00
private IEnumerator ShowRank()
{
// Title
yield return new WaitForSeconds(0.5f);
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
Jukebox.PlayOneShot("Rankings/ranking_title_show");
Title.SetActive(true);
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
// Desc
yield return new WaitForSeconds(2f);
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
Jukebox.PlayOneShot("Rankings/ranking_desc_show");
Desc.SetActive(true);
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
// Rating
yield return new WaitForSeconds(2f);
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
Jukebox.PlayOneShot(rank);
Rank.transform.GetChild(rankId).gameObject.SetActive(true);
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
// Epilogue
yield return new WaitForSeconds(5f);
Fade.GetComponent<Image>().DOColor(Color.black, 0.75f).OnComplete(delegate
{
StartCoroutine(ShowEpilogue());
});
}
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
private IEnumerator ShowEpilogue()
2021-12-19 04:10:43 +00:00
{
2021-12-21 01:10:49 +00:00
epilogueImage.sprite = epilogueSprites[rankId];
switch (rankId)
{
case 2:
epilogueText.text = "Blood sugar...so...low...";
break;
case 1:
epilogueText.text = "I could eat two more dinners!";
break;
case 0:
epilogueText.text = "So full! So satisfied!";
break;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
}
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
yield return new WaitForSeconds(1);
Fade.GetComponent<Image>().color = new Color(0, 0, 0, 0);
RankingHolder.SetActive(false);
Epilogue.SetActive(true);
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
switch (rankId)
{
case 0:
Jukebox.PlayOneShot("Rankings/epilogue_superb");
break;
case 1:
Jukebox.PlayOneShot("Rankings/epilogue_ok");
break;
case 2:
Jukebox.PlayOneShot("Rankings/epilogue_tryagain");
break;
}
yield return new WaitForSeconds(8);
GlobalGameManager.LoadScene(0);
2021-12-19 04:10:43 +00:00
}
2021-12-21 01:10:49 +00:00
private IEnumerator PerfectIE()
{
yield return new WaitForSeconds(8);
GlobalGameManager.LoadScene(0);
}
2021-12-19 04:10:43 +00:00
}
2021-12-21 01:10:49 +00:00
}