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

81 lines
2.2 KiB
C#
Raw Normal View History

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