Init repository
This commit is contained in:
Executable file
+123
@@ -0,0 +1,123 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class HomeWorld_Initialize : MonoBehaviour
|
||||
{
|
||||
public AudioSource audioSource;
|
||||
public AudioClip OpenMenuClip1;
|
||||
public float PlayVolume = 0.8f;
|
||||
public string StartingClipName = "UI_OpenMenu_Start.wav";
|
||||
|
||||
private readonly System.Random random = new();
|
||||
//[ShowOnly] public float AudioElapsedTimePlaying = 0;
|
||||
[ShowOnly] public float AudioChangesOn = 0f;
|
||||
[ShowOnly] public bool AudioIsPlaying = false;
|
||||
public List<string> AudioClipNames = new() {
|
||||
"Gion3.ogg",
|
||||
"OriginStation.ogg",
|
||||
"TrainToTheFuture.ogg",
|
||||
"AsBefore.ogg"
|
||||
//"Finality-HOYO-MiX.ogg"
|
||||
};
|
||||
public bool useAssetBundle = false;
|
||||
public AudioBundleLoader BundleLoader;
|
||||
public AssetBundle AudioBundle;
|
||||
public RectTransform SettingsPanel;
|
||||
private Resolution GameResolutionPre;
|
||||
public Toggle FullscreenToggle;
|
||||
|
||||
private async void Start()
|
||||
{
|
||||
if (useAssetBundle)
|
||||
{
|
||||
/*BundleLoader.InitializeAudioAssetBundle();
|
||||
new WaitForSeconds(2);*/
|
||||
AudioBundle = BundleLoader.GetAudioAssetBundle();
|
||||
OpenMenuClip1 = BundleLoader.GetAudioClipFromAssetBundle(StartingClipName);
|
||||
}
|
||||
else if (!OpenMenuClip1)
|
||||
OpenMenuClip1 = await JTN.Utils.LoadClip(Path.Combine(Application.streamingAssetsPath, StartingClipName));
|
||||
if (audioSource && OpenMenuClip1)
|
||||
audioSource.PlayOneShot(OpenMenuClip1, PlayVolume);
|
||||
/* if (SettingsPanel)
|
||||
{
|
||||
if (Screen.currentResolution.height != GameResolutionPre.height)
|
||||
{
|
||||
SettingsPanel.sizeDelta = new Vector2(SettingsPanel.sizeDelta.x, Screen.currentResolution.height);
|
||||
GameResolutionPre = Screen.currentResolution;
|
||||
}
|
||||
if (Screen.currentResolution.width != GameResolutionPre.width)
|
||||
{
|
||||
SettingsPanel.sizeDelta = new Vector2(Screen.currentResolution.width, SettingsPanel.sizeDelta.y);
|
||||
GameResolutionPre = Screen.currentResolution;
|
||||
}
|
||||
}*/
|
||||
|
||||
if (PlayerPrefs.HasKey("FullscreenState") && FullscreenToggle)
|
||||
{
|
||||
if (PlayerPrefs.GetInt("FullscreenState") == 1)
|
||||
{
|
||||
FullscreenToggle.isOn = true;
|
||||
} else
|
||||
{
|
||||
FullscreenToggle.isOn = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (BundleLoader.AudioAssetBundle)
|
||||
{
|
||||
if (!audioSource.isPlaying)
|
||||
PlayBGM();
|
||||
else
|
||||
{
|
||||
AudioChangesOn -= Time.fixedDeltaTime;
|
||||
}
|
||||
if (AudioChangesOn <= 0f && AudioIsPlaying)
|
||||
{
|
||||
Debug.LogError("Clip has finished playing. Choosing a random clip...");
|
||||
PlayBGM();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*private void Update()
|
||||
{
|
||||
if (SettingsPanel)
|
||||
{
|
||||
if (Screen.currentResolution.height != GameResolutionPre.height &&
|
||||
Screen.currentResolution.width != GameResolutionPre.width)
|
||||
{
|
||||
SettingsPanel.sizeDelta = new Vector2(Screen.currentResolution.width, Screen.currentResolution.height);
|
||||
}
|
||||
GameResolutionPre = Screen.currentResolution;
|
||||
}
|
||||
}*/
|
||||
public void PlayBGM()
|
||||
{
|
||||
string AudioClipName = AudioClipNames[random.Next(AudioClipNames.Count)];
|
||||
Debug.Log("Attempting to load audiobundle...");
|
||||
if (audioSource)
|
||||
{
|
||||
AudioClip clip = BundleLoader.GetAudioClipFromAssetBundle(/*"Default/" + */AudioClipName);
|
||||
if (!clip)
|
||||
Debug.LogError($"AudioClip {AudioClipName} could not be loaded.");
|
||||
else
|
||||
{
|
||||
audioSource.clip = clip;
|
||||
audioSource.Play();
|
||||
audioSource.clip = clip;
|
||||
AudioChangesOn = clip.length;
|
||||
Debug.LogError($"Tried playing ambience: {clip.name} with a length of {clip.length}");
|
||||
AudioIsPlaying = true;
|
||||
//TimesAmbientSet++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user