using System.Collections; using System.Collections.Generic; using System.Threading.Tasks; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; public class TutorialScreen : MonoBehaviour { public Transform messageParent; public Button btn_next; public Button[] additional_next_buttons; public int delayBeforeAppear; public bool hideNextButtonOnStart=true; public UnityEvent OnNextClicked; Dictionary messages; void Awake(){ btn_next.onClick.AddListener(OnNextButton); foreach(Button btn in additional_next_buttons){ btn.onClick.AddListener(OnNextButton); } } public void Show(){ gameObject.SetActive(true); ShowTexts(); } async void ShowTexts(){ if(hideNextButtonOnStart){btn_next.gameObject.SetActive(false);} int typewriteDelay = 0; if(messages == null){ messages = new Dictionary(); TMP_Text[] texts = messageParent.GetComponentsInChildren(); foreach(TMP_Text text in texts){ messages.Add(text, text.text); text.text = ""; } } foreach(KeyValuePair message in messages){ message.Key.text=""; Debug.Log(message.Value); for(int i=0; i < message.Value.Length; i++){ message.Key.text+=message.Value.ToCharArray()[i]; if(typewriteDelay< 4){ typewriteDelay++; }else{ AudioManager.instnace.TypeWriter(); typewriteDelay=0; } await Task.Delay(20); } await Task.Delay(500); } btn_next.gameObject.SetActive(true); } public void Hide(){ gameObject.SetActive(false); } public void OnNextButton(){ OnNextClicked.Invoke(); Debug.Log("Next button clicked"); TutorialManager.NextClicked(); AudioManager.instnace.UIClick(); } }