private void Awake() { Instance = this; #if NVR_FMOD Provider = this.gameObject.AddComponent <NVRCollisionSoundProviderFMOD>(); #else Provider = this.gameObject.AddComponent <NVRCollisionSoundProviderUnity>(); #endif }
private void Awake() { Instance = this; #if NVR_FMOD //todo: implement fmod provider #else Provider = this.gameObject.AddComponent <NVRCollisionSoundProviderUnity>(); #endif }
protected virtual void OnCollisionEnter(Collision collision) { Collider collider = collision.collider; if (SoundObjects.ContainsKey(collider)) { NVRCollisionSoundObject collisionSoundObject = SoundObjects[collider]; float volume = CalculateImpactVolume(collision); if (volume < NVRCollisionSoundController.Instance.MinCollisionVolume) { //Debug.Log("Volume too low to play: " + Volume); return; } NVRCollisionSoundController.Play(this.Material, collision.contacts[0].point, volume); NVRCollisionSoundController.Play(collisionSoundObject.Material, collision.contacts[0].point, volume); } }
public void PlayCollisionAudio(Collision collision, float volume) { if (m_cooldownTimer > 0) { // Ignore sound return; } float thisScale = transform.localScale.x; // Play this object's collision sound, depending on scale if so configured string thisMat = m_material; if (m_smallScaleThreshold != 0.0f && thisScale < m_smallScaleThreshold) { thisMat = m_smallScaleMaterial; } else if (m_largeScaleThreshold != 0.0f && thisScale > m_largeScaleThreshold) { thisMat = m_largeScaleMaterial; } if (string.IsNullOrEmpty(thisMat)) { thisMat = NVRCollisionSoundMaterialsList.DefaultMaterial; } if (thisMat != NVRCollisionSoundMaterialsList.EmptyMaterialName) { //Debug.Log("Play " + thisMat + " " + gameObject.name); NVRCollisionSoundController.Play(thisMat, collision.contacts[0].point, volume); } if (m_soundCooldown > 0) { // Start timer to prevent multiple sounds triggered in quick succession m_cooldownTimer = m_soundCooldown; } }
public override void OnInspectorGUI() { NVRCollisionSoundController controller = (NVRCollisionSoundController)target; if (hasReloaded == false) { DidReloadScripts(); } if (waitingForReload) { HasWaitedLongEnough(); } bool installFMOD = false; bool isFMODEnabled = controller.SoundEngine == NVRCollisionSoundProviders.FMOD; bool isUnityEnabled = controller.SoundEngine == NVRCollisionSoundProviders.Unity; bool enableFMOD = controller.SoundEngine == NVRCollisionSoundProviders.FMOD; bool enableUnity = controller.SoundEngine == NVRCollisionSoundProviders.Unity; EditorGUILayout.BeginHorizontal(); if (hasFMODSDK == false) { using (new EditorGUI.DisabledScope(hasFMODSDK == false)) { EditorGUILayout.Toggle("Use FMOD", false); } installFMOD = GUILayout.Button("Install FMOD"); } else { enableFMOD = EditorGUILayout.Toggle("Use FMOD", enableFMOD); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); enableUnity = EditorGUILayout.Toggle("Use Unity Sound", enableUnity); EditorGUILayout.EndHorizontal(); GUILayout.Space(10); if (enableFMOD == false && isFMODEnabled == true) { RemoveDefine(FMODDefine); controller.SoundEngine = NVRCollisionSoundProviders.None; } else if (enableFMOD == true && isFMODEnabled == false) { AddDefine(FMODDefine); controller.SoundEngine = NVRCollisionSoundProviders.FMOD; } if (enableUnity == false && isUnityEnabled == true) { RemoveDefine(FMODDefine); controller.SoundEngine = NVRCollisionSoundProviders.None; } else if (enableUnity == true && isUnityEnabled == false) { RemoveDefine(FMODDefine); controller.SoundEngine = NVRCollisionSoundProviders.Unity; } if (installFMOD == true) { Application.OpenURL("http://www.fmod.org/download/"); } DrawDefaultInspector(); if (waitingForReload == true || string.IsNullOrEmpty(progressBarMessage) == false) { DisplayProgressBar(); } if (GUI.changed) { if (Application.isPlaying == false) { EditorUtility.SetDirty(target); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); } } }