| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using TMPro; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.UI; |
| | 8 | |
|
| | 9 | | namespace LoadingHUD |
| | 10 | | { |
| | 11 | |
|
| | 12 | | public class LoadingTipsRandomizer : MonoBehaviour |
| | 13 | | { |
| | 14 | | [SerializeField] internal LoadingTip[] tips; |
| | 15 | | [SerializeField] internal Image image; |
| | 16 | | [SerializeField] internal TextMeshProUGUI label; |
| 14 | 17 | | [SerializeField] internal float secondsBetweenTips = 7.5f; |
| | 18 | |
|
| 14 | 19 | | private List<LoadingTip> randomizedTips = new List<LoadingTip>(); |
| 14 | 20 | | private int tipIndex = -1; |
| | 21 | |
|
| | 22 | | private void Awake() |
| | 23 | | { |
| 104 | 24 | | randomizedTips = tips.OrderBy(x => Guid.NewGuid()).ToList(); |
| 13 | 25 | | StartCoroutine(ShowRandomTipsRoutine()); |
| 13 | 26 | | } |
| | 27 | |
|
| | 28 | | private IEnumerator ShowRandomTipsRoutine() |
| | 29 | | { |
| 0 | 30 | | while (true) |
| | 31 | | { |
| 13 | 32 | | tipIndex = (tipIndex + 1) % randomizedTips.Count; |
| 13 | 33 | | SetTip(randomizedTips[tipIndex]); |
| 13 | 34 | | yield return WaitForSecondsCache.Get(secondsBetweenTips); |
| | 35 | | } |
| | 36 | | } |
| | 37 | |
|
| | 38 | | private void SetTip(LoadingTip tip) |
| | 39 | | { |
| 13 | 40 | | label.text = tip.text; |
| 13 | 41 | | image.sprite = tip.sprite; |
| 13 | 42 | | } |
| | 43 | | } |
| | 44 | |
|
| | 45 | | [Serializable] |
| | 46 | | public class LoadingTip |
| | 47 | | { |
| | 48 | | public string text; |
| | 49 | | public Sprite sprite; |
| | 50 | | } |
| | 51 | |
|
| | 52 | | } |