feat: add PlayOnTrigger for music-synced audio playback

- Add PlayOnTrigger method to AudioSystem for scheduling audio playback on music sync events (beat/bar/grid)
- Rename ButtonInvoker to SetStateBind for better clarity
- Update PlaySoundBind to support both direct playback and trigger-based playback with callback flags
- Add CallbackFlags enum (MusicSyncBeat, MusicSyncBar, MusicSyncGrid)
- Update Metronome demo to use new callback flag naming convention
- Add test audio file sfx_notice_test.wav
- Update scene UI to demonstrate PlayOnTrigger functionality
This commit is contained in:
2026-04-16 14:39:58 +08:00
parent a4e6e6eccb
commit 91f1b18771
11 changed files with 102 additions and 127 deletions
+9 -116
View File
@@ -1298,7 +1298,7 @@ MonoBehaviour:
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: PlaySound Direct
m_Text: PlaySound OnTrigger
--- !u!222 &1193187745
CanvasRenderer:
m_ObjectHideFlags: 0
@@ -1319,7 +1319,6 @@ GameObject:
- component: {fileID: 1371927796}
- component: {fileID: 1371927795}
- component: {fileID: 1371927794}
- component: {fileID: 1371927798}
- component: {fileID: 1371927797}
m_Layer: 5
m_Name: PlaySoundDirect
@@ -1327,7 +1326,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &1371927793
RectTransform:
m_ObjectHideFlags: 0
@@ -1343,9 +1342,9 @@ RectTransform:
- {fileID: 1193187743}
m_Father: {fileID: 1667985901}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 150, y: -608.3334}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 160, y: 30}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1371927794
@@ -1392,21 +1391,9 @@ MonoBehaviour:
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 1371927798}
m_TargetAssemblyTypeName: UnityEngine.AudioSource, UnityEngine
m_MethodName: Play
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 1371927797}
m_TargetAssemblyTypeName: PlaySoundBind, Assembly-CSharp
m_MethodName: OnButtonPressed
m_MethodName: PlaySoundOnTrigger
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
@@ -1466,103 +1453,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3bdbaddf2c05142e19686a9a82ef92c3, type: 3}
m_Name:
m_EditorClassIdentifier:
callbackFlags: 2
inputField: {fileID: 1490886059}
--- !u!82 &1371927798
AudioSource:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1371927792}
m_Enabled: 1
serializedVersion: 4
OutputAudioMixerGroup: {fileID: -1744738308437188463, guid: 11793d92750e64286bcdd6a61eeec520, type: 2}
m_audioClip: {fileID: 8300000, guid: 95f3e694b4c5b4892871f69fd96b4b7f, type: 3}
m_PlayOnAwake: 0
m_Volume: 1
m_Pitch: 1
Loop: 0
Mute: 0
Spatialize: 0
SpatializePostEffects: 0
Priority: 128
DopplerLevel: 1
MinDistance: 1
MaxDistance: 500
Pan2D: 0
rolloffMode: 0
BypassEffects: 0
BypassListenerEffects: 0
BypassReverbZones: 0
rolloffCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
- serializedVersion: 3
time: 1
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
panLevelCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
spreadCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
reverbZoneMixCustomCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 1
inSlope: 0
outSlope: 0
tangentMode: 0
weightedMode: 0
inWeight: 0.33333334
outWeight: 0.33333334
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
--- !u!1 &1394234347
GameObject:
m_ObjectHideFlags: 0
@@ -1649,7 +1541,7 @@ MonoBehaviour:
m_Calls:
- m_Target: {fileID: 1394234352}
m_TargetAssemblyTypeName: PlaySoundBind, Assembly-CSharp
m_MethodName: OnButtonPressed
m_MethodName: PlaySound
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
@@ -1709,6 +1601,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 3bdbaddf2c05142e19686a9a82ef92c3, type: 3}
m_Name:
m_EditorClassIdentifier:
callbackFlags: 0
inputField: {fileID: 1490886059}
--- !u!1 &1490886057
GameObject: