wip : scene timing with music & early custom cue listener
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
using UnityEngine;
|
||||
|
||||
// Requires the Wwise Unity Integration package in your project.
|
||||
public class Audio_MusicCueListener : MonoBehaviour
|
||||
{
|
||||
// Drag your Wwise event asset here in the Inspector,
|
||||
// or assign the event name as a string (see PostEvent overload below).
|
||||
[SerializeField] private AK.Wwise.Event musicEvent;
|
||||
|
||||
private uint _playingId;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
PlayMusicWithCueCallbacks();
|
||||
}
|
||||
|
||||
private void PlayMusicWithCueCallbacks()
|
||||
{
|
||||
// AK_MusicSyncUserCue fires every time a Custom Cue marker is hit.
|
||||
// Combine with other flags using | if you need beat/bar callbacks too.
|
||||
uint callbackFlags = (uint)(AkCallbackType.AK_MusicSyncUserCue
|
||||
| AkCallbackType.AK_EndOfEvent);
|
||||
|
||||
_playingId = musicEvent.Post(
|
||||
gameObject,
|
||||
callbackFlags,
|
||||
OnMusicCallback
|
||||
);
|
||||
|
||||
if (_playingId == AkUnitySoundEngine.AK_INVALID_PLAYING_ID)
|
||||
{
|
||||
Debug.LogError("[MusicCuePlayer] Failed to post Wwise event. "
|
||||
+ "Check the event name and AkGameObj component.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"[MusicCuePlayer] Music started — playing ID: {_playingId}");
|
||||
}
|
||||
}
|
||||
|
||||
// Called by Wwise on the main thread for each registered callback type.
|
||||
private void OnMusicCallback(object cookie, AkCallbackType type, AkCallbackInfo info)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case AkCallbackType.AK_MusicSyncUserCue:
|
||||
var cueInfo = (AkMusicSyncCallbackInfo)info;
|
||||
Debug.Log($"[MusicCuePlayer] Cue reached: '{cueInfo.userCueName}'");
|
||||
// Hook your game logic here, e.g.:
|
||||
// OnCueReached(cueInfo.userCueName);
|
||||
break;
|
||||
|
||||
case AkCallbackType.AK_EndOfEvent:
|
||||
Debug.Log("[MusicCuePlayer] Music event ended.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Stop the sound cleanly when this object is destroyed.
|
||||
AkUnitySoundEngine.StopPlayingID(_playingId, 500); // 500 ms fade-out
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57e4af8a70aa9904da2b35504ad63407
|
||||
@@ -1,35 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class MusicCueLogger : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private AK.Wwise.Event musicEvent;
|
||||
|
||||
private uint _playingId;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_playingId = musicEvent.Post(
|
||||
gameObject,
|
||||
(uint)AkCallbackType.AK_MusicSyncUserCue,
|
||||
OnMusicSync
|
||||
);
|
||||
}
|
||||
|
||||
private void OnMusicSync(object in_cookie, AkCallbackType in_type, AkCallbackInfo in_info)
|
||||
{
|
||||
if (in_type != AkCallbackType.AK_MusicSyncUserCue)
|
||||
return;
|
||||
|
||||
var cueInfo = in_info as AkMusicSyncCallbackInfo;
|
||||
if (cueInfo == null)
|
||||
return;
|
||||
|
||||
Debug.Log($"[MusicCueLogger] Cue reached: {cueInfo.userCueName}");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (_playingId != AkUnitySoundEngine.AK_INVALID_PLAYING_ID)
|
||||
AkUnitySoundEngine.StopPlayingID(_playingId);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8c7b417b385a5b4babca499ff6b8a68
|
||||
Reference in New Issue
Block a user