HeavenStudioPlus/Assets/Scripts/GlobalGameManager.cs

102 lines
3.1 KiB
C#
Raw Normal View History

2021-12-19 04:10:43 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using DG.Tweening;
2021-12-21 01:10:49 +00:00
namespace RhythmHeavenMania
2021-12-19 04:10:43 +00:00
{
2021-12-21 01:10:49 +00:00
public class GlobalGameManager : MonoBehaviour
{
public static GlobalGameManager instance { get; set; }
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public static int loadedScene;
public int lastLoadedScene;
public static float fadeDuration;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public GameObject loadScenePrefab;
public GameObject hourGlass;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public static string levelLocation;
public static bool officialLevel;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public enum Scenes : int
{
SplashScreen = 0,
Menu = 1,
Editor = 2,
Game = 3
}
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
public static void Init()
{
BasicCheck();
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
loadedScene = 0;
fadeDuration = 0;
2022-01-29 21:59:20 +00:00
/*GameObject ui = new GameObject();
ui.AddComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("tempBuildUI");
2022-01-18 00:40:23 +00:00
ui.GetComponent<SpriteRenderer>().sortingOrder = 1000;
ui.layer = 5;
2022-01-29 21:59:20 +00:00
ui.name = "tempBuildUI";*/
2021-12-21 01:10:49 +00:00
}
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public void Awake()
{
Init();
DontDestroyOnLoad(this.gameObject);
instance = this;
Starpelly.OS.Windows.ChangeWindowTitle($"Rhythm Heaven Mania DEMO");
}
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public static GameObject CreateFade()
{
GameObject fade = new GameObject();
DontDestroyOnLoad(fade);
fade.transform.localScale = new Vector3(4000, 4000);
SpriteRenderer sr = fade.AddComponent<SpriteRenderer>();
sr.sprite = Resources.Load<Sprite>("Sprites/GeneralPurpose/Square");
sr.sortingOrder = 20000;
fade.layer = 5;
return fade;
}
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public static void BasicCheck()
2021-12-19 04:10:43 +00:00
{
2021-12-21 01:10:49 +00:00
if (FindGGM() == null)
{
GameObject GlobalGameManager = new GameObject("GlobalGameManager");
GlobalGameManager.name = "GlobalGameManager";
GlobalGameManager.AddComponent<GlobalGameManager>();
}
2021-12-19 04:10:43 +00:00
}
2021-12-21 01:10:49 +00:00
public static GameObject FindGGM()
{
if (GameObject.Find("GlobalGameManager") != null)
return GameObject.Find("GlobalGameManager");
else
return null;
}
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
public static void LoadScene(int sceneIndex, float duration = 0.35f)
{
print("bruh");
BasicCheck();
loadedScene = sceneIndex;
fadeDuration = duration;
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
// DOTween.Clear(true);
// SceneManager.LoadScene(sceneIndex);
2021-12-19 04:10:43 +00:00
2021-12-21 01:10:49 +00:00
GameObject fade = CreateFade();
fade.GetComponent<SpriteRenderer>().color = new Color(0, 0, 0, 0);
fade.GetComponent<SpriteRenderer>().DOColor(Color.black, fadeDuration).OnComplete(() => { SceneManager.LoadScene(loadedScene); fade.GetComponent<SpriteRenderer>().DOColor(new Color(0, 0, 0, 0), fadeDuration).OnComplete(() => { Destroy(fade); }); });
}
2021-12-19 04:10:43 +00:00
}
2021-12-21 01:10:49 +00:00
}