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); } } } }
public void SetVolume(float volume) { if (instance.isValid()) { instance.setVolume(volume); } }
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; } } } }
public void UpdateInsideStatus(int insideStatus) { if (spotAmbienceInstance.isValid()) { spotAmbienceInstance.setVolume(insideStatus); } }
protected void PlayEvent() { if (!string.IsNullOrEmpty(eventName)) { eventInstance = RuntimeManager.CreateInstance(eventName); // Only attach to object if the game is actually playing, not auditioning. if (Application.isPlaying && TrackTargetObject) { Rigidbody rb = TrackTargetObject.GetComponent <Rigidbody>(); if (rb) { RuntimeManager.AttachInstanceToGameObject(eventInstance, TrackTargetObject.transform, rb); } else { RuntimeManager.AttachInstanceToGameObject(eventInstance, TrackTargetObject.transform, TrackTargetObject.GetComponent <Rigidbody2D>()); } } else { eventInstance.set3DAttributes(RuntimeUtils.To3DAttributes(Vector3.zero)); } foreach (var param in parameters) { eventInstance.setParameterByID(param.ID, param.Value); } eventInstance.setVolume(currentVolume); eventInstance.start(); } }
public override void OnNewLaserbeam(Laserbeam laserbeams) { Player player = base.Scene.Tracker.GetEntity <Player>(); Vector2 position = player != null && atPlayer ? player.Position : Position; float pitch = NoteHelper.relativeA4ToFreq(this.pitch - 69) / 440f; FMOD.Studio.EventInstance instance = Audio.Play(SFX.EventnameByHandle(sound), position); instance?.setVolume(volume); instance?.setPitch(pitch); }
private void StartAmbience() { if (ambienceStarted) { return; } baseAmbienceInstance = FMODUnity.RuntimeManager.CreateInstance(baseAmbience); if (baseAmbienceInstance.isValid()) { baseAmbienceInstance.setVolume(InsideStatus); baseAmbienceInstance.start(); } ambienceStarted = true; }
public void Play(float volume = 1.0f, GameObject parent = null, Rigidbody rb = null, FmodParamData[] paramData = null) { //print("PLAY FMOD EVENT " + eventName + " INDEX " + index); fmodEvent.setVolume(volume); if (parent != null && rb != null) { FMODUnity.RuntimeManager.AttachInstanceToGameObject(fmodEvent, parent.transform, rb); } if (paramData != null) { for (int i = 0; i < paramData.Length; i++) { FmodFacade.instance.SetFmodParameterValue(fmodEvent, paramData[i].paramName, paramData[i].paramValue); } } fmodEvent.start(); isReadyToPlay = false; }
/// <summary> /// Plays the passed in fmod event as a one shot event, meaning it is set to release the event automatically as soon as it stops playing. /// This allows for instanced fmod events without letting them infinitely build up. /// </summary> /// <param name="fmodEvent"> The name of the event we want to play as a one shot event </param> /// <param name="volume"> The volume of the event we want to play as a one shot event </param> /// <param name="paramData"> An array of param data that should be passed to our fmod event before playing it </param> public void PlayOneShotFmodEvent(FMOD.Studio.EventInstance fmodEvent, float volume = 1.0f, FmodParamData[] paramData = null) { if (paramData != null) { for (int i = 0; i < paramData.Length; i++) { SetFmodParameterValue(fmodEvent, paramData[i].paramName, paramData[i].paramValue); } } fmodEvent.setVolume(volume); if (debugOneShotEvents) { Debug.Log("1. START ONE SHOT EVENT"); FMOD.Studio.EVENT_CALLBACK stoppedOneShotEventCallback; stoppedOneShotEventCallback = new FMOD.Studio.EVENT_CALLBACK(StoppedOneShotEventCallback); fmodEvent.setCallback(stoppedOneShotEventCallback, FMOD.Studio.EVENT_CALLBACK_TYPE.STOPPED); } fmodEvent.start(); fmodEvent.release(); }
protected void PlayEvent() { if (!eventReference.IsNull) { eventInstance = RuntimeManager.CreateInstance(eventReference); // Only attach to object if the game is actually playing, not auditioning. if (Application.isPlaying && TrackTargetObject) { #if UNITY_PHYSICS_EXIST if (TrackTargetObject.GetComponent <Rigidbody>()) { RuntimeManager.AttachInstanceToGameObject(eventInstance, TrackTargetObject.transform, TrackTargetObject.GetComponent <Rigidbody>()); } else #endif #if UNITY_PHYSICS2D_EXIST if (TrackTargetObject.GetComponent <Rigidbody2D>()) { RuntimeManager.AttachInstanceToGameObject(eventInstance, TrackTargetObject.transform, TrackTargetObject.GetComponent <Rigidbody2D>()); } else #endif { RuntimeManager.AttachInstanceToGameObject(eventInstance, TrackTargetObject.transform); } } else { eventInstance.set3DAttributes(RuntimeUtils.To3DAttributes(Vector3.zero)); } foreach (var param in parameters) { eventInstance.setParameterByID(param.ID, param.Value); } eventInstance.setVolume(currentVolume); eventInstance.start(); } }
public void UpdateBehavior(float time, float volume) { if (volume != currentVolume) { currentVolume = volume; if (eventInstance.isValid()) { eventInstance.setVolume(volume); } } if ((time >= OwningClip.start) && (time < OwningClip.end)) { OnEnter(); } else { OnExit(); } }
/// <summary> /// Plays the passed in fmod event /// </summary> /// <param name="fmodEvent"> The name of the fmod event we want to play </param> /// <param name="volume"> The volume of the fmod event we want to play </param> public void PlayFmodEvent(FMOD.Studio.EventInstance fmodEvent, float volume = 1.0f) { fmodEvent.setVolume(volume); fmodEvent.start(); }
public void AdjustVolume(float volume) { _volume = volume; _musicInstance.setVolume(_volume); }