2024-01-27 08:49:55 +08:00
using System.IO ;
using TMPro ;
using UnityEngine ;
2024-02-05 00:40:21 +08:00
using UnityEngine.UIElements ;
2024-01-27 08:49:55 +08:00
using System.Collections.Generic ;
namespace JTN
{
public class Startup : MonoBehaviour
{
public bool changeResolutionAutomatically ;
public bool useStartupScriptHere ;
2024-02-04 17:52:19 +08:00
public Utils UtilsScript ;
2024-01-27 08:49:55 +08:00
public TMP_Text MessageText ;
[ShowOnly] public int MissingAssetFiles = 0 ;
public List < string > FilesThatMustExistInStreamingAssetsToSwitchScenes = new List < string > ( ) {
2024-02-03 18:15:47 +08:00
Path . Combine ( "Audio" , "Audio.blk" )
2024-01-27 08:49:55 +08:00
} ;
2024-02-03 18:15:47 +08:00
[ShowOnly]
2024-01-27 08:49:55 +08:00
public string MissingFiles = "" ;
2024-02-05 00:40:21 +08:00
public GameObject DevMenu ;
public GameObject ObjectWithUIDocument ;
2024-01-27 08:49:55 +08:00
public void resoChange ( )
{
if ( ! PlayerPrefs . HasKey ( "FullscreenState" ) )
{
if ( changeResolutionAutomatically & & useStartupScriptHere )
{
2024-02-05 00:40:21 +08:00
Screen . SetResolution ( 1533 , 862 , false ) ;
2024-01-27 08:49:55 +08:00
Debug . Log ( "Changed game resolution to 1533x720" ) ;
}
}
else
{
int FullscreenState = PlayerPrefs . GetInt ( "FullscreenState" ) ;
2024-02-04 17:52:19 +08:00
if ( PlayerPrefs . HasKey ( "FullscreenState" ) )
UtilsScript . SetFullscreen ( bool . Parse ( PlayerPrefs . GetString ( "FullscreenState" ) ) ) ;
2024-01-27 08:49:55 +08:00
}
}
2024-02-05 00:40:21 +08:00
public void ActivateContainer ( )
{
UIDocument UIDoc = ObjectWithUIDocument . GetComponent < UIDocument > ( ) ;
VisualElement root = UIDoc . rootVisualElement ;
root . Q < VisualElement > ( "Container" ) . visible = true ;
}
2024-01-27 08:49:55 +08:00
private void Start ( )
{
if ( useStartupScriptHere )
{
2024-02-05 00:40:21 +08:00
UIDocument UIDoc = ObjectWithUIDocument . GetComponent < UIDocument > ( ) ;
VisualElement root = UIDoc . rootVisualElement ;
root . Q < Button > ( "OpenDevMenu" ) . clicked + = ( ) = > {
root . Q < VisualElement > ( "Container" ) . visible = false ;
DevMenu . SetActive ( true ) ;
} ;
2024-01-27 08:49:55 +08:00
resoChange ( ) ;
2024-01-31 22:53:00 +08:00
if ( ! PlayerPrefs . HasKey ( "PostProcessingEnabled" ) )
PlayerPrefs . SetInt ( "PostProcessingEnabled" , 1 ) ;
2024-01-27 08:49:55 +08:00
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
{
2024-02-05 00:40:21 +08:00
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}" ;
2024-01-27 08:49:55 +08:00
}
}
}
}
}