124 lines
3.3 KiB
C#
Executable File
124 lines
3.3 KiB
C#
Executable File
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class TutorialScreen : MonoBehaviour
|
|
{
|
|
public bool FreezeTime=false;
|
|
public Transform messageParent;
|
|
public Button btn_next;
|
|
public Button[] additional_next_buttons;
|
|
public int delayBeforeAppear;
|
|
public bool hideNextButtonOnStart = true;
|
|
public UnityEvent OnNextClicked;
|
|
|
|
Dictionary<TMP_Text, string> messages;
|
|
|
|
void Awake()
|
|
{
|
|
btn_next.onClick.AddListener(OnNextButton);
|
|
foreach (Button btn in additional_next_buttons)
|
|
{
|
|
btn.onClick.AddListener(OnNextButton);
|
|
}
|
|
|
|
EventTrigger.Entry entry = new EventTrigger.Entry();
|
|
entry.eventID = EventTriggerType.PointerDown;
|
|
entry.callback.AddListener((eventData) => { SkipText(); });
|
|
|
|
GetComponent<EventTrigger>().triggers.Add(entry);
|
|
|
|
}
|
|
|
|
public void Show()
|
|
{
|
|
if(FreezeTime){
|
|
Time.timeScale = 0;
|
|
}
|
|
Debug.Log($"is GO null? :{gameObject == null}");
|
|
gameObject.SetActive(true);
|
|
ShowTexts();
|
|
}
|
|
bool textSkipped = false;
|
|
void ShowTexts()
|
|
{
|
|
StartCoroutine(showTexts());
|
|
}
|
|
|
|
IEnumerator showTexts(){
|
|
|
|
if (hideNextButtonOnStart) { btn_next.gameObject.SetActive(false); }
|
|
int typewriteDelay = 0;
|
|
if (messages == null)
|
|
{
|
|
messages = new Dictionary<TMP_Text, string>();
|
|
TMP_Text[] texts = messageParent.GetComponentsInChildren<TMP_Text>();
|
|
foreach (TMP_Text text in texts)
|
|
{
|
|
messages.Add(text, text.text.Replace("{Player}", DBmanager.username ?? "Dev"));
|
|
Debug.Log(text.text);
|
|
|
|
text.text = "";
|
|
}
|
|
}
|
|
TMP_Text lastTxt = null;
|
|
foreach (KeyValuePair<TMP_Text, string> 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;
|
|
}
|
|
if(!textSkipped){
|
|
yield return new WaitForSecondsRealtime(0.02f);
|
|
}
|
|
}
|
|
yield return new WaitForSecondsRealtime(0.05f);
|
|
|
|
lastTxt = message.Key;
|
|
}
|
|
|
|
textSkipped=false;
|
|
btn_next.gameObject.SetActive(true);
|
|
|
|
yield return new WaitForSecondsRealtime(0.25f);
|
|
|
|
lastTxt.text += " ";
|
|
}
|
|
|
|
void SkipText()
|
|
{
|
|
textSkipped=true;
|
|
}
|
|
|
|
public void Hide()
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public void OnNextButton()
|
|
{
|
|
if(FreezeTime){
|
|
Time.timeScale = 1;
|
|
}
|
|
OnNextClicked.Invoke();
|
|
Debug.Log("Next button clicked");
|
|
TutorialManager.NextClicked();
|
|
AudioManager.instnace.UIClick();
|
|
}
|
|
}
|