83 lines
2.5 KiB
C#
83 lines
2.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine.Localization;
|
|
using OpenCvSharp;
|
|
|
|
public class TutorialHintManager : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI tutorialHintText; // Assign this in the inspector with your Text UI object
|
|
public List<LocalizedString> tutorialHints; // List of tutorial hints
|
|
public float displayDuration = 5f; // Duration to display each hint in seconds
|
|
|
|
private List<LocalizedString> remainingHints;
|
|
|
|
private static TutorialHintManager _instance;
|
|
public static TutorialHintManager GetInstance() { return _instance; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (!_instance)
|
|
{
|
|
_instance = this;
|
|
}
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
if (tutorialHints.Count == 0)
|
|
{
|
|
Debug.LogError("Tutorial hints list is empty.");
|
|
return;
|
|
}
|
|
|
|
// Make a copy of the tutorial hints to track which ones have been displayed
|
|
remainingHints = new List<LocalizedString>(tutorialHints);
|
|
}
|
|
|
|
public void DisplayLoadingTutorialHint()
|
|
{
|
|
// Start displaying hints
|
|
StartCoroutine(DisplayNextHint());
|
|
}
|
|
|
|
public void StopDisplayingTutorialHints()
|
|
{
|
|
StopAllCoroutines();
|
|
tutorialHintText.text = "";
|
|
}
|
|
|
|
IEnumerator DisplayNextHint()
|
|
{
|
|
if(remainingHints.Count == 0)
|
|
{
|
|
// Make a copy of the tutorial hints to track which ones have been displayed
|
|
remainingHints = new List<LocalizedString>(tutorialHints);
|
|
}
|
|
|
|
while (remainingHints.Count > 0)
|
|
{
|
|
// Pick a random hint
|
|
int randomIndex = Random.Range(0, remainingHints.Count);
|
|
LocalizedString currentHint = remainingHints[randomIndex];
|
|
|
|
// Fetch the localized string asynchronously
|
|
yield return currentHint.GetLocalizedStringAsync().Task;
|
|
|
|
// Display the localized hint
|
|
tutorialHintText.text = currentHint.GetLocalizedString();
|
|
|
|
// Remove the displayed hint from the list to avoid repetition
|
|
remainingHints.RemoveAt(randomIndex);
|
|
|
|
// Wait for the display duration before showing the next hint
|
|
yield return new WaitForSecondsRealtime(displayDuration);
|
|
}
|
|
|
|
// Optional: Loop back if you want to restart the hints after all have been displayed
|
|
remainingHints = new List<LocalizedString>(tutorialHints);
|
|
StartCoroutine(DisplayNextHint());
|
|
}
|
|
} |