-
Notifications
You must be signed in to change notification settings - Fork 14
/
DemoFMOD.cs
54 lines (48 loc) · 1.79 KB
/
DemoFMOD.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class DemoFMOD : MonoBehaviour
{
FMOD.Studio.EventInstance _EventInstance;
FMOD.Studio.PARAMETER_ID _ID;
float _EventInstanceUse = 0.0f;
FMOD.Studio.PARAMETER_ID CacheHandle(FMOD.Studio.EventInstance eventInstance, string parameterName)
{
FMOD.Studio.EventDescription eventDescription;
eventInstance.getDescription(out eventDescription);
FMOD.Studio.PARAMETER_DESCRIPTION parameterDescription;
eventDescription.getParameterDescriptionByName(parameterName, out parameterDescription);
return parameterDescription.id;
}
bool IsPlaying(FMOD.Studio.EventInstance eventInstance)
{
FMOD.Studio.PLAYBACK_STATE state;
eventInstance.getPlaybackState(out state);
return state != FMOD.Studio.PLAYBACK_STATE.STOPPED;
}
void Start()
{
_EventInstance = FMODUnity.RuntimeManager.CreateInstance("event:/Audio/EventName");
_EventInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
_ID = CacheHandle(_EventInstance, "ParamaterName");
}
void OnGUI()
{
if (GUI.Button(new Rect(10, 150, 200, 50), "Enable Audio"))
{
if (!IsPlaying(_EventInstance))
{
_EventInstance.set3DAttributes(FMODUnity.RuntimeUtils.To3DAttributes(gameObject));
_EventInstance.start();
_EventInstanceUse = 1.0f;
_EventInstance.setParameterByID(_ID, _EventInstanceUse);
}
}
}
void OnDestroy()
{
_EventInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
_EventInstance.release();
}
}