public static void PreviewUpdateParameter(FMOD.Studio.PARAMETER_ID id, float paramValue) { if (previewEventInstance.isValid()) { CheckResult(previewEventInstance.setParameterByID(id, paramValue)); } }
private void AudioTriggerArea_OnTriggerAreaEvent(object sender, AudioTriggerAreaEventArgs e) { if (e.triggerEventType == AudioTriggerAreaEventArgs.TriggerEventType.TriggerEnter) { insideCount++; if (insideCount == 1 && initializationSuccesfull) { snapshotInstance = FMODUnity.RuntimeManager.CreateInstance(snapshotPath); if (snapshotInstance.isValid()) { snapshotInstance.start(); } else { Debug.LogError("Snapshot event path is invalid for Reverb Zone " + gameObject.name + "."); } } } else { insideCount--; if (insideCount == 0 && initializationSuccesfull) { if (snapshotInstance.isValid()) { snapshotInstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE); snapshotInstance.release(); } } } }
public static void PreviewUpdateParameter(string paramName, float paramValue) { if (previewEventInstance.isValid()) { CheckResult(previewEventInstance.setParameterValue(paramName, paramValue)); } }
public void UpdateInsideStatus(int insideStatus) { if (spotAmbienceInstance.isValid()) { spotAmbienceInstance.setVolume(insideStatus); } }
public int PlayVoiceover(string key, string dialogueName, float overrideDuration) { if (!initializationSuccesfull || string.IsNullOrEmpty(key) || string.IsNullOrEmpty(dialogueName)) { return(-1); } if (!isSpeaking) { bool didSucceed = PlayProtocol(key, dialogueName, overrideDuration); if (didSucceed) { return(1); } else { return(-1); } } else if (eventInstance.isValid()) { // Stop the current dialogue with a quick fade out and then start the new line. // <- No click/pop stops, but also enforces the speaker monophony. eventInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); if (coroutineRunning) { StopAllCoroutines(); coroutineRunning = false; } // Inform the voiceover manager that the playback handler is busy stopping the previous dialogue line and it should queue the line. return(0); } else // If we are on a customly assigned pacing wait after a line has stopped playing let's abort this wait and start the new line immediately. { if (coroutineRunning) { StopAllCoroutines(); coroutineRunning = false; isSpeaking = false; currentDialogue = null; } bool didSucceed = PlayProtocol(key, dialogueName, overrideDuration); if (didSucceed) { return(1); } else { return(-1); } } }
void OnDestroy() { if (!isQuitting) { HandleGameEvent(EmitterGameEvent.LevelEnd); if (instance != null && instance.isValid()) { RuntimeManager.DetachInstanceFromGameObject(instance); } } }
public void OnExit() { if (isPlayheadInside) { if (eventInstance.isValid()) { if (stopType != STOP_MODE.None) { eventInstance.stop(stopType == STOP_MODE.Immediate ? FMOD.Studio.STOP_MODE.IMMEDIATE : FMOD.Studio.STOP_MODE.ALLOWFADEOUT); } eventInstance.release(); } isPlayheadInside = false; } }
private void AudioTriggerArea_OnTriggerAreaEvent(object sender, AudioTriggerAreaEventArgs e) { if (!initializationSuccesfull) { return; } if (e.triggerEventType == AudioTriggerAreaEventArgs.TriggerEventType.TriggerEnter) { insideCounter++; if (insideCounter == 1) { if (!ambienceStarted) { StartAmbience(); } InsideStatus = 1; if (baseAmbienceInstance.isValid()) { baseAmbienceInstance.setVolume(InsideStatus); UpdateInsideStatusForSpots(); } } } else { insideCounter--; if (insideCounter == 0) { InsideStatus = 0; if (baseAmbienceInstance.isValid()) { baseAmbienceInstance.setVolume(InsideStatus); UpdateInsideStatusForSpots(); } if (enteredSpotAmbienceAreas.Count < 1) { StopAmbience(FMOD.Studio.STOP_MODE.IMMEDIATE); } } } }
void OnDestroy() { if (!isQuitting) { HandleGameEvent(EmitterGameEvent.ObjectDestroy); if (instance != null && instance.isValid()) { RuntimeManager.DetachInstanceFromGameObject(instance); } if (Preload) { eventDescription.unloadSampleData(); } } }
public void StartSpotAmbience(int initialInsideStatus) { if (!IsInitialized) { return; } if (!InstanceAlreadyPlaying) { spotAmbienceInstance = FMODUnity.RuntimeManager.CreateInstance(spotAmbience); if (spotAmbienceInstance.isValid()) { FMODUnity.RuntimeManager.AttachInstanceToGameObject(spotAmbienceInstance, gameObject.transform, rb); spotAmbienceInstance.setProperty(FMOD.Studio.EVENT_PROPERTY.MAXIMUM_DISTANCE, adjustMaxDistance); if (spatialAudioRoomAware && SpatialAudioManager.Instance != null) { SpatialAudioManager.Instance.RegisterRoomAwareInstance(spotAmbienceInstance, gameObject.transform, adjustMaxDistance, initialRoom); } spotAmbienceInstance.setVolume(initialInsideStatus); FMOD.RESULT result = spotAmbienceInstance.start(); if (result == FMOD.RESULT.OK) { InstanceAlreadyPlaying = true; } } } }
private bool PlayProtocol(string key, string dialogueName, float overrideDuration) { eventInstance = FMODUnity.RuntimeManager.CreateInstance(masterVoiceoverEvent); if (!eventInstance.isValid()) { return(false); } GCHandle stringHandle = GCHandle.Alloc(key, GCHandleType.Pinned); eventInstance.setUserData(GCHandle.ToIntPtr(stringHandle)); eventInstance.setCallback(voiceoverCallback); if (is3D) { Transform transformToFollow; if (followTransform != null) { transformToFollow = followTransform; } else { transformToFollow = gameObject.transform; } // If the followed game object has a rigidbody, retrieve it and pass it to FMODUnity Runtimemanager for velocity updates. Rigidbody rb = transformToFollow.gameObject.GetComponent <Rigidbody>(); FMODUnity.RuntimeManager.AttachInstanceToGameObject(eventInstance, transformToFollow, rb); if (spatialAudioRoomAware && SpatialAudioManager.Instance != null) { SpatialAudioManager.Instance.RegisterRoomAwareInstance(eventInstance, transformToFollow, maxDistance, initialRoom); } } isSpeaking = true; currentDialogue = dialogueName; if (overrideDuration >= 0) { StartCoroutine(WaitBeforeDialogueRelease(overrideDuration)); coroutineRunning = true; } eventInstance.start(); return(true); }
public override void RunLine(LocalizedLine dialogueLine, System.Action onDialogueDeliveryComplete) { StartCoroutine(DoRunLine(dialogueLine, onDialogueDeliveryComplete)); IEnumerator DoRunLine(LocalizedLine dialogueLine, System.Action onDialogueDeliveryComplete) { interrupted = false; // Check if this instance is currently playing back another // voice over in which case we stop it if (lastVoiceOverEvent.isValid()) { lastVoiceOverEvent.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); } // Create playback event FMOD.Studio.EventInstance dialogueInstance; try { dialogueInstance = FMODUnity.RuntimeManager.CreateInstance(fmodEvent); } catch (Exception) { UnityEngine.Debug.LogWarning("FMOD: Voice over playback failed.", gameObject); throw; } lastVoiceOverEvent = dialogueInstance; // Pin the key string in memory and pass a pointer through the // user data GCHandle stringHandle = GCHandle.Alloc(dialogueLine.TextID.Remove(0, 5), GCHandleType.Pinned); dialogueInstance.setUserData(GCHandle.ToIntPtr(stringHandle)); dialogueInstance.setCallback(dialogueCallback, FMOD.Studio.EVENT_CALLBACK_TYPE.ALL); dialogueInstance.start(); dialogueInstance.release(); while (!interrupted && dialogueInstance.isValid()) { yield return(null); } if (dialogueInstance.isValid()) { dialogueInstance.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT); } } }
void OnDestroy() { if (!isQuitting) { HandleGameEvent(EmitterGameEvent.ObjectDestroy); if (instance.isValid()) { RuntimeManager.DetachInstanceFromGameObject(instance); if (eventDescription.isValid() && isOneshot) { instance.release(); instance.clearHandle(); } } if (Preload) { eventDescription.unloadSampleData(); } } }
private void StartAmbience() { if (ambienceStarted) { return; } baseAmbienceInstance = FMODUnity.RuntimeManager.CreateInstance(baseAmbience); if (baseAmbienceInstance.isValid()) { baseAmbienceInstance.setVolume(InsideStatus); baseAmbienceInstance.start(); } ambienceStarted = true; }
public static bool SetResonanceAudioSourceMaxDistance(FMOD.Studio.EventInstance eventInstance, float maxDistanceValue) { if (!eventInstance.isValid() || maxDistanceValue < 0) { return(false); } FMOD.RESULT result; FMOD.ChannelGroup channelGroup; result = eventInstance.getChannelGroup(out channelGroup); if (result != FMOD.RESULT.OK) { Debug.Log(result); return(false); } int dspNumber; result = channelGroup.getNumDSPs(out dspNumber); if (result != FMOD.RESULT.OK) { Debug.Log(result); return(false); } for (int i = 0; i < dspNumber; i++) { FMOD.DSP dsp; result = channelGroup.getDSP(i, out dsp); if (result != FMOD.RESULT.OK) { Debug.Log(result); continue; } result = dsp.getInfo(out string name, out uint version, out int channels, out int configWidth, out int configHeight); if (result != FMOD.RESULT.OK) { Debug.Log(result); continue; } if (name == "Resonance Audio Source") { result = dsp.getNumParameters(out int parameterNumber); if (result != FMOD.RESULT.OK) { Debug.Log(result); continue; } for (int j = 0; j < parameterNumber; j++) { result = dsp.getParameterInfo(j, out FMOD.DSP_PARAMETER_DESC description); if (result != FMOD.RESULT.OK) { Debug.Log(result); continue; } string stringName = System.Text.Encoding.UTF8.GetString(description.name); if (String.Equals(stringName, "Max Distance", StringComparison.InvariantCultureIgnoreCase)) { result = dsp.setParameterFloat(j, maxDistanceValue); if (result != FMOD.RESULT.OK) { Debug.Log(result); continue; } return(true); } } } } return(false); }