109 lines
4.4 KiB
C#
109 lines
4.4 KiB
C#
using System.IO;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace JTN
|
|
{
|
|
public class Startup : MonoBehaviour
|
|
{
|
|
public bool changeResolutionAutomatically;
|
|
public bool useStartupScriptHere;
|
|
public Utils UtilsScript;
|
|
public TMP_Text MessageText;
|
|
[ShowOnly] public int MissingAssetFiles = 0;
|
|
|
|
public List<string> FilesThatMustExistInStreamingAssetsToSwitchScenes = new List<string>() { };
|
|
[ShowOnly]
|
|
public string MissingFiles = "";
|
|
public GameObject DevMenu;
|
|
public GameObject ObjectWithUIDocument;
|
|
|
|
public static string GetPlatformName()
|
|
{
|
|
switch (Application.platform)
|
|
{
|
|
case RuntimePlatform.Android:
|
|
return "Android";
|
|
case RuntimePlatform.IPhonePlayer:
|
|
return "iOS";
|
|
case RuntimePlatform.WindowsPlayer:
|
|
return "Windows";
|
|
case RuntimePlatform.LinuxPlayer:
|
|
return "Linux";
|
|
case RuntimePlatform.OSXPlayer:
|
|
return "Mac";
|
|
case RuntimePlatform.WebGLPlayer:
|
|
return "Web";
|
|
default:
|
|
return "Unsupported Platform";
|
|
}
|
|
}
|
|
|
|
public void resoChange()
|
|
{
|
|
if (!PlayerPrefs.HasKey("FullscreenState") && Application.platform != RuntimePlatform.Android)
|
|
{
|
|
if (changeResolutionAutomatically && useStartupScriptHere)
|
|
{
|
|
Screen.SetResolution(1280, 720, false);
|
|
Debug.Log("Changed game resolution to 1280x720");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
int FullscreenState = PlayerPrefs.GetInt("FullscreenState");
|
|
//if (PlayerPrefs.HasKey("FullscreenState"))
|
|
// UtilsScript.SetFullscreen(bool.Parse(PlayerPrefs.GetString("FullscreenState")));
|
|
}
|
|
}
|
|
public void ActivateContainer()
|
|
{
|
|
UIDocument UIDoc = ObjectWithUIDocument.GetComponent<UIDocument>();
|
|
VisualElement root = UIDoc.rootVisualElement;
|
|
root.Q<VisualElement>("Container").visible = true;
|
|
root.Q<VisualElement>("ExtraContent").visible = true;
|
|
}
|
|
private void Start()
|
|
{
|
|
if (useStartupScriptHere)
|
|
{
|
|
FilesThatMustExistInStreamingAssetsToSwitchScenes = new List<string>() {
|
|
Path.Combine("Audio", "GeneratedSoundBanks", GetPlatformName(), "BGM_S.bnk"),
|
|
Path.Combine("Audio", "GeneratedSoundBanks", GetPlatformName(), "Init.bnk")
|
|
};
|
|
UIDocument UIDoc = ObjectWithUIDocument.GetComponent<UIDocument>();
|
|
VisualElement root = UIDoc.rootVisualElement;
|
|
root.Q<Button>("OpenDevMenu").clicked += () =>
|
|
{
|
|
root.Q<VisualElement>("Container").visible = false;
|
|
root.Q<VisualElement>("ExtraContent").visible = false;
|
|
DevMenu.SetActive(true);
|
|
};
|
|
|
|
resoChange();
|
|
if (!PlayerPrefs.HasKey("PostProcessingEnabled"))
|
|
PlayerPrefs.SetInt("PostProcessingEnabled", 1);
|
|
foreach (string Filename in FilesThatMustExistInStreamingAssetsToSwitchScenes)
|
|
if (!File.Exists(Path.Combine(Application.streamingAssetsPath, Filename)) && Application.platform != RuntimePlatform.Android)
|
|
{
|
|
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
|
|
{
|
|
root.Q<VisualElement>("ExtraContent").visible = true;
|
|
root.Q<Label>("Message").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}";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |