175 lines
5.4 KiB
C#
175 lines
5.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class Tutorial : MonoBehaviour
|
|
{
|
|
public static bool isInTutorial = true;
|
|
|
|
public TextMeshPro tutorialText;
|
|
public AudioSource audioSource;
|
|
public AudioClip typingBeep;
|
|
|
|
public float wordTypingSpeed = 0.3f;
|
|
public float pauseBetweenTexts = 1f;
|
|
|
|
private Coroutine typingCoroutine;
|
|
private Queue<string> textQueue = new Queue<string>();
|
|
private bool isTyping = false;
|
|
|
|
public TrashSpawner trashSpawner;
|
|
|
|
public GameObject plasticPrefab;
|
|
public GameObject metalPrefab;
|
|
public GameObject biodegradabilPrefab;
|
|
public GameObject hartiePrefab;
|
|
public GameObject cartonPrefab;
|
|
public GameObject sticlaPrefab;
|
|
public GameObject rezidualPrefab;
|
|
public GameObject sgrPrefab;
|
|
|
|
public GameObject buton;
|
|
|
|
public int tutorialStep = 0;
|
|
|
|
private void Start()
|
|
{
|
|
StartCoroutine(WaitForSeconds(5.0f));
|
|
}
|
|
|
|
private IEnumerator WaitForSeconds(float seconds)
|
|
{
|
|
yield return new WaitForSeconds(seconds);
|
|
|
|
RunTutorialStep();
|
|
|
|
}
|
|
|
|
public void RunTutorialStep()
|
|
{
|
|
switch (tutorialStep)
|
|
{
|
|
case 0:
|
|
OutputText("Salut si bine ai venit la ICI Recycle! \n\n" +
|
|
"Iata cateva informatii despre cum functioneaza aplicatia noastra. \n\n" +
|
|
"In acest tutorial, vei invata cum sa folosesti aplicatia pentru a recicla corect.");
|
|
NextStep();
|
|
break;
|
|
|
|
case 1:
|
|
trashSpawner.SpawnSpecificTrash(plasticPrefab);
|
|
OutputText("Pe masa a fost asezat un deseu de plastic. \n\nAcesta se arunca la cosul GALBEN.");
|
|
break;
|
|
|
|
case 2:
|
|
trashSpawner.SpawnSpecificTrash(metalPrefab);
|
|
OutputText("Acum, trebuie sa arunci un deseu de metal. \n\n" +
|
|
"Incearca sa gasesti un deseu de metal pe masa. Si sa il arunci tot la cosul de gunoi GALBEN.");
|
|
break;
|
|
|
|
case 3:
|
|
// Biodegradabil
|
|
trashSpawner.SpawnSpecificTrash(biodegradabilPrefab);
|
|
OutputText("Acum, trebuie sa arunci un deseu biodegradabil. \n\n" +
|
|
"Incearca sa gasesti un deseu biodegradabil pe masa. Si sa il arunci la cosul de gunoi MARO.");
|
|
break;
|
|
|
|
case 4:
|
|
// Hartie
|
|
trashSpawner.SpawnSpecificTrash(hartiePrefab);
|
|
OutputText("Acum, trebuie sa arunci un deseu de hartie. \n\n" +
|
|
"Incearca sa gasesti un deseu de hartie pe masa. Si sa il arunci la cosul de gunoi ALBASTRU.");
|
|
break;
|
|
case 5:
|
|
// Carton
|
|
trashSpawner.SpawnSpecificTrash(cartonPrefab);
|
|
OutputText("Acum, trebuie sa arunci un deseu de carton. \n\n" +
|
|
"Incearca sa gasesti un deseu de carton pe masa. Si sa il arunci la cosul de gunoi ALBASTRU.");
|
|
break;
|
|
case 6:
|
|
// Sticla
|
|
trashSpawner.SpawnSpecificTrash(sticlaPrefab);
|
|
OutputText("Acum, trebuie sa arunci un deseu de sticla. \n\n" +
|
|
"Incearca sa gasesti un deseu de sticla pe masa. Si sa il arunci la cosul de gunoi VERDE.");
|
|
break;
|
|
case 7:
|
|
// Rezidual
|
|
trashSpawner.SpawnSpecificTrash(rezidualPrefab);
|
|
OutputText("Acum, trebuie sa arunci un deseu rezidual. \n\n" +
|
|
"Incearca sa gasesti un deseu rezidual pe masa. Si sa il arunci la cosul de gunoi NEGRU.");
|
|
break;
|
|
case 8:
|
|
// Sgr
|
|
trashSpawner.SpawnSpecificTrash(sgrPrefab);
|
|
OutputText("Acum, trebuie sa arunci un deseu SGR. \n\n" +
|
|
"Incearca sa gasesti un deseu SGR pe masa. Si sa il arunci la aparatul SGR.");
|
|
|
|
|
|
break;
|
|
case 9:
|
|
OutputText("Tutorial complet!");
|
|
buton.SetActive(true);
|
|
isInTutorial = false;
|
|
|
|
break;
|
|
default:
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void NextStep()
|
|
{
|
|
tutorialStep++;
|
|
RunTutorialStep();
|
|
}
|
|
|
|
public void PlayStep()
|
|
{
|
|
RunTutorialStep(); // reia pasul curent
|
|
}
|
|
|
|
public void OutputText(string text)
|
|
{
|
|
textQueue.Enqueue(text);
|
|
|
|
if (!isTyping)
|
|
{
|
|
typingCoroutine = StartCoroutine(ProcessQueue());
|
|
}
|
|
}
|
|
|
|
private IEnumerator ProcessQueue()
|
|
{
|
|
isTyping = true;
|
|
|
|
while (textQueue.Count > 0)
|
|
{
|
|
string currentText = textQueue.Dequeue();
|
|
tutorialText.text = "";
|
|
|
|
string[] words = currentText.Split(' ');
|
|
for (int i = 0; i < words.Length; i++)
|
|
{
|
|
tutorialText.text += words[i];
|
|
|
|
if (typingBeep != null)
|
|
{
|
|
audioSource.pitch = Random.Range(0.85f, 1.4f);
|
|
audioSource.PlayOneShot(typingBeep, 0.9f);
|
|
}
|
|
|
|
if (i < words.Length - 1)
|
|
tutorialText.text += " ";
|
|
|
|
yield return new WaitForSeconds(wordTypingSpeed);
|
|
}
|
|
|
|
yield return new WaitForSeconds(pauseBetweenTexts);
|
|
}
|
|
|
|
isTyping = false;
|
|
}
|
|
}
|