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

80 lines
2.3 KiB
C#
Raw Permalink 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
2023-06-02 06:30:58 +02:00
namespace UI
2023-04-11 05:58:47 +02:00
{
2023-06-02 06:30:58 +02:00
public class MainMenuManager : MonoBehaviour
{
[SerializeField] private TMP_Text title;
2023-06-01 17:03:48 +02:00
2023-06-02 06:30:58 +02:00
[SerializeField] private List<TMP_Text> textList = new();
2023-06-01 17:03:48 +02:00
2023-06-02 06:30:58 +02:00
[SerializeField] private float dilateSpeed = 0.1f;
2023-06-01 17:03:48 +02:00
2023-06-02 06:30:58 +02:00
[SerializeField] private Animator cover;
2023-06-01 17:03:48 +02:00
2023-06-02 06:30:58 +02:00
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;
2023-04-11 05:58:47 +02:00
2023-06-02 06:30:58 +02:00
// Start is called before the first frame update
private void Start()
{
//initDilate = title.fontSharedMaterials[0].GetFloat(component);
initDilate = title.fontMaterials[0].GetFloat(component);
2023-04-11 05:58:47 +02:00
2023-06-01 17:03:48 +02:00
2023-06-02 06:30:58 +02:00
foreach (var text in textList)
{
initDilates.Add(text.fontMaterials[0].GetFloat(component));
dilates.Add(-1f);
}
2023-04-11 05:58:47 +02:00
2023-06-02 06:30:58 +02:00
textList[0].GetComponent<Button>().onClick.AddListener(LoadFirstLevel);
textList[2].GetComponent<Button>().onClick.AddListener(ExitApp);
}
2023-06-01 17:03:48 +02:00
2023-06-02 06:30:58 +02:00
// Update is called once per frame
private void Update()
2023-06-01 17:03:48 +02:00
{
2023-06-02 06:30:58 +02:00
//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
2023-06-02 06:30:58 +02:00
private void LoadFirstLevel()
{
2023-06-02 06:30:58 +02:00
if (!transitioning)
{
cover.Play("Cover_load_out");
transitioning = true;
StartCoroutine(_LoadFirstLevel());
}
}
2023-06-01 17:03:48 +02:00
2023-06-02 06:30:58 +02:00
private IEnumerator _LoadFirstLevel()
{
yield return new WaitForSeconds(4);
SceneManager.LoadScene(1);
}
2023-06-02 06:30:58 +02:00
private void ExitApp()
{
Application.Quit();
}
2023-04-11 05:58:47 +02:00
}
2023-06-02 06:30:58 +02:00
}