You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.3 KiB
C#

4 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
public float CustomTimeScale = 0.25f;
public GameObject Logo;
public GameObject LogoShadow;
public GameObject MenuOptions;
public float QuickFadeStep = 0.0025f;
public float SlowFadeStep = 0.0001f;
public float LogoFadeInDelay = 8.0f;
public float LogoShadowFadeInDelay = 6.0f;
public float MenuFadeInDelay = 12.0f;
private bool logoFadingIn;
private bool logoShadowFadingIn;
private bool menuFadingIn;
// Start is called before the first frame update
void Start()
{
Time.timeScale = CustomTimeScale;
var logoImage = Logo.GetComponent<Image>();
var logoShadowImage = LogoShadow.GetComponent<Image>();
logoImage.color = new Color(0.0f, 0.0f, 0.0f, 0.0f);
logoShadowImage.color = new Color(0.0f, 0.0f, 0.0f, 0.0f);
MenuOptions.SetActive(false);
StartCoroutine(startLogoFadeTimer());
StartCoroutine(startLogoShadowFadeTimer());
StartCoroutine(startMenuFadeTimer());
}
IEnumerator startLogoFadeTimer()
{
yield return new WaitForSecondsRealtime(LogoFadeInDelay);
logoFadingIn = true;
}
IEnumerator startLogoShadowFadeTimer()
{
yield return new WaitForSecondsRealtime(LogoShadowFadeInDelay);
logoShadowFadingIn = true;
}
IEnumerator startMenuFadeTimer()
{
yield return new WaitForSecondsRealtime(MenuFadeInDelay);
menuFadingIn = true;
}
public void NewGame()
{
SceneManager.LoadScene("New Game Demo Scene");
// SceneManager.LoadScene("New Game");
}
public void LoadGame()
{
SceneManager.LoadScene("Load Game");
}
public void OpenSettings()
{
SceneManager.LoadScene("Settings Menu");
}
public void QuitGame()
{
Application.Quit();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) || Input.GetButton("Submit"))
{
var logoImage = Logo.GetComponent<Image>();
var logoShadowImage = LogoShadow.GetComponent<Image>();
MenuOptions.SetActive(true);
logoShadowImage.color = new Color(0.1603774f, 0.08714567f, 0.0f, 0.67f);
logoImage.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
logoFadingIn = false;
logoShadowFadingIn = false;
menuFadingIn = false;
}
if (logoShadowFadingIn)
{
var logoShadowImage = LogoShadow.GetComponent<Image>();
if (logoShadowImage.color.a < 0.67f)
{
logoShadowImage.color = new Color(0.1603774f, 0.08714567f, 0.0f, logoShadowImage.color.a + QuickFadeStep);
}
}
if (logoFadingIn)
{
var logoImage = Logo.GetComponent<Image>();
// if (logoShadowImage.color.a < 0.3607843f)
if (logoImage.color.a < 1.0f)
{
logoImage.color = new Color(1.0f, 1.0f, 1.0f, logoImage.color.a + SlowFadeStep);
// logoShadowImage.color = new Color(0.8204432f, 0.9209584f, 0.9716981f, logoShadowImage.color.a + SlowFadeStep);
}
}
if (menuFadingIn)
{
MenuOptions.SetActive(true);
//something is weird with this... don't fade the menu in or out rn
return;
var menuOptionImages = MenuOptions.GetComponentsInChildren<Image>();
var menuOptionTextFields = MenuOptions.GetComponentsInChildren<Text>();
for (var i = 0; i < menuOptionImages.Length; i++)
{
if (menuOptionImages[i].color.a < 0.67f)
{
menuOptionImages[i].color = new Color(0.1603774f, 0.08714567f, 0.0f, menuOptionImages[i].color.a + QuickFadeStep);
}
}
for (var i = 0; i < menuOptionTextFields.Length; i++)
{
if (menuOptionTextFields[i].color.a < 0.67f)
{
menuOptionTextFields[i].color = new Color(0.1603774f, 0.08714567f, 0.0f, menuOptionTextFields[i].color.a + QuickFadeStep);
}
}
}
}
}