StationObscurum/Assets/Scripts/MainMenu/MainMenuManager.cs

141 lines
4.0 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-11-13 03:08:23 +01:00
using Steamworks;
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
2023-11-15 04:11:47 +01:00
[SerializeField] private Animator cameraAnimator;
[SerializeField] private MainMenuSettingsManager settingsManager;
[SerializeField] private Canvas creditsCanvas;
private bool isAnimating = false;
private bool isDown = false;
private static MainMenuManager instance;
public static MainMenuManager Instance { get { return instance; } }
private void Awake()
{
instance = this;
}
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
{
2023-11-15 04:11:47 +01:00
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);
2023-11-15 04:11:47 +01:00
textList[1].GetComponent<Button>().onClick.AddListener(LoadSettings);
2023-06-01 17:03:48 +02:00
textList[2].GetComponent<Button>().onClick.AddListener(ExitApp);
2023-11-15 04:11:47 +01:00
textList[3].GetComponent<Button>().onClick.AddListener(LoadCredits);
2023-11-13 03:08:23 +01:00
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Confined;
2023-11-15 04:11:47 +01:00
this.creditsCanvas.gameObject.SetActive(false);
this.settingsManager.gameObject.SetActive(false);
2023-06-01 17:03:48 +02:00
}
// 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
{
2023-11-13 03:08:23 +01:00
if (SteamManager.Initialized)
{
Steamworks.SteamUserStats.GetAchievement("ENTER_THE_STATION", out bool achievementCompleted);
if (!achievementCompleted)
{
SteamUserStats.SetAchievement("ENTER_THE_STATION");
SteamUserStats.StoreStats();
SteamAPI.RunCallbacks();
}
}
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-11-15 04:11:47 +01:00
private void LoadSettings()
{
ToggleCamera();
this.creditsCanvas.gameObject.SetActive(false);
this.settingsManager.gameObject.SetActive(true);
}
private void LoadCredits()
{
ToggleCamera();
this.creditsCanvas.gameObject.SetActive(true);
this.settingsManager.gameObject.SetActive(false);
}
public void ToggleCamera()
{
if(!isAnimating)
StartCoroutine(_ToggleCamera());
}
private IEnumerator _ToggleCamera()
{
cameraAnimator.Play(isDown?"CameraUp":"CameraDown");
isAnimating = true;
yield return new WaitForSeconds(1.5f);
isAnimating = false;
isDown = !isDown;
}
2023-06-01 17:03:48 +02:00
}