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;
|
|
|
|
|
|
2023-01-24 19:31:49 +00:00
|
|
|
|
using HeavenStudio.Common;
|
|
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
|
namespace HeavenStudio
|
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
|
|
|
|
|
2022-10-13 16:20:48 +00:00
|
|
|
|
public static string buildTime = "00/00/0000 00: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
|
|
|
|
|
2022-07-09 02:11:55 +00:00
|
|
|
|
public static int CustomScreenWidth = 1280;
|
|
|
|
|
public static int CustomScreenHeight = 720;
|
|
|
|
|
|
|
|
|
|
public static readonly (int width, int height)[] DEFAULT_SCREEN_SIZES = new[] { (1280, 720), (1920, 1080), (2560, 1440), (3840, 2160)};
|
|
|
|
|
public static readonly string[] DEFAULT_SCREEN_SIZES_STRING = new[] { "1280x720", "1920x1080", "2560x1440", "3840x2160", "Custom" };
|
|
|
|
|
public static int ScreenSizeIndex = 0;
|
|
|
|
|
|
2022-07-10 21:39:14 +00:00
|
|
|
|
public static float MasterVolume = 0.8f;
|
2023-03-12 02:56:26 +00:00
|
|
|
|
public static int currentDspSize = 512;
|
2023-03-11 04:51:22 +00:00
|
|
|
|
public static int currentSampleRate = 44100;
|
|
|
|
|
public static readonly int[] DSP_BUFFER_SIZES =
|
|
|
|
|
{
|
|
|
|
|
128, 256, 340, 480, 512, 1024
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static readonly int[] SAMPLE_RATES =
|
|
|
|
|
{
|
|
|
|
|
22050, 44100, 48000, 88200, 96000,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static RenderTexture GameRenderTexture;
|
|
|
|
|
public static RenderTexture OverlayRenderTexture;
|
2022-07-10 21:39:14 +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-17 02:31:49 +00:00
|
|
|
|
|
2023-01-24 19:31:49 +00:00
|
|
|
|
PersistentDataManager.LoadSettings();
|
|
|
|
|
|
|
|
|
|
ScreenSizeIndex = PersistentDataManager.gameSettings.resolutionIndex;
|
|
|
|
|
CustomScreenWidth = PersistentDataManager.gameSettings.resolutionWidth;
|
|
|
|
|
CustomScreenHeight = PersistentDataManager.gameSettings.resolutionHeight;
|
|
|
|
|
|
|
|
|
|
ChangeMasterVolume(PersistentDataManager.gameSettings.masterVolume);
|
2023-03-11 04:51:22 +00:00
|
|
|
|
|
|
|
|
|
if (PersistentDataManager.gameSettings.dspSize == 0)
|
2023-03-12 02:56:26 +00:00
|
|
|
|
PersistentDataManager.gameSettings.dspSize = 512;
|
2023-03-11 04:51:22 +00:00
|
|
|
|
if (PersistentDataManager.gameSettings.sampleRate == 0)
|
|
|
|
|
PersistentDataManager.gameSettings.sampleRate = 44100;
|
|
|
|
|
currentDspSize = PersistentDataManager.gameSettings.dspSize;
|
|
|
|
|
currentSampleRate = PersistentDataManager.gameSettings.sampleRate;
|
|
|
|
|
|
|
|
|
|
ChangeAudioSettings(currentDspSize, currentSampleRate);
|
|
|
|
|
|
2023-01-24 19:31:49 +00:00
|
|
|
|
if (PersistentDataManager.gameSettings.isFullscreen)
|
|
|
|
|
{
|
|
|
|
|
Screen.SetResolution(Display.main.systemWidth, Display.main.systemHeight, FullScreenMode.FullScreenWindow);
|
|
|
|
|
Screen.fullScreen = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Screen.fullScreen = false;
|
|
|
|
|
ChangeScreenSize();
|
|
|
|
|
}
|
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;
|
2022-06-22 19:55:12 +00:00
|
|
|
|
Starpelly.OS.ChangeWindowTitle("Heaven Studio DEMO");
|
2022-09-18 20:48:14 +00:00
|
|
|
|
QualitySettings.maxQueuedFrames = 1;
|
2022-07-24 00:36:10 +00:00
|
|
|
|
PlayerInput.InitInputControllers();
|
2022-10-13 16:20:48 +00:00
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
buildTime = "(EDITOR) " + System.DateTime.UtcNow.ToString("dd/MM/yyyy hh:mm:ss");
|
|
|
|
|
#else
|
|
|
|
|
buildTime = AppInfo.Date.ToString("dd/MM/yyyy hh:mm:ss");
|
|
|
|
|
#endif
|
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 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); }); });
|
|
|
|
|
}
|
2022-07-08 22:49:15 +00:00
|
|
|
|
|
|
|
|
|
public static void WindowFullScreen()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("WindowFullScreen");
|
2022-07-09 02:11:55 +00:00
|
|
|
|
if (!Screen.fullScreen)
|
2022-07-08 22:49:15 +00:00
|
|
|
|
{
|
|
|
|
|
// Set the resolution to the display's current resolution
|
2022-07-09 02:11:55 +00:00
|
|
|
|
Screen.SetResolution(Display.main.systemWidth, Display.main.systemHeight, FullScreenMode.FullScreenWindow);
|
|
|
|
|
Screen.fullScreen = true;
|
2023-01-24 19:31:49 +00:00
|
|
|
|
PersistentDataManager.gameSettings.isFullscreen = true;
|
2022-07-08 22:49:15 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-07-09 02:11:55 +00:00
|
|
|
|
Screen.SetResolution(1280, 720, FullScreenMode.Windowed);
|
|
|
|
|
Screen.fullScreen = false;
|
2023-01-24 19:31:49 +00:00
|
|
|
|
PersistentDataManager.gameSettings.isFullscreen = false;
|
2022-07-08 22:49:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-21 01:10:49 +00:00
|
|
|
|
|
2022-07-09 02:11:55 +00:00
|
|
|
|
public static void ChangeScreenSize()
|
|
|
|
|
{
|
|
|
|
|
FullScreenMode mode = Screen.fullScreenMode;
|
|
|
|
|
if (ScreenSizeIndex == DEFAULT_SCREEN_SIZES_STRING.Length - 1)
|
|
|
|
|
{
|
|
|
|
|
Screen.SetResolution(CustomScreenWidth, CustomScreenHeight, mode);
|
2023-01-24 19:31:49 +00:00
|
|
|
|
PersistentDataManager.gameSettings.resolutionWidth = CustomScreenWidth;
|
|
|
|
|
PersistentDataManager.gameSettings.resolutionHeight = CustomScreenHeight;
|
|
|
|
|
PersistentDataManager.gameSettings.resolutionIndex = DEFAULT_SCREEN_SIZES_STRING.Length - 1;
|
2022-07-09 02:11:55 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Screen.SetResolution(DEFAULT_SCREEN_SIZES[ScreenSizeIndex].width, DEFAULT_SCREEN_SIZES[ScreenSizeIndex].height, mode);
|
2023-01-24 19:31:49 +00:00
|
|
|
|
PersistentDataManager.gameSettings.resolutionWidth = DEFAULT_SCREEN_SIZES[ScreenSizeIndex].width;
|
|
|
|
|
PersistentDataManager.gameSettings.resolutionHeight = DEFAULT_SCREEN_SIZES[ScreenSizeIndex].height;
|
|
|
|
|
PersistentDataManager.gameSettings.resolutionIndex = ScreenSizeIndex;
|
2022-07-09 02:11:55 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-10 21:39:14 +00:00
|
|
|
|
|
2023-03-11 04:51:22 +00:00
|
|
|
|
public static void ResetGameRenderTexture()
|
|
|
|
|
{
|
2023-03-12 02:56:26 +00:00
|
|
|
|
// keep 16:9 aspect ratio
|
|
|
|
|
int width = Screen.width;
|
|
|
|
|
int height = Screen.height;
|
|
|
|
|
if (width / 16f > height / 9f)
|
|
|
|
|
{
|
|
|
|
|
width = (int)(height / 9f * 16f);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
height = (int)(width / 16f * 9f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GameRenderTexture.width = width;
|
|
|
|
|
GameRenderTexture.height = height;
|
2023-03-11 04:51:22 +00:00
|
|
|
|
|
2023-03-12 02:56:26 +00:00
|
|
|
|
OverlayRenderTexture.width = width;
|
|
|
|
|
OverlayRenderTexture.height = height;
|
2023-03-11 04:51:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-10 21:39:14 +00:00
|
|
|
|
public static void ChangeMasterVolume(float value)
|
|
|
|
|
{
|
|
|
|
|
MasterVolume = value;
|
|
|
|
|
AudioListener.volume = MasterVolume;
|
|
|
|
|
}
|
2022-07-24 00:36:10 +00:00
|
|
|
|
|
2023-03-11 04:51:22 +00:00
|
|
|
|
public static void ChangeAudioSettings(int dspSize, int sampleRate)
|
|
|
|
|
{
|
|
|
|
|
// don't reset audio if no changes are done
|
|
|
|
|
AudioConfiguration config = AudioSettings.GetConfiguration();
|
|
|
|
|
if (dspSize == config.dspBufferSize && sampleRate == config.sampleRate) return;
|
|
|
|
|
currentDspSize = dspSize;
|
|
|
|
|
currentSampleRate = sampleRate;
|
|
|
|
|
|
|
|
|
|
config.dspBufferSize = currentDspSize;
|
|
|
|
|
config.sampleRate = currentSampleRate;
|
|
|
|
|
AudioSettings.Reset(config);
|
|
|
|
|
|
|
|
|
|
PersistentDataManager.gameSettings.dspSize = currentDspSize;
|
|
|
|
|
PersistentDataManager.gameSettings.sampleRate = currentSampleRate;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-24 00:36:10 +00:00
|
|
|
|
void OnApplicationQuit()
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Disconnecting JoyShocks...");
|
|
|
|
|
PlayerInput.DisconnectJoyshocks();
|
|
|
|
|
}
|
2022-07-09 02:11:55 +00:00
|
|
|
|
}
|
2022-06-22 19:55:12 +00:00
|
|
|
|
}
|