using UnityEngine;
using UnityEngine.UI;

public class GameManager : MonoBehaviour {

    private static Text[] choicesTexts = null;

    private static float choicesTextsAlpha = 0;

	void Start() {
        #if !UNITY_EDITOR
        Cursor.visible = false;
        #endif
        FadeManager.DoFadeIn(false);
        if (Application.loadedLevelName == "MainMenu") {
            choicesTexts = GameObject.Find("Choices").GetComponentsInChildren<Text>();
            choicesTextsAlpha = 0;
            InvokeRepeating("FadeTexts", 0, 1 / FadeManager.fpsStatic);
        }
        Cursor.lockState = CursorLockMode.Locked;
	}

    void Update() {
        if (Input.GetKeyDown(KeyCode.Escape)) {
            if (Application.loadedLevelName.Contains("MainScene")) {
                FadeManager.DoFadeOut("MainMenu");
            }
        }
    }

    void FadeTexts() {
        choicesTextsAlpha += 1 / (FadeManager.fpsStatic * FadeManager.fadeDurationStatic);
        foreach(Text t in choicesTexts) {
            t.color = new Color(t.color.r, t.color.g, t.color.b, choicesTextsAlpha);
        }
        if (choicesTextsAlpha > 0.99f) {
            choicesTextsAlpha = 1;
            CancelInvoke("FadeTexts");
        }
    }

    void OnLevelWasLoaded(int level) {
        if (RotateSkybox.skyboxMat != null) {
            RotateSkybox.skyboxMat.SetColor("_Tint", new Color(0.5f, 0.5f, 0.5f));
        }
    }
}