Added support for a single AWB file containing multiple audio clips
This commit is contained in:
+1
-1
Submodule Assets/Scripts/Criware updated: 7c43bf70c7...63dc6f86fb
@@ -27,8 +27,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
public UmaContainer CurrentLiveContainer;
|
||||
public UmaContainer CurrentOtherContainer;
|
||||
|
||||
public AudioSource CurrentAudioSource;
|
||||
public AudioSource CurrentBGAudioSource;
|
||||
public List<AudioSource> CurrentAudioSources = new List<AudioSource>();
|
||||
|
||||
public AnimatorOverrideController OverrideController;
|
||||
|
||||
@@ -356,63 +355,77 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
public void LoadLiveSound(int songid,UmaDatabaseEntry SongAwb)
|
||||
public void LoadLiveSound(int songid, UmaDatabaseEntry SongAwb)
|
||||
{
|
||||
if (CurrentAudioSource)
|
||||
if (CurrentAudioSources.Count > 0)
|
||||
{
|
||||
Destroy(CurrentAudioSource.gameObject);
|
||||
var tmp = CurrentAudioSources[0];
|
||||
CurrentAudioSources.Clear();
|
||||
Destroy(tmp.gameObject);
|
||||
UI.ResetPlayer();
|
||||
}
|
||||
|
||||
|
||||
AudioClip clip = LoadAudio(SongAwb);
|
||||
if (clip != null)
|
||||
|
||||
foreach (AudioClip clip in LoadAudio(SongAwb))
|
||||
{
|
||||
CurrentAudioSource = new GameObject("SoundController").AddComponent<AudioSource>();
|
||||
CurrentAudioSource.clip = clip;
|
||||
CurrentAudioSource.Play();
|
||||
AddAudioSource(clip);
|
||||
}
|
||||
|
||||
string nameVar = $"snd_bgm_live_{songid}_oke";
|
||||
UmaDatabaseEntry BGawb = Main.AbList.FirstOrDefault(a => a.Name.Contains(nameVar) && a.Name.EndsWith("awb"));
|
||||
if (BGawb != null)
|
||||
{
|
||||
AudioClip BGclip = LoadAudio(BGawb);
|
||||
if (BGclip)
|
||||
var BGclip = LoadAudio(BGawb);
|
||||
if (BGclip.Count>0)
|
||||
{
|
||||
CurrentBGAudioSource = CurrentAudioSource.gameObject.AddComponent<AudioSource>();
|
||||
CurrentBGAudioSource.clip = BGclip;
|
||||
CurrentBGAudioSource.Play();
|
||||
AddAudioSource(BGclip[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public AudioClip LoadAudio(UmaDatabaseEntry awb)
|
||||
private void AddAudioSource(AudioClip clip)
|
||||
{
|
||||
UmaViewerUI.Instance.LoadedAssetsAdd(awb);
|
||||
AudioSource source;
|
||||
if (CurrentAudioSources.Count > 0)
|
||||
{
|
||||
|
||||
if (Mathf.Abs(CurrentAudioSources[0].clip.length - clip.length) > 3) return;
|
||||
source = CurrentAudioSources[0].gameObject.AddComponent<AudioSource>();
|
||||
}
|
||||
else
|
||||
{
|
||||
source = new GameObject("SoundController").AddComponent<AudioSource>();
|
||||
}
|
||||
CurrentAudioSources.Add(source);
|
||||
source.clip = clip;
|
||||
source.Play();
|
||||
}
|
||||
|
||||
public List<AudioClip> LoadAudio(UmaDatabaseEntry awb)
|
||||
{
|
||||
List<AudioClip> clips = new List<AudioClip>();
|
||||
UmaViewerUI.Instance.LoadedAssetsAdd(awb);
|
||||
string awbPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "Low"}\\Cygames\\umamusume\\dat\\{awb.Url.Substring(0, 2)}\\{awb.Url}";
|
||||
if (!File.Exists(awbPath)) return null;
|
||||
if (!File.Exists(awbPath)) return clips;
|
||||
|
||||
FileStream awbFile = File.OpenRead(awbPath);
|
||||
AwbReader awbReader = new AwbReader(awbFile);
|
||||
|
||||
|
||||
var stream = new UmaWaveStream(awbReader, 0);
|
||||
MemoryStream outputStream = new MemoryStream();
|
||||
WaveFileWriter.WriteWavFileToStream(outputStream, stream);
|
||||
|
||||
WAV wav = new WAV(outputStream.ToArray());
|
||||
AudioClip clip = AudioClip.Create(Path.GetFileName(awb.Name).Replace(".awb", ""),wav.SampleCount,wav.ChannelCount,wav.Frequency,false);
|
||||
clip.SetData(wav.ChannelCount > 1 ? wav.StereoChannel : wav.LeftChannel, 0);
|
||||
foreach (Wave wave in awbReader.Waves)
|
||||
{
|
||||
var stream = new UmaWaveStream(awbReader, wave.WaveId);
|
||||
MemoryStream outputStream = new MemoryStream();
|
||||
WaveFileWriter.WriteWavFileToStream(outputStream, stream);
|
||||
WAV wav = new WAV(outputStream.ToArray());
|
||||
AudioClip clip = AudioClip.Create(Path.GetFileName(awb.Name).Replace(".awb", wave.WaveId.ToString()), wav.SampleCount, wav.ChannelCount, wav.Frequency, false);
|
||||
clip.SetData(wav.ChannelCount > 1 ? wav.StereoChannel : wav.LeftChannel, 0);
|
||||
clips.Add(clip);
|
||||
outputStream.Dispose();
|
||||
}
|
||||
|
||||
awbReader.Dispose();
|
||||
awbFile.Dispose();
|
||||
outputStream.Dispose();
|
||||
|
||||
return clip;
|
||||
return clips;
|
||||
}
|
||||
|
||||
private void RecursiveLoadAsset(UmaDatabaseEntry entry, bool IsSubAsset = false)
|
||||
|
||||
@@ -427,55 +427,53 @@ public class UmaViewerUI : MonoBehaviour,FaceLoadCallBack
|
||||
|
||||
public void AudioPause()
|
||||
{
|
||||
if (Builder.CurrentAudioSource)
|
||||
if (Builder.CurrentAudioSources.Count>0)
|
||||
{
|
||||
AudioSource source = Builder.CurrentAudioSource;
|
||||
if (source.isPlaying)
|
||||
AudioSource MianSource = Builder.CurrentAudioSources[0];
|
||||
foreach (AudioSource source in Builder.CurrentAudioSources)
|
||||
{
|
||||
source.Pause();
|
||||
if (Builder.CurrentBGAudioSource)
|
||||
Builder.CurrentBGAudioSource.Pause();
|
||||
}
|
||||
else if(source.clip)
|
||||
{
|
||||
source.Play();
|
||||
if (Builder.CurrentBGAudioSource)
|
||||
Builder.CurrentBGAudioSource.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
source.Stop();
|
||||
if (Builder.CurrentBGAudioSource)
|
||||
Builder.CurrentBGAudioSource.Stop();
|
||||
if (MianSource.isPlaying)
|
||||
{
|
||||
source.Pause();
|
||||
}
|
||||
else if (MianSource.clip)
|
||||
{
|
||||
source.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
MianSource.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AudioProgressChange(float val)
|
||||
{
|
||||
if (Builder.CurrentAudioSource)
|
||||
if (Builder.CurrentAudioSources.Count>0)
|
||||
{
|
||||
AudioSource source = Builder.CurrentAudioSource;
|
||||
if (Builder.CurrentAudioSource.clip)
|
||||
AudioSource MianSource = Builder.CurrentAudioSources[0];
|
||||
foreach (AudioSource source in Builder.CurrentAudioSources)
|
||||
{
|
||||
source.time = source.clip.length * val;
|
||||
|
||||
if (Builder.CurrentBGAudioSource)
|
||||
Builder.CurrentBGAudioSource.time = source.clip.length * val;
|
||||
if (source.clip)
|
||||
{
|
||||
source.time = source.clip.length * val;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Builder.CurrentAudioSource)
|
||||
if (Builder.CurrentAudioSources.Count > 0)
|
||||
{
|
||||
AudioSource source = Builder.CurrentAudioSource;
|
||||
if (Builder.CurrentAudioSource.clip)
|
||||
AudioSource MianSource = Builder.CurrentAudioSources[0];
|
||||
if (MianSource.clip)
|
||||
{
|
||||
TitleText.text = source.clip.name;
|
||||
ProgressText.text = string.Format("{0} / {1}", ToTimeFormat(source.time), ToTimeFormat(source.clip.length));
|
||||
AudioSlider.SetValueWithoutNotify(source.time/ source.clip.length);
|
||||
TitleText.text = MianSource.clip.name;
|
||||
ProgressText.text = string.Format("{0} / {1}", ToTimeFormat(MianSource.time), ToTimeFormat(MianSource.clip.length));
|
||||
AudioSlider.SetValueWithoutNotify(MianSource.time/ MianSource.clip.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user