174 lines
5.9 KiB
C#
174 lines
5.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using Ichni.RhythmGame.Beatmap;
|
|
using SLSUtilities.WwiseAssistance;
|
|
|
|
namespace Ichni.RhythmGame
|
|
{
|
|
public partial class NoteAudioSubmodule : SubmoduleBase
|
|
{
|
|
#region Audio Settings
|
|
public List<string> generalJudgeAudioList;
|
|
public List<string> perfectAudioList;
|
|
public List<string> goodAudioList;
|
|
public List<string> badAudioList;
|
|
public List<string> missAudioList;
|
|
public List<string> holdStartAudioList;
|
|
public List<string> holdLoopAudioList;
|
|
public List<string> holdEndAudioList;
|
|
#endregion
|
|
|
|
#region GC-Free Wwise IDs
|
|
private uint[] _generalJudgeAudioIds;
|
|
private uint[] _perfectAudioIds;
|
|
private uint[] _goodAudioIds;
|
|
private uint[] _badAudioIds;
|
|
private uint[] _missAudioIds;
|
|
private uint[] _holdStartAudioIds;
|
|
private uint[] _holdEndAudioIds;
|
|
|
|
private NoteBase note => attachedGameElement as NoteBase;
|
|
#endregion
|
|
|
|
#region Initialization
|
|
public NoteAudioSubmodule(NoteBase attachedGameElement, string defaultAudio) : base(attachedGameElement)
|
|
{
|
|
generalJudgeAudioList = new List<string> { defaultAudio };
|
|
perfectAudioList = new List<string>();
|
|
goodAudioList = new List<string>();
|
|
badAudioList = new List<string>();
|
|
missAudioList = new List<string>();
|
|
holdStartAudioList = new List<string>();
|
|
holdLoopAudioList = new List<string>();
|
|
holdEndAudioList = new List<string>();
|
|
|
|
if (!HaveSameSubmodule)
|
|
{
|
|
note.NoteAudioSubmodule = this;
|
|
}
|
|
|
|
InitializeAudio();
|
|
}
|
|
|
|
public NoteAudioSubmodule(NoteBase attachedGameElement, List<string> generalJudgeAudioList,
|
|
List<string> perfectAudioList, List<string> goodAudioList, List<string> badAudioList,
|
|
List<string> missAudioList, List<string> holdStartAudioList,
|
|
List<string> holdLoopAudioList = null, List<string> holdEndAudioList = null) : base(attachedGameElement)
|
|
{
|
|
this.generalJudgeAudioList = generalJudgeAudioList ?? new List<string>();
|
|
this.perfectAudioList = perfectAudioList ?? new List<string>();
|
|
this.goodAudioList = goodAudioList ?? new List<string>();
|
|
this.badAudioList = badAudioList ?? new List<string>();
|
|
this.missAudioList = missAudioList ?? new List<string>();
|
|
this.holdStartAudioList = holdStartAudioList ?? new List<string>();
|
|
this.holdLoopAudioList = holdLoopAudioList ?? new List<string>();
|
|
this.holdEndAudioList = holdEndAudioList ?? new List<string>();
|
|
|
|
if (!HaveSameSubmodule)
|
|
{
|
|
note.NoteAudioSubmodule = this;
|
|
}
|
|
|
|
InitializeAudio();
|
|
}
|
|
|
|
public void InitializeAudio()
|
|
{
|
|
_generalJudgeAudioIds = ParseWwiseEventIDs(generalJudgeAudioList);
|
|
_perfectAudioIds = ParseWwiseEventIDs(perfectAudioList);
|
|
_goodAudioIds = ParseWwiseEventIDs(goodAudioList);
|
|
_badAudioIds = ParseWwiseEventIDs(badAudioList);
|
|
_missAudioIds = ParseWwiseEventIDs(missAudioList);
|
|
_holdStartAudioIds = ParseWwiseEventIDs(holdStartAudioList);
|
|
_holdEndAudioIds = ParseWwiseEventIDs(holdEndAudioList);
|
|
}
|
|
|
|
private uint[] ParseWwiseEventIDs(List<string> audioNames)
|
|
{
|
|
if (audioNames == null || audioNames.Count == 0) return Array.Empty<uint>();
|
|
|
|
List<uint> ids = new List<uint>(audioNames.Count);
|
|
Type eventsType = typeof(AK.EVENTS);
|
|
|
|
for (int i = 0; i < audioNames.Count; i++)
|
|
{
|
|
if (string.IsNullOrEmpty(audioNames[i])) continue;
|
|
|
|
string upperName = audioNames[i].ToUpper();
|
|
FieldInfo field = eventsType.GetField(upperName, BindingFlags.Public | BindingFlags.Static);
|
|
|
|
if (field != null)
|
|
{
|
|
ids.Add((uint)field.GetValue(null));
|
|
}
|
|
else
|
|
{
|
|
UnityEngine.Debug.LogWarning($"[Wwise] AK.EVENTS does not contain event name: {upperName}");
|
|
}
|
|
}
|
|
|
|
return ids.ToArray();
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
#region Audio Playback Methods
|
|
public partial class NoteAudioSubmodule
|
|
{
|
|
public void PlayHoldStartAudio()
|
|
{
|
|
PlayAudioInternal(_holdStartAudioIds);
|
|
}
|
|
|
|
public void PlayHoldEndAudio()
|
|
{
|
|
if (_holdEndAudioIds != null && _holdEndAudioIds.Length > 0)
|
|
{
|
|
PlayAudioInternal(_holdEndAudioIds);
|
|
return;
|
|
}
|
|
|
|
PlayGeneralJudgeAudios();
|
|
}
|
|
|
|
public void PlayGeneralJudgeAudios()
|
|
{
|
|
PlayAudioInternal(_generalJudgeAudioIds);
|
|
}
|
|
|
|
public void PlayNoteJudgeAudios(NoteBase.NoteJudgeType judgeType)
|
|
{
|
|
switch (judgeType)
|
|
{
|
|
case NoteBase.NoteJudgeType.Perfect:
|
|
PlayAudioInternal(_perfectAudioIds);
|
|
break;
|
|
case NoteBase.NoteJudgeType.Good:
|
|
PlayAudioInternal(_goodAudioIds);
|
|
break;
|
|
case NoteBase.NoteJudgeType.Bad:
|
|
PlayAudioInternal(_badAudioIds);
|
|
break;
|
|
case NoteBase.NoteJudgeType.Miss:
|
|
PlayAudioInternal(_missAudioIds);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void PlayAudioInternal(uint[] audioIds)
|
|
{
|
|
if (audioIds == null) return;
|
|
for (int i = 0; i < audioIds.Length; i++)
|
|
{
|
|
AkSoundEngine.PostEvent(audioIds[i], AudioManager.Instance.gameObject);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Beatmap
|
|
|
|
#endregion
|
|
}
|