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

76 lines
2.1 KiB
C#
Raw Normal View History

2023-04-11 05:58:47 +02:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
2023-06-01 17:03:48 +02:00
using UnityEngine.UI;
2023-04-11 05:58:47 +02:00
public class MainMenuManager : MonoBehaviour
{
2023-06-01 17:03:48 +02:00
[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";
2023-04-11 05:58:47 +02:00
private float dilate = -1;
2023-06-01 17:03:48 +02:00
private readonly List<float> dilates = new();
2023-04-11 05:58:47 +02:00
private float initDilate;
2023-06-01 17:03:48 +02:00
private readonly List<float> initDilates = new();
private bool transitioning;
2023-04-11 05:58:47 +02:00
// Start is called before the first frame update
2023-06-01 17:03:48 +02:00
private void Start()
2023-04-11 05:58:47 +02:00
{
//initDilate = title.fontSharedMaterials[0].GetFloat(component);
initDilate = title.fontMaterials[0].GetFloat(component);
2023-06-01 17:03:48 +02:00
foreach (var text in textList)
2023-04-11 05:58:47 +02:00
{
2023-06-01 17:03:48 +02:00
initDilates.Add(text.fontMaterials[0].GetFloat(component));
dilates.Add(-1f);
}
2023-04-11 05:58:47 +02:00
2023-06-01 17:03:48 +02:00
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]);
2023-04-11 05:58:47 +02:00
}
}
2023-06-01 17:03:48 +02:00
private void LoadFirstLevel()
2023-04-11 05:58:47 +02:00
{
if (!transitioning)
{
cover.Play("Cover_load_out");
transitioning = true;
StartCoroutine(_LoadFirstLevel());
}
}
2023-06-01 17:03:48 +02:00
private IEnumerator _LoadFirstLevel()
{
yield return new WaitForSeconds(4);
2023-04-11 05:58:47 +02:00
SceneManager.LoadScene(1);
}
2023-06-01 17:03:48 +02:00
private void ExitApp()
2023-04-11 05:58:47 +02:00
{
Application.Quit();
}
2023-06-01 17:03:48 +02:00
}