This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/MainMenu/MainMenuManager.cs
2023-06-14 04:28:41 -04:00

80 lines
2.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace UI
{
public class MainMenuManager : MonoBehaviour
{
[SerializeField] private TMP_Text title;
[SerializeField] private List<TMP_Text> textList = new();
[SerializeField] private float dilateSpeed = 0.1f;
[SerializeField] private Animator cover;
private readonly string component = "_FaceDilate";
private float dilate = -1;
private readonly List<float> dilates = new();
private float initDilate;
private readonly List<float> initDilates = new();
private bool transitioning;
// Start is called before the first frame update
private void Start()
{
//initDilate = title.fontSharedMaterials[0].GetFloat(component);
initDilate = title.fontMaterials[0].GetFloat(component);
foreach (var text in textList)
{
initDilates.Add(text.fontMaterials[0].GetFloat(component));
dilates.Add(-1f);
}
textList[0].GetComponent<Button>().onClick.AddListener(LoadFirstLevel);
textList[2].GetComponent<Button>().onClick.AddListener(ExitApp);
}
// Update is called once per frame
private void Update()
{
//dilate = Mathf.Min(initDilate, dilate += Time.deltaTime);
dilate = Mathf.Lerp(dilate, initDilate, Time.deltaTime * dilateSpeed);
title.fontMaterials[0].SetFloat(component, dilate);
for (var i = 0; i < textList.Count; i++)
{
dilates[i] = Mathf.Lerp(dilates[i], initDilates[i], Time.deltaTime * dilateSpeed);
textList[i].fontMaterials[0].SetFloat(component, dilates[i]);
}
}
private void LoadFirstLevel()
{
if (!transitioning)
{
cover.Play("Cover_load_out");
transitioning = true;
StartCoroutine(_LoadFirstLevel());
}
}
private IEnumerator _LoadFirstLevel()
{
yield return new WaitForSeconds(4);
SceneManager.LoadScene(1);
}
private void ExitApp()
{
Application.Quit();
}
}
}