VictoryView.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. namespace DiamondArrow
  5. {
  6. public sealed class VictoryView : MonoBehaviour
  7. {
  8. public RawImage portrait;
  9. public Text playerName;
  10. public Text level;
  11. public Text chapter;
  12. public RawImage[] stars;
  13. public Text performance;
  14. public Text total;
  15. public Text clearBonus;
  16. public Text firstClearBonus;
  17. public Text timeBonus;
  18. public Button next;
  19. public Button home;
  20. public void ShowReward(ClearReward reward)
  21. {
  22. total.text = "+" + reward.Total;
  23. clearBonus.text = "+" + reward.basic;
  24. firstClearBonus.text = "+" + reward.first;
  25. timeBonus.text = "+" + reward.time;
  26. for (int i = 0; i < stars.Length; i++)
  27. stars[i].color = i < reward.stars ? Color.white : new Color(.48f, .37f, .55f, .48f);
  28. StartCoroutine(RevealStars(reward.stars));
  29. }
  30. IEnumerator RevealStars(int earned)
  31. {
  32. const float duration = .32f, stagger = .09f;
  33. for (float elapsed = 0; elapsed < duration + stagger * (earned - 1); elapsed += Time.unscaledDeltaTime)
  34. {
  35. for (int i = 0; i < earned; i++)
  36. {
  37. float t = Mathf.Clamp01((elapsed - i * stagger) / duration);
  38. float scale = Mathf.SmoothStep(.64f, 1f, t) + .17f * Mathf.Sin(t * Mathf.PI);
  39. stars[i].rectTransform.localScale = Vector3.one * scale;
  40. }
  41. yield return null;
  42. }
  43. for (int i = 0; i < earned; i++) stars[i].rectTransform.localScale = Vector3.one;
  44. }
  45. }
  46. }