update audio + switch to wwise

This commit is contained in:
mangorifo
2024-03-08 15:49:30 +08:00
parent 578388f144
commit d59237af1c
510 changed files with 110625 additions and 102 deletions
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
@@ -9,13 +10,14 @@ public class HomeWorld_Initialize : MonoBehaviour
public AudioSource audioSource;
public AudioClip OpenMenuClip1;
public float PlayVolume = 0.8f;
public string StartingClipName = "UI_OpenMenu_Start.wav";
public AK.Wwise.Event StartingEvent;
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() {
[ShowOnly] bool SoundIsPlaying = false;
[ShowOnly] string previousEventName = "";
/*public List<string> AudioClipNames = new() {
"Gion3.ogg",
"OriginStation.ogg",
"TrainToTheFuture.ogg",
@@ -23,7 +25,17 @@ public class HomeWorld_Initialize : MonoBehaviour
"OriginStation_Cue_127.ogg",
"H3P2-Default_231.ogg"
//"Finality-HOYO-MiX.ogg"
};
};*/
/*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;
public bool useAssetBundle = false;
public AudioBundleLoader BundleLoader;
public AssetBundle AudioBundle;
@@ -31,21 +43,24 @@ public class HomeWorld_Initialize : MonoBehaviour
private Resolution GameResolutionPre;
public Toggle PostProcessingToggle;
public SettingsPanel SettingsPanelScript;
//static uint[] currentlyPlayingIDs = new uint[50];
private async void Start()
{
if (useAssetBundle)
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += delegate
{
CurrentEvent.Stop(gameObject);
};
/*if (useAssetBundle)
{
/*BundleLoader.InitializeAudioAssetBundle();
new WaitForSeconds(2);*/
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);
audioSource.PlayOneShot(OpenMenuClip1, PlayVolume);*/
/* if (SettingsPanel)
{
if (Screen.currentResolution.height != GameResolutionPre.height)
@@ -59,14 +74,16 @@ public class HomeWorld_Initialize : MonoBehaviour
GameResolutionPre = Screen.currentResolution;
}
}*/
if (!SoundIsPlaying)
PostNormal(StartingEvent);
if (PlayerPrefs.GetInt("PostProcessingEnabled") == 1)
{
foreach (PostProcessVolume volume in SettingsPanelScript.PostProcessingVolumes)
volume.enabled = true;
PostProcessingToggle.isOn = true;
} else
}
else
{
foreach (PostProcessVolume volume in SettingsPanelScript.PostProcessingVolumes)
volume.enabled = false;
@@ -76,7 +93,7 @@ public class HomeWorld_Initialize : MonoBehaviour
private void FixedUpdate()
{
if (BundleLoader.AudioAssetBundle)
/*if (BundleLoader.AudioAssetBundle)
{
if (!audioSource.isPlaying)
PlayBGM();
@@ -89,7 +106,19 @@ public class HomeWorld_Initialize : MonoBehaviour
Debug.LogError("Clip has finished playing. Choosing a random clip...");
PlayBGM();
}
}*/
if (!SoundIsPlaying)
{
Debug.LogError("An event finished playing.");
PlayBGM();
}
/*else
AudioChangesOn -= Time.fixedDeltaTime;
if (AudioChangesOn <= 0f && SoundIsPlaying)
{
Debug.LogError("Event has finished playing. Choosing a random clip...");
PlayBGM();
}*/
}
/*private void Update()
@@ -104,13 +133,13 @@ public class HomeWorld_Initialize : MonoBehaviour
GameResolutionPre = Screen.currentResolution;
}
}*/
public void PlayBGM()
/*public void PlayBGM()
{
string AudioClipName = AudioClipNames[random.Next(AudioClipNames.Count)];
Debug.Log("Attempting to load audiobundle...");
if (audioSource)
{
AudioClip clip = BundleLoader.GetAudioClipFromAssetBundle(/*"Default/" + */AudioClipName);
AudioClip clip = BundleLoader.GetAudioClipFromAssetBundle(AudioClipName);
if (!clip)
Debug.LogError($"AudioClip {AudioClipName} could not be loaded.");
else
@@ -124,6 +153,61 @@ public class HomeWorld_Initialize : MonoBehaviour
//TimesAmbientSet++;
}
}
}*/
// 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...");
}
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();
}
}
}