97 lines
3.2 KiB
C#
97 lines
3.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class NewMainMenu_SettingsSubMenu : MonoBehaviour
|
|
{
|
|
public List<TextMeshProUGUI> BackgroundTextLines = new List<TextMeshProUGUI>();
|
|
|
|
[SerializeField]
|
|
private List<int> BackgroundTextMaxCount = new List<int>();
|
|
|
|
private bool wasEnabled;
|
|
|
|
private bool AllTextShown;
|
|
|
|
private void Awake()
|
|
{
|
|
foreach (TextMeshProUGUI backgroundTextLine in BackgroundTextLines)
|
|
{
|
|
BackgroundTextMaxCount.Add(backgroundTextLine.text.Length);
|
|
backgroundTextLine.maxVisibleCharacters = 0;
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!wasEnabled && base.gameObject.activeSelf)
|
|
{
|
|
wasEnabled = true;
|
|
StartCoroutine(ShowBackgroundText());
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
wasEnabled = false;
|
|
AllTextShown = false;
|
|
foreach (TextMeshProUGUI backgroundTextLine in BackgroundTextLines)
|
|
{
|
|
backgroundTextLine.maxVisibleCharacters = 0;
|
|
}
|
|
}
|
|
|
|
private IEnumerator ShowBackgroundText()
|
|
{
|
|
if (!SettingsManager.Instance.GetBoolSettingValue("SimpleVFX"))
|
|
{
|
|
List<TextMeshProUGUI> finishedTexts = new List<TextMeshProUGUI>();
|
|
while (!AllTextShown)
|
|
{
|
|
yield return null;
|
|
foreach (TextMeshProUGUI backgroundTextLine in BackgroundTextLines)
|
|
{
|
|
if (!finishedTexts.Contains(backgroundTextLine) && backgroundTextLine.maxVisibleCharacters >= backgroundTextLine.text.Length)
|
|
{
|
|
finishedTexts.Add(backgroundTextLine);
|
|
}
|
|
else if (backgroundTextLine.maxVisibleCharacters < backgroundTextLine.text.Length)
|
|
{
|
|
float num = 100 + Random.Range(-60, -10);
|
|
backgroundTextLine.maxVisibleCharacters += Mathf.CeilToInt(num * Time.deltaTime);
|
|
backgroundTextLine.maxVisibleCharacters = Mathf.Clamp(backgroundTextLine.maxVisibleCharacters, 0, backgroundTextLine.text.Length);
|
|
NewMainMenuManager.instance.MenuSource.PlayOneShot(NewMainMenuManager.instance.SFX_MenuClick);
|
|
}
|
|
}
|
|
if (CompareTextLists(finishedTexts, BackgroundTextLines))
|
|
{
|
|
AllTextShown = true;
|
|
MonoBehaviour.print("all text shown");
|
|
}
|
|
}
|
|
yield break;
|
|
}
|
|
foreach (TextMeshProUGUI backgroundTextLine2 in BackgroundTextLines)
|
|
{
|
|
backgroundTextLine2.maxVisibleCharacters = backgroundTextLine2.text.Length;
|
|
}
|
|
}
|
|
|
|
private bool CompareTextLists(List<TextMeshProUGUI> list1, List<TextMeshProUGUI> list2)
|
|
{
|
|
if (list1.Count != list2.Count)
|
|
{
|
|
return false;
|
|
}
|
|
for (int i = 0; i < list1.Count; i++)
|
|
{
|
|
if (list1[i].text != list2[i].text)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|