2024-03-08 15:49:30 +08:00
|
|
|
using System;
|
2024-01-27 08:49:55 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using UnityEngine;
|
2024-01-31 22:53:00 +08:00
|
|
|
using UnityEngine.Rendering.PostProcessing;
|
2024-01-27 08:49:55 +08:00
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
|
|
public class HomeWorld_Initialize : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public AudioSource audioSource;
|
|
|
|
|
public AudioClip OpenMenuClip1;
|
|
|
|
|
public float PlayVolume = 0.8f;
|
2024-03-08 15:49:30 +08:00
|
|
|
public AK.Wwise.Event StartingEvent;
|
2024-01-27 08:49:55 +08:00
|
|
|
|
|
|
|
|
private readonly System.Random random = new();
|
|
|
|
|
//[ShowOnly] public float AudioElapsedTimePlaying = 0;
|
|
|
|
|
[ShowOnly] public float AudioChangesOn = 0f;
|
2024-03-08 15:49:30 +08:00
|
|
|
[ShowOnly] bool SoundIsPlaying = false;
|
|
|
|
|
[ShowOnly] string previousEventName = "";
|
|
|
|
|
/*public List<string> AudioClipNames = new() {
|
2024-01-27 08:49:55 +08:00
|
|
|
"Gion3.ogg",
|
|
|
|
|
"OriginStation.ogg",
|
|
|
|
|
"TrainToTheFuture.ogg",
|
2024-02-27 06:34:55 +08:00
|
|
|
"AsBefore.ogg",
|
|
|
|
|
"OriginStation_Cue_127.ogg",
|
|
|
|
|
"H3P2-Default_231.ogg"
|
2024-01-27 08:49:55 +08:00
|
|
|
//"Finality-HOYO-MiX.ogg"
|
2024-03-08 15:49:30 +08:00
|
|
|
};*/
|
|
|
|
|
/*public List<string> AudioEventNames = new()
|
|
|
|
|
{
|
|
|
|
|
"Play_BGM_Df_1",
|
|
|
|
|
"Play_BGM_Df_2",
|
|
|
|
|
"Play_BGM_Df_3",
|
|
|
|
|
"Play_BGM_Df_4",
|
|
|
|
|
"Play_BGM_Df_5"
|
|
|
|
|
};*/
|
|
|
|
|
public List<AK.Wwise.Event> AudioEvents = new() { };
|
|
|
|
|
public AK.Wwise.Event CurrentEvent = null;
|
2024-01-27 08:49:55 +08:00
|
|
|
public bool useAssetBundle = false;
|
|
|
|
|
public AudioBundleLoader BundleLoader;
|
|
|
|
|
public AssetBundle AudioBundle;
|
|
|
|
|
public RectTransform SettingsPanel;
|
|
|
|
|
private Resolution GameResolutionPre;
|
2024-01-31 22:53:00 +08:00
|
|
|
public Toggle PostProcessingToggle;
|
|
|
|
|
public SettingsPanel SettingsPanelScript;
|
2024-03-08 15:49:30 +08:00
|
|
|
//static uint[] currentlyPlayingIDs = new uint[50];
|
2024-01-27 08:49:55 +08:00
|
|
|
private async void Start()
|
|
|
|
|
{
|
2024-03-08 15:49:30 +08:00
|
|
|
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += delegate
|
|
|
|
|
{
|
|
|
|
|
CurrentEvent.Stop(gameObject);
|
|
|
|
|
};
|
|
|
|
|
/*if (useAssetBundle)
|
2024-01-27 08:49:55 +08:00
|
|
|
{
|
|
|
|
|
/*BundleLoader.InitializeAudioAssetBundle();
|
2024-03-08 15:49:30 +08:00
|
|
|
new WaitForSeconds(2)
|
2024-01-27 08:49:55 +08:00
|
|
|
AudioBundle = BundleLoader.GetAudioAssetBundle();
|
|
|
|
|
OpenMenuClip1 = BundleLoader.GetAudioClipFromAssetBundle(StartingClipName);
|
|
|
|
|
}
|
|
|
|
|
else if (!OpenMenuClip1)
|
|
|
|
|
OpenMenuClip1 = await JTN.Utils.LoadClip(Path.Combine(Application.streamingAssetsPath, StartingClipName));
|
|
|
|
|
if (audioSource && OpenMenuClip1)
|
2024-03-08 15:49:30 +08:00
|
|
|
audioSource.PlayOneShot(OpenMenuClip1, PlayVolume);*/
|
2024-01-31 22:53:00 +08:00
|
|
|
/* 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;
|
|
|
|
|
}
|
|
|
|
|
}*/
|
2024-03-08 15:49:30 +08:00
|
|
|
if (!SoundIsPlaying)
|
|
|
|
|
PostNormal(StartingEvent);
|
2024-01-31 22:53:00 +08:00
|
|
|
|
|
|
|
|
if (PlayerPrefs.GetInt("PostProcessingEnabled") == 1)
|
|
|
|
|
{
|
|
|
|
|
foreach (PostProcessVolume volume in SettingsPanelScript.PostProcessingVolumes)
|
|
|
|
|
volume.enabled = true;
|
|
|
|
|
PostProcessingToggle.isOn = true;
|
2024-03-08 15:49:30 +08:00
|
|
|
}
|
|
|
|
|
else
|
2024-01-31 22:53:00 +08:00
|
|
|
{
|
|
|
|
|
foreach (PostProcessVolume volume in SettingsPanelScript.PostProcessingVolumes)
|
|
|
|
|
volume.enabled = false;
|
|
|
|
|
PostProcessingToggle.isOn = false;
|
|
|
|
|
}
|
2024-01-27 08:49:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FixedUpdate()
|
|
|
|
|
{
|
2024-03-08 15:49:30 +08:00
|
|
|
/*if (BundleLoader.AudioAssetBundle)
|
2024-01-27 08:49:55 +08:00
|
|
|
{
|
|
|
|
|
if (!audioSource.isPlaying)
|
|
|
|
|
PlayBGM();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AudioChangesOn -= Time.fixedDeltaTime;
|
|
|
|
|
}
|
|
|
|
|
if (AudioChangesOn <= 0f && AudioIsPlaying)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Clip has finished playing. Choosing a random clip...");
|
|
|
|
|
PlayBGM();
|
|
|
|
|
}
|
2024-03-08 15:49:30 +08:00
|
|
|
}*/
|
|
|
|
|
if (!SoundIsPlaying)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("An event finished playing.");
|
|
|
|
|
PlayBGM();
|
2024-01-27 08:49:55 +08:00
|
|
|
}
|
2024-03-08 15:49:30 +08:00
|
|
|
/*else
|
|
|
|
|
AudioChangesOn -= Time.fixedDeltaTime;
|
|
|
|
|
if (AudioChangesOn <= 0f && SoundIsPlaying)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("Event has finished playing. Choosing a random clip...");
|
|
|
|
|
PlayBGM();
|
|
|
|
|
}*/
|
2024-01-27 08:49:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*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;
|
|
|
|
|
}
|
|
|
|
|
}*/
|
2024-03-08 15:49:30 +08:00
|
|
|
/*public void PlayBGM()
|
2024-01-27 08:49:55 +08:00
|
|
|
{
|
|
|
|
|
string AudioClipName = AudioClipNames[random.Next(AudioClipNames.Count)];
|
|
|
|
|
Debug.Log("Attempting to load audiobundle...");
|
|
|
|
|
if (audioSource)
|
|
|
|
|
{
|
2024-03-08 15:49:30 +08:00
|
|
|
AudioClip clip = BundleLoader.GetAudioClipFromAssetBundle(AudioClipName);
|
2024-01-27 08:49:55 +08:00
|
|
|
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++;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-08 15:49:30 +08:00
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
// March 08, 2024 -- Move to Wwise
|
|
|
|
|
public void PlayBGM()
|
|
|
|
|
{
|
|
|
|
|
foreach (var @event in AudioEvents)
|
|
|
|
|
{
|
|
|
|
|
if (previousEventName.Length > 1 && CurrentEvent != null)
|
|
|
|
|
{
|
|
|
|
|
if (previousEventName == CurrentEvent.Name)
|
|
|
|
|
CurrentEvent = AudioEvents[random.Next(AudioEvents.Count)];
|
|
|
|
|
}
|
|
|
|
|
CurrentEvent = AudioEvents[random.Next(AudioEvents.Count)];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CurrentEvent.Post(gameObject, (uint)AkCallbackType.AK_EndOfEvent, BGMCallback);
|
|
|
|
|
Debug.LogError($"Posted event \"{CurrentEvent.Name}\"");
|
|
|
|
|
if (!SoundIsPlaying)
|
|
|
|
|
{
|
|
|
|
|
CurrentEvent.Post(gameObject);
|
|
|
|
|
SoundIsPlaying = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Debug.LogError($"The event \"{CurrentEvent.Name}\" is currently playing...");
|
2024-01-27 08:49:55 +08:00
|
|
|
}
|
|
|
|
|
|
2024-03-08 15:49:30 +08:00
|
|
|
public void PostNormal(AK.Wwise.Event @event)
|
|
|
|
|
{
|
|
|
|
|
CurrentEvent = @event;
|
|
|
|
|
CurrentEvent.Post(gameObject, (uint)AkCallbackType.AK_EndOfEvent, CallbackFunction);
|
|
|
|
|
Debug.LogError($"Posted event \"{CurrentEvent.Name}\"");
|
|
|
|
|
if (!SoundIsPlaying)
|
|
|
|
|
{
|
|
|
|
|
CurrentEvent.Post(gameObject);
|
|
|
|
|
SoundIsPlaying = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
Debug.LogError($"The event \"{CurrentEvent.Name}\" is currently playing...");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CallbackFunction(object in_cookie, AkCallbackType callType, object in_info)
|
|
|
|
|
{
|
|
|
|
|
if (callType == AkCallbackType.AK_EndOfEvent)
|
|
|
|
|
{
|
|
|
|
|
SoundIsPlaying = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BGMCallback(object in_cookie, AkCallbackType callType, object in_info)
|
|
|
|
|
{
|
|
|
|
|
if (callType == AkCallbackType.AK_EndOfEvent)
|
|
|
|
|
{
|
|
|
|
|
SoundIsPlaying = false;
|
|
|
|
|
PlayBGM();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-27 08:49:55 +08:00
|
|
|
}
|