Created
April 8, 2021 13:28
-
-
Save silenciocorner/84be72e2bf7ecd5988bce25b6ccdc18d to your computer and use it in GitHub Desktop.
Part of MusicManager.cs script from Colin Vandervort article "FMOD Unity: Beat-Mapping"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MusicManager : MonoBehaviour | |
| { | |
| ... | |
| [AOT.MonoPInvokeCallback(typeof(FMOD.Studio.EVENT_CALLBACK))] | |
| static FMOD.RESULT BeatEventCallback(FMOD.Studio.EVENT_CALLBACK_TYPE type, FMOD.Studio.EventInstance instance, IntPtr parameterPtr) | |
| { | |
| IntPtr timelineInfoPtr; | |
| FMOD.RESULT result = instance.getUserData(out timelineInfoPtr); | |
| if (result != FMOD.RESULT.OK) | |
| { | |
| Debug.LogError("Timeline Callback error: " + result); | |
| } | |
| else if (timelineInfoPtr != IntPtr.Zero) //System(IntPtr) | |
| { | |
| GCHandle timelineHandle = GCHandle.FromIntPtr(timelineInfoPtr); | |
| TimelineInfo timelineInfo = (TimelineInfo)timelineHandle.Target; | |
| switch (type) | |
| { | |
| case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT: | |
| { | |
| var parameter = (FMOD.Studio.TIMELINE_BEAT_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_BEAT_PROPERTIES)); | |
| timelineInfo.currentBeat = parameter.beat; | |
| timelineInfo.currentBar = parameter.bar; | |
| timelineInfo.currentTempo = parameter.tempo; | |
| } | |
| break; | |
| case FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER: | |
| { | |
| var parameter = (FMOD.Studio.TIMELINE_MARKER_PROPERTIES)Marshal.PtrToStructure(parameterPtr, typeof(FMOD.Studio.TIMELINE_MARKER_PROPERTIES)); | |
| timelineInfo.lastMarker = parameter.name; | |
| } | |
| break; | |
| } | |
| } | |
| return FMOD.RESULT.OK; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment