Files
JourneyToNowhere_Unity/Assets/Scripts/Startup.cs
T
2024-01-27 08:49:55 +08:00

69 lines
2.6 KiB
C#
Executable File

using System.IO;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
namespace JTN
{
public class Startup : MonoBehaviour
{
public bool changeResolutionAutomatically;
public bool useStartupScriptHere;
public TMP_Text MessageText;
[ShowOnly] public int MissingAssetFiles = 0;
public List<string> FilesThatMustExistInStreamingAssetsToSwitchScenes = new List<string>() {
Path.Combine("Audio", "AudioAssets.bunl")
};
public string MissingFiles = "";
public void resoChange()
{
if (!PlayerPrefs.HasKey("FullscreenState"))
{
if (changeResolutionAutomatically && useStartupScriptHere)
{
Screen.SetResolution(1533, 720, false);
Debug.Log("Changed game resolution to 1533x720");
}
}
else
{
int FullscreenState = PlayerPrefs.GetInt("FullscreenState");
if (FullscreenState == 0)
{
Screen.fullScreenMode = FullScreenMode.Windowed;
Screen.SetResolution(1533, 720, false);
Debug.Log("Changed game resolution to 1533x720");
} else
{
Debug.Log($"Set game resolution to {Screen.currentResolution} (fullscreen)");
Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
}
}
}
private void Start()
{
if (useStartupScriptHere)
{
resoChange();
foreach (string Filename in FilesThatMustExistInStreamingAssetsToSwitchScenes)
if (!File.Exists(Path.Combine(Application.streamingAssetsPath, Filename)))
{
MissingAssetFiles++;
MissingFiles += "\n" + Path.Combine(Application.streamingAssetsPath, Filename);
}
if (MissingAssetFiles == 0)
{
Debug.Log("No missing files were found. Loading next scene.");
JTN.Utils.SwitchScene("HomeWorld_Journey1");
}
else
{
MessageText.text = $"{MissingAssetFiles} asset(s) that are required to run the game have been moved, deleted or renamed.\n\nSearched for but was not found:<size=28>{MissingFiles}";
}
}
}
}
}