diff --git a/Assets/Editor/ScreenCaptureEditor.cs b/Assets/Editor/ScreenCaptureEditor.cs
new file mode 100644
index 0000000..59495cc
--- /dev/null
+++ b/Assets/Editor/ScreenCaptureEditor.cs
@@ -0,0 +1,82 @@
+using System.IO;
+using UnityEditor;
+using UnityEngine;
+
+//Credit: https://gist.github.com/Tymski/63da742d595eaf36e80ffe5a36ce30d9
+public class ScreenCaptureEditor : EditorWindow
+{
+ private static string directory = "Screenshots/Capture/";
+ private static string latestScreenshotPath = "";
+ private bool initDone = false;
+
+ private GUIStyle BigText;
+
+ void InitStyles()
+ {
+ initDone = true;
+ BigText = new GUIStyle(GUI.skin.label)
+ {
+ fontSize = 20,
+ fontStyle = FontStyle.Bold
+ };
+ }
+
+ private void OnGUI()
+ {
+ if (!initDone)
+ {
+ InitStyles();
+ }
+
+ GUILayout.Label("Screen Capture", BigText);
+ if (GUILayout.Button("Take a screenshot"))
+ {
+ TakeScreenshot();
+ }
+ GUILayout.Label("Resolution: " + GetResolution());
+
+ if (GUILayout.Button("Reveal in Explorer"))
+ {
+ ShowFolder();
+ }
+ GUILayout.Label("Directory: " + directory);
+ }
+
+ [MenuItem("Tools/Screenshots/Open Window")]
+ public static void ShowWindow()
+ {
+ EditorWindow.GetWindow(typeof(ScreenCaptureEditor));
+ }
+
+ [MenuItem("Tools/Screenshots/Reveal in Explorer")]
+ private static void ShowFolder()
+ {
+ if (File.Exists(latestScreenshotPath))
+ {
+ EditorUtility.RevealInFinder(latestScreenshotPath);
+ return;
+ }
+ Directory.CreateDirectory(directory);
+ EditorUtility.RevealInFinder(directory);
+ }
+
+ [MenuItem("Tools/Screenshots/Take a Screenshot")]
+ private static void TakeScreenshot()
+ {
+ Directory.CreateDirectory(directory);
+ var currentTime = System.DateTime.Now;
+ var filename = currentTime.ToString().Replace('/', '-').Replace(':', '_') + ".png";
+ var path = directory + filename;
+ ScreenCapture.CaptureScreenshot(path);
+ latestScreenshotPath = path;
+ Debug.Log($"Screenshot saved: {path} with resolution {GetResolution()}");
+ }
+
+ private static string GetResolution()
+ {
+ Vector2 size = UnityEditor.Handles.GetMainGameViewSize();
+ Vector2Int sizeInt = new Vector2Int((int)size.x, (int)size.y);
+ return $"{sizeInt.x.ToString()}x{sizeInt.y.ToString()}";
+ }
+
+}
\ No newline at end of file
diff --git a/Assets/Oculus/Avatar/Scripts/GazeTarget.cs.meta b/Assets/Editor/ScreenCaptureEditor.cs.meta
similarity index 83%
rename from Assets/Oculus/Avatar/Scripts/GazeTarget.cs.meta
rename to Assets/Editor/ScreenCaptureEditor.cs.meta
index d2b2082..dcfc72f 100644
--- a/Assets/Oculus/Avatar/Scripts/GazeTarget.cs.meta
+++ b/Assets/Editor/ScreenCaptureEditor.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: 5bfcd054df64e334ba2f191666f3fe92
+guid: 62d870029ba5817488811f48f3ec1c26
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/InputSystem.inputsettings.asset b/Assets/InputSystem.inputsettings.asset
new file mode 100644
index 0000000..170571f
--- /dev/null
+++ b/Assets/InputSystem.inputsettings.asset
@@ -0,0 +1,36 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!114 &11400000
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 0}
+ m_Enabled: 1
+ m_EditorHideFlags: 0
+ m_Script: {fileID: 11500000, guid: c46f07b5ed07e4e92aa78254188d3d10, type: 3}
+ m_Name: InputSystem.inputsettings
+ m_EditorClassIdentifier:
+ m_SupportedDevices: []
+ m_UpdateMode: 1
+ m_MaxEventBytesPerUpdate: 5242880
+ m_MaxQueuedEventsPerUpdate: 1000
+ m_CompensateForScreenOrientation: 1
+ m_BackgroundBehavior: 0
+ m_EditorInputBehaviorInPlayMode: 0
+ m_DefaultDeadzoneMin: 0.125
+ m_DefaultDeadzoneMax: 0.925
+ m_DefaultButtonPressPoint: 0.5
+ m_ButtonReleaseThreshold: 0.75
+ m_DefaultTapTime: 0.2
+ m_DefaultSlowTapTime: 0.5
+ m_DefaultHoldTime: 0.4
+ m_TapRadius: 5
+ m_MultiTapDelayTime: 0.75
+ m_DisableRedundantEventsMerging: 0
+ m_ShortcutKeysConsumeInputs: 0
+ m_iOSSettings:
+ m_MotionUsage:
+ m_Enabled: 0
+ m_Description:
diff --git a/Assets/Oculus/OculusProjectConfig.asset.meta b/Assets/InputSystem.inputsettings.asset.meta
similarity index 79%
rename from Assets/Oculus/OculusProjectConfig.asset.meta
rename to Assets/InputSystem.inputsettings.asset.meta
index 18cbbbb..2f66171 100644
--- a/Assets/Oculus/OculusProjectConfig.asset.meta
+++ b/Assets/InputSystem.inputsettings.asset.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: f298595f04c8ecc4fbe1fb807460b40a
+guid: bed9d30a55ff5d44db2cf4e44657a26e
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
diff --git a/Assets/Oculus/AudioManager/Audio.meta b/Assets/Oculus/AudioManager/Audio.meta
deleted file mode 100644
index b8c21f2..0000000
--- a/Assets/Oculus/AudioManager/Audio.meta
+++ /dev/null
@@ -1,9 +0,0 @@
-fileFormatVersion: 2
-guid: 29ab7e927676ef74a93aeedf4146f1ac
-folderAsset: yes
-timeCreated: 1470780399
-licenseType: Store
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Oculus/AudioManager/Audio/TestSounds.meta b/Assets/Oculus/AudioManager/Audio/TestSounds.meta
deleted file mode 100644
index 50d0b84..0000000
--- a/Assets/Oculus/AudioManager/Audio/TestSounds.meta
+++ /dev/null
@@ -1,9 +0,0 @@
-fileFormatVersion: 2
-guid: 180c8a539f95cce428f820b0ba392c1f
-folderAsset: yes
-timeCreated: 1468506676
-licenseType: Store
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01.wav b/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01.wav
deleted file mode 100644
index 17d8c5d..0000000
--- a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01.wav
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:02df2b7172e6dcd2abb2d1a69eebb86046f29f225d7bc3f2aff9cbb07b79bd7b
-size 40180
diff --git a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01.wav.meta b/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01.wav.meta
deleted file mode 100644
index b6fd578..0000000
--- a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01.wav.meta
+++ /dev/null
@@ -1,22 +0,0 @@
-fileFormatVersion: 2
-guid: 485ac48a563e2bf44bb4de7ead5a1f68
-timeCreated: 1461716881
-licenseType: Store
-AudioImporter:
- serializedVersion: 6
- defaultSettings:
- loadType: 0
- sampleRateSetting: 0
- sampleRateOverride: 44100
- compressionFormat: 1
- quality: 1
- conversionMode: 0
- platformSettingOverrides: {}
- forceToMono: 0
- normalize: 1
- preloadAudioData: 1
- loadInBackground: 0
- 3D: 1
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01a.wav b/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01a.wav
deleted file mode 100644
index 2886843..0000000
--- a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01a.wav
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:e5410447a888bd7d8938b3bdc328dbe0d1272469eab88b81c336d899c2e7d2e8
-size 40178
diff --git a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01a.wav.meta b/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01a.wav.meta
deleted file mode 100644
index 01694b6..0000000
--- a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_close_01a.wav.meta
+++ /dev/null
@@ -1,22 +0,0 @@
-fileFormatVersion: 2
-guid: d3994560fb567c34a821fd9355c10eef
-timeCreated: 1461716882
-licenseType: Store
-AudioImporter:
- serializedVersion: 6
- defaultSettings:
- loadType: 0
- sampleRateSetting: 0
- sampleRateOverride: 44100
- compressionFormat: 1
- quality: 1
- conversionMode: 0
- platformSettingOverrides: {}
- forceToMono: 0
- normalize: 1
- preloadAudioData: 1
- loadInBackground: 0
- 3D: 1
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01.wav b/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01.wav
deleted file mode 100644
index 8ff899b..0000000
--- a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01.wav
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:56851dede6d1079545702e92d44ce73048277b5daaeb1168f309945cc0fccfcc
-size 47956
diff --git a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01.wav.meta b/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01.wav.meta
deleted file mode 100644
index a8ebd4b..0000000
--- a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01.wav.meta
+++ /dev/null
@@ -1,22 +0,0 @@
-fileFormatVersion: 2
-guid: 7000b4d67a1320940b363f3cf891dfff
-timeCreated: 1461716881
-licenseType: Store
-AudioImporter:
- serializedVersion: 6
- defaultSettings:
- loadType: 0
- sampleRateSetting: 0
- sampleRateOverride: 44100
- compressionFormat: 1
- quality: 1
- conversionMode: 0
- platformSettingOverrides: {}
- forceToMono: 0
- normalize: 1
- preloadAudioData: 1
- loadInBackground: 0
- 3D: 1
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01a.wav b/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01a.wav
deleted file mode 100644
index fd10e79..0000000
--- a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01a.wav
+++ /dev/null
@@ -1,3 +0,0 @@
-version https://git-lfs.github.com/spec/v1
-oid sha256:bf859666893d89be742948896fec030f0eafa304dc2b028e8cf03561878e1b98
-size 51014
diff --git a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01a.wav.meta b/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01a.wav.meta
deleted file mode 100644
index 94b9fd8..0000000
--- a/Assets/Oculus/AudioManager/Audio/TestSounds/metal_sliding_door_open_01a.wav.meta
+++ /dev/null
@@ -1,22 +0,0 @@
-fileFormatVersion: 2
-guid: 8198ccc08475a764daaf226b841a55f1
-timeCreated: 1461716882
-licenseType: Store
-AudioImporter:
- serializedVersion: 6
- defaultSettings:
- loadType: 0
- sampleRateSetting: 0
- sampleRateOverride: 44100
- compressionFormat: 1
- quality: 1
- conversionMode: 0
- platformSettingOverrides: {}
- forceToMono: 0
- normalize: 1
- preloadAudioData: 1
- loadInBackground: 0
- 3D: 1
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Oculus/AudioManager/Scripts.meta b/Assets/Oculus/AudioManager/Scripts.meta
deleted file mode 100644
index 94f5a04..0000000
--- a/Assets/Oculus/AudioManager/Scripts.meta
+++ /dev/null
@@ -1,9 +0,0 @@
-fileFormatVersion: 2
-guid: 25be027379f7fce4d97ba2bcaf313019
-folderAsset: yes
-timeCreated: 1470780399
-licenseType: Store
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Oculus/AudioManager/Scripts/Audio.meta b/Assets/Oculus/AudioManager/Scripts/Audio.meta
deleted file mode 100644
index b8a53af..0000000
--- a/Assets/Oculus/AudioManager/Scripts/Audio.meta
+++ /dev/null
@@ -1,9 +0,0 @@
-fileFormatVersion: 2
-guid: b8c0d722519c64144a78f8fc99cd40b5
-folderAsset: yes
-timeCreated: 1468505670
-licenseType: Store
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Oculus/AudioManager/Scripts/Audio/AmbienceEmitter.cs b/Assets/Oculus/AudioManager/Scripts/Audio/AmbienceEmitter.cs
deleted file mode 100644
index 740639f..0000000
--- a/Assets/Oculus/AudioManager/Scripts/Audio/AmbienceEmitter.cs
+++ /dev/null
@@ -1,118 +0,0 @@
-using UnityEngine;
-using System.Collections;
-
-namespace OVR
-{
-
-/*
------------------------
-
- AmbienceEmitter()
-
------------------------
-*/
-public class AmbienceEmitter : MonoBehaviour {
-
- public SoundFXRef[] ambientSounds = new SoundFXRef[0];
- public bool autoActivate = true;
- [Tooltip("Automatically play the sound randomly again when checked. Should be OFF for looping sounds")]
- public bool autoRetrigger = true;
- [MinMax( 2.0f, 4.0f, 0.1f, 10.0f )]
- public Vector2 randomRetriggerDelaySecs = new Vector2( 2.0f, 4.0f );
- [Tooltip( "If defined, the sounds will randomly play from these transform positions, otherwise the sound will play from this transform" )]
- public Transform[] playPositions = new Transform[0];
- private bool activated = false;
- private int playingIdx = -1;
- private float nextPlayTime = 0.0f;
- private float fadeTime = 0.25f;
- private int lastPosIdx = -1;
-
- /*
- -----------------------
- Awake()
- -----------------------
- */
- void Awake() {
- if ( autoActivate ) {
- activated = true;
- nextPlayTime = Time.time + Random.Range( randomRetriggerDelaySecs.x, randomRetriggerDelaySecs.y );
- }
- // verify all the play positions are valid
- foreach ( Transform t in playPositions ) {
- if ( t == null ) {
- Debug.LogWarning( "[AmbienceEmitter] Invalid play positions in " + name );
- playPositions = new Transform[0];
- break;
- }
- }
- }
-
- /*
- -----------------------
- Update()
- -----------------------
- */
- void Update() {
- if ( activated ) {
- if ( ( playingIdx == -1 ) || autoRetrigger ) {
- if ( Time.time >= nextPlayTime ) {
- Play();
- if ( !autoRetrigger ) {
- activated = false;
- }
- }
- }
- }
- }
-
- /*
- -----------------------
- OnTriggerEnter()
- -----------------------
- */
- public void OnTriggerEnter( Collider col ) {
- activated = !activated;
- }
-
- /*
- -----------------------
- Play()
- -----------------------
- */
- public void Play() {
- Transform transformToPlayFrom = transform;
- if ( playPositions.Length > 0 ) {
- int idx = Random.Range( 0, playPositions.Length );
- while ( ( playPositions.Length > 1 ) && ( idx == lastPosIdx ) ) {
- idx = Random.Range( 0, playPositions.Length );
- }
- transformToPlayFrom = playPositions[idx];
- lastPosIdx = idx;
- }
- playingIdx = ambientSounds[Random.Range(0, ambientSounds.Length)].PlaySoundAt( transformToPlayFrom.position );
- if ( playingIdx != -1 ) {
- AudioManager.FadeInSound( playingIdx, fadeTime );
- nextPlayTime = Time.time + Random.Range( randomRetriggerDelaySecs.x, randomRetriggerDelaySecs.y );
- }
- }
-
- /*
- -----------------------
- EnableEmitter()
- -----------------------
- */
- public void EnableEmitter( bool enable ) {
- activated = enable;
- if ( enable ) {
- Play();
- } else {
- if ( playingIdx != -1 ) {
- AudioManager.FadeOutSound( playingIdx, fadeTime );
- }
- }
-
- }
-
-}
-
-} // namespace OVR
diff --git a/Assets/Oculus/AudioManager/Scripts/Audio/AmbienceEmitter.cs.meta b/Assets/Oculus/AudioManager/Scripts/Audio/AmbienceEmitter.cs.meta
deleted file mode 100644
index 3cba3d6..0000000
--- a/Assets/Oculus/AudioManager/Scripts/Audio/AmbienceEmitter.cs.meta
+++ /dev/null
@@ -1,12 +0,0 @@
-fileFormatVersion: 2
-guid: c11944691f6b9cf44a391c95cb3f7dea
-timeCreated: 1455050294
-licenseType: Store
-MonoImporter:
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Oculus/AudioManager/Scripts/Audio/AudioManager.cs b/Assets/Oculus/AudioManager/Scripts/Audio/AudioManager.cs
deleted file mode 100644
index 4a1608d..0000000
--- a/Assets/Oculus/AudioManager/Scripts/Audio/AudioManager.cs
+++ /dev/null
@@ -1,429 +0,0 @@
-using UnityEngine;
-using UnityEngine.Audio;
-using System.Collections;
-using System.Collections.Generic;
-#if UNITY_EDITOR
-using UnityEditor;
-using System;
-using System.Reflection;
-#endif
-
-namespace OVR
-{
-
-public enum PreloadSounds {
- Default, // default unity behavior
- Preload, // audio clips are forced to preload
- ManualPreload, // audio clips are forced to not preload, preloading must be done manually
-}
-
-public enum Fade
-{
- In,
- Out
-}
-
-[System.Serializable]
-public class SoundGroup {
- public SoundGroup( string name ) {
- this.name = name;
- }
- public SoundGroup() {
- mixerGroup = null;
- maxPlayingSounds = 0;
- preloadAudio = PreloadSounds.Default;
- volumeOverride = 1.0f;
- }
- public void IncrementPlayCount() {
- playingSoundCount = Mathf.Clamp( ++playingSoundCount, 0, maxPlayingSounds );
- }
- public void DecrementPlayCount() {
- playingSoundCount = Mathf.Clamp( --playingSoundCount, 0, maxPlayingSounds );
- }
- public bool CanPlaySound() {
- return ( maxPlayingSounds == 0 ) || ( playingSoundCount < maxPlayingSounds );
- }
-
- public string name = string.Empty;
- public SoundFX[] soundList = new SoundFX[0];
- public AudioMixerGroup mixerGroup = null; // default = AudioManager.defaultMixerGroup
- [Range(0,64)]
- public int maxPlayingSounds = 0; // default = 0, unlimited
- // TODO: this preload behavior is not yet implemented
- public PreloadSounds preloadAudio = PreloadSounds.Default; // default = true, audio clip data will be preloaded
- public float volumeOverride = 1.0f; // default = 1.0
-
- [HideInInspector]
- public int playingSoundCount = 0;
-}
-
-/*
------------------------
-
- AudioManager
-
------------------------
-*/
-public partial class AudioManager : MonoBehaviour {
-
- [Tooltip("Make the audio manager persistent across all scene loads")]
- public bool makePersistent = true; // true = don't destroy on load
- [Tooltip("Enable the OSP audio plugin features")]
- public bool enableSpatializedAudio = true; // true = enable spatialized audio
- [Tooltip("Always play spatialized sounds with no reflections (Default)")]
- public bool enableSpatializedFastOverride = false; // true = disable spatialized reflections override
- [Tooltip("The audio mixer asset used for snapshot blends, etc.")]
- public AudioMixer audioMixer = null;
- [Tooltip( "The audio mixer group used for the pooled emitters" )]
- public AudioMixerGroup defaultMixerGroup = null;
- [Tooltip( "The audio mixer group used for the reserved pool emitter" )]
- public AudioMixerGroup reservedMixerGroup = null;
- [Tooltip( "The audio mixer group used for voice chat" )]
- public AudioMixerGroup voiceChatMixerGroup = null;
- [Tooltip("Log all PlaySound calls to the Unity console")]
- public bool verboseLogging = false; // true = log all PlaySounds
- [Tooltip("Maximum sound emitters")]
- public int maxSoundEmitters = 32; // total number of sound emitters created
- [Tooltip("Default volume for all sounds modulated by individual sound FX volumes")]
- public float volumeSoundFX = 1.0f; // user pref: volume of all sound FX
- [Tooltip("Sound FX fade time")]
- public float soundFxFadeSecs = 1.0f; // sound FX fade time
-
- public float audioMinFallOffDistance = 1.0f; // minimum falloff distance
- public float audioMaxFallOffDistance = 25.0f; // maximum falloff distance
-
- public SoundGroup[] soundGroupings = new SoundGroup[0];
-
- private Dictionary soundFXCache = null;
-
- static private AudioManager theAudioManager = null;
- static private FastList names = new FastList();
- static private string[] defaultSound = new string[1] { "Default Sound" };
- static private SoundFX nullSound = new SoundFX();
- static private bool hideWarnings = false;
- static public bool enableSpatialization { get { return ( theAudioManager !=null ) ? theAudioManager.enableSpatializedAudio : false; } }
-
- static public AudioManager Instance { get { return theAudioManager; } }
- static public float NearFallOff { get { return theAudioManager.audioMinFallOffDistance; } }
- static public float FarFallOff { get { return theAudioManager.audioMaxFallOffDistance; } }
- static public AudioMixerGroup EmitterGroup { get { return theAudioManager.defaultMixerGroup; } }
- static public AudioMixerGroup ReservedGroup { get { return theAudioManager.reservedMixerGroup; } }
- static public AudioMixerGroup VoipGroup { get { return theAudioManager.voiceChatMixerGroup; } }
-
- /*
- -----------------------
- Awake()
- -----------------------
- */
- void Awake() {
- Init();
- }
-
- /*
- -----------------------
- OnDestroy()
- -----------------------
- */
- void OnDestroy() {
- // we only want the initialized audio manager instance cleaning up the sound emitters
- if ( theAudioManager == this ) {
- if ( soundEmitterParent != null ) {
- Destroy( soundEmitterParent );
- }
- }
- ///TODO - if you change scenes you'll want to call OnPreSceneLoad to detach the sound emitters
- ///from anything they might be parented to or they will get destroyed with that object
- ///there should only be one instance of the AudioManager across the life of the game/app
- ///GameManager.OnPreSceneLoad -= OnPreSceneLoad;
- }
-
- /*
- -----------------------
- Init()
- -----------------------
- */
- void Init() {
- if ( theAudioManager != null ) {
- if ( Application.isPlaying && ( theAudioManager != this ) ) {
- enabled = false;
- }
- return;
- }
- theAudioManager = this;
-
- ///TODO - if you change scenes you'll want to call OnPreSceneLoad to detach the sound emitters
- ///from anything they might be parented to or they will get destroyed with that object
- ///there should only be one instance of the AudioManager across the life of the game/app
- ///GameManager.OnPreSceneLoad += OnPreSceneLoad;
-
- // make sure the first one is a null sound
- nullSound.name = "Default Sound";
-
- // build the sound FX cache
- RebuildSoundFXCache();
-
- // create the sound emitters
- if ( Application.isPlaying ) {
- InitializeSoundSystem();
- if ( makePersistent && ( transform.parent == null ) ) {
- // don't destroy the audio manager on scene loads
- DontDestroyOnLoad( gameObject );
- }
- }
-
-#if UNITY_EDITOR
- Debug.Log( "[AudioManager] Initialized..." );
-#endif
- }
-
- /*
- -----------------------
- Update()
- -----------------------
- */
- void Update() {
- // update the free and playing lists
- UpdateFreeEmitters();
- }
-
- /*
- -----------------------
- RebuildSoundFXCache()
- -----------------------
- */
- void RebuildSoundFXCache() {
- // build the SoundFX dictionary for quick name lookups
- int count = 0;
- for ( int group = 0; group < soundGroupings.Length; group++ ) {
- count += soundGroupings[group].soundList.Length;
- }
- soundFXCache = new Dictionary( count + 1 );
- // add the null sound
- soundFXCache.Add( nullSound.name, nullSound );
- // add the rest
- for ( int group = 0; group < soundGroupings.Length; group++ ) {
- for ( int i = 0; i < soundGroupings[group].soundList.Length; i++ ) {
- if ( soundFXCache.ContainsKey( soundGroupings[group].soundList[i].name ) ) {
- Debug.LogError( "ERROR: Duplicate Sound FX name in the audio manager: '" + soundGroupings[group].name + "' > '" + soundGroupings[group].soundList[i].name + "'" );
- } else {
- soundGroupings[group].soundList[i].Group = soundGroupings[group];
- soundFXCache.Add( soundGroupings[group].soundList[i].name, soundGroupings[group].soundList[i] );
- }
- }
- soundGroupings[group].playingSoundCount = 0;
- }
- }
-
- /*
- -----------------------
- FindSoundFX()
- -----------------------
- */
- static public SoundFX FindSoundFX( string name, bool rebuildCache = false ) {
-#if UNITY_EDITOR
- if ( theAudioManager == null ) {
- Debug.LogError( "ERROR: audio manager not yet initialized or created!" + " Time: " + Time.time );
- return null;
- }
-#endif
- if ( string.IsNullOrEmpty( name ) ) {
- return nullSound;
- }
- if ( rebuildCache ) {
- theAudioManager.RebuildSoundFXCache();
- }
- if ( !theAudioManager.soundFXCache.ContainsKey( name ) ) {
-#if DEBUG_BUILD || UNITY_EDITOR
- Debug.LogError( "WARNING: Missing Sound FX in cache: " + name );
-#endif
- return nullSound;
- }
- return theAudioManager.soundFXCache[name];
- }
-
- /*
- -----------------------
- FindAudioManager()
- -----------------------
- */
- static private bool FindAudioManager() {
- GameObject audioManagerObject = GameObject.Find( "AudioManager" );
- if ( ( audioManagerObject == null ) || ( audioManagerObject.GetComponent() == null ) ) {
- if ( !hideWarnings ) {
- Debug.LogError( "[ERROR] AudioManager object missing from hierarchy!" );
- hideWarnings = true;
- }
- return false;
- } else {
- audioManagerObject.GetComponent().Init();
- }
- return true;
- }
-
- /*
- -----------------------
- GetGameObject()
- -----------------------
- */
- static public GameObject GetGameObject() {
- if ( theAudioManager == null ) {
- if ( !FindAudioManager() ) {
- return null;
- }
- }
- return theAudioManager.gameObject;
- }
-
- /*
- -----------------------
- NameMinusGroup()
- strip off the sound group from the inspector dropdown
- -----------------------
- */
- static public string NameMinusGroup( string name ) {
- if ( name.IndexOf( "/" ) > -1 ) {
- return name.Substring( name.IndexOf( "/" ) + 1 );
- }
- return name;
- }
-
- /*
- -----------------------
- GetSoundFXNames()
- used by the inspector
- -----------------------
- */
- static public string[] GetSoundFXNames( string currentValue, out int currentIdx ) {
- currentIdx = 0;
- names.Clear();
- if ( theAudioManager == null ) {
- if ( !FindAudioManager() ) {
- return defaultSound;
- }
- }
- names.Add( nullSound.name );
- for ( int group = 0; group < theAudioManager.soundGroupings.Length; group++ ) {
- for ( int i = 0; i < theAudioManager.soundGroupings[group].soundList.Length; i++ ) {
- if ( string.Compare( currentValue, theAudioManager.soundGroupings[group].soundList[i].name, true ) == 0 ) {
- currentIdx = names.Count;
- }
- names.Add( theAudioManager.soundGroupings[group].name + "/" + theAudioManager.soundGroupings[group].soundList[i].name );
- }
- }
- //names.Sort( delegate( string s1, string s2 ) { return s1.CompareTo( s2 ); } );
- return names.ToArray();
-
- }
-#if UNITY_EDITOR
- /*
- -----------------------
- OnPrefabReimported()
- -----------------------
- */
- static public void OnPrefabReimported() {
- if ( theAudioManager != null ) {
- Debug.Log( "[AudioManager] Reimporting the sound FX cache." );
- theAudioManager.RebuildSoundFXCache();
- }
- }
-
- /*
- -----------------------
- PlaySound()
- used in the editor
- -----------------------
- */
- static public void PlaySound( string soundFxName ) {
- if ( theAudioManager == null ) {
- if ( !FindAudioManager() ) {
- return;
- }
- }
- SoundFX soundFX = FindSoundFX( soundFxName, true );
- if ( soundFX == null ) {
- return;
- }
- AudioClip clip = soundFX.GetClip();
- if ( clip != null ) {
- Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
- Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
- MethodInfo method = audioUtilClass.GetMethod(
- "PlayClip",
- BindingFlags.Static | BindingFlags.Public,
- null,
- new System.Type[] { typeof(AudioClip) },
- null );
- method.Invoke( null, new object[] { clip } );
- }
- }
-
- /*
- -----------------------
- IsSoundPlaying()
- used in the editor
- -----------------------
- */
- static public bool IsSoundPlaying( string soundFxName ) {
- if ( theAudioManager == null ) {
- if ( !FindAudioManager() ) {
- return false;
- }
- }
- SoundFX soundFX = FindSoundFX( soundFxName, true );
- if ( soundFX == null ) {
- return false;
- }
- AudioClip clip = soundFX.GetClip();
- if ( clip != null ) {
- Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
- Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
- MethodInfo method = audioUtilClass.GetMethod(
- "IsClipPlaying",
- BindingFlags.Static | BindingFlags.Public,
- null,
- new System.Type[] { typeof(AudioClip) },
- null );
- return Convert.ToBoolean( method.Invoke( null, new object[] { clip } ) );
- }
-
- return false;
- }
-
- /*
- -----------------------
- StopSound()
- used in the editor
- -----------------------
- */
- static public void StopSound(string soundFxName)
- {
- if (theAudioManager == null)
- {
- if (!FindAudioManager())
- {
- return;
- }
- }
- SoundFX soundFX = FindSoundFX(soundFxName, true);
- if (soundFX == null)
- {
- return;
- }
- AudioClip clip = soundFX.GetClip();
- if (clip != null)
- {
- Assembly unityEditorAssembly = typeof(AudioImporter).Assembly;
- Type audioUtilClass = unityEditorAssembly.GetType("UnityEditor.AudioUtil");
- MethodInfo method = audioUtilClass.GetMethod(
- "StopClip",
- BindingFlags.Static | BindingFlags.Public,
- null,
- new System.Type[] { typeof(AudioClip) },
- null);
- method.Invoke(null, new object[] { clip });
- }
- }
-#endif
-}
-
-} // namespace OVR
diff --git a/Assets/Oculus/AudioManager/Scripts/Audio/AudioManager.cs.meta b/Assets/Oculus/AudioManager/Scripts/Audio/AudioManager.cs.meta
deleted file mode 100644
index 55df52e..0000000
--- a/Assets/Oculus/AudioManager/Scripts/Audio/AudioManager.cs.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: 6d1d30b41806244fca035fdae2896fb7
-MonoImporter:
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
diff --git a/Assets/Oculus/AudioManager/Scripts/Audio/AudioManager_Sound.cs b/Assets/Oculus/AudioManager/Scripts/Audio/AudioManager_Sound.cs
deleted file mode 100644
index 36530e3..0000000
--- a/Assets/Oculus/AudioManager/Scripts/Audio/AudioManager_Sound.cs
+++ /dev/null
@@ -1,787 +0,0 @@
-using UnityEngine;
-using UnityEngine.Audio;
-
-namespace OVR
-{
-
-//-------------------------------------------------------------------------
-// Types
-//-------------------------------------------------------------------------
-
-public enum EmitterChannel {
- None = -1,
- Reserved = 0, // plays on the single reserved emitter
- Any // queues to the next available emitter
-}
-
-[System.Serializable]
-public class MixerSnapshot {
- public AudioMixerSnapshot snapshot = null;
- public float transitionTime = 0.25f;
-}
-
-/*
------------------------
-
- GameManager Sound Routines
-
------------------------
-*/
-public partial class AudioManager : MonoBehaviour {
-
- public enum Fade {
- In,
- Out
- }
-
- private float audioMaxFallOffDistanceSqr = 25.0f * 25.0f; // past this distance, sounds are ignored for the local player
-
- private SoundEmitter[] soundEmitters = null; // pool of sound emitters to play sounds through
-
- private FastList playingEmitters = new FastList();
- private FastList nextFreeEmitters = new FastList();
-
- private MixerSnapshot currentSnapshot = null;
-
- static private GameObject soundEmitterParent = null; // parent object for the sound emitters
- static private Transform staticListenerPosition = null; // play position for regular 2D sounds
-
- static private bool showPlayingEmitterCount = false;
- static private bool forceShowEmitterCount = false;
-
- static private bool soundEnabled = true;
- static public bool SoundEnabled { get { return soundEnabled; } }
-
- static readonly AnimationCurve defaultReverbZoneMix = new AnimationCurve( new Keyframe[2] { new Keyframe( 0f, 1.0f ), new Keyframe( 1f, 1f ) } );
-
- /*
- -----------------------
- InitializeSoundSystem()
- initialize persistent sound emitter objects that live across scene loads
- -----------------------
- */
- void InitializeSoundSystem() {
-
- int bufferLength = 960;
- int numBuffers = 4;
- AudioSettings.GetDSPBufferSize( out bufferLength, out numBuffers );
- if ( Application.isPlaying ) {
- Debug.Log( "[AudioManager] Audio Sample Rate: " + AudioSettings.outputSampleRate );
- Debug.Log( "[AudioManager] Audio Buffer Length: " + bufferLength + " Size: " + numBuffers );
- }
-
- // find the audio listener for playing regular 2D sounds
- AudioListener audioListenerObject = GameObject.FindObjectOfType() as AudioListener;
- if ( audioListenerObject == null ) {
- Debug.LogError( "[AudioManager] Missing AudioListener object! Add one to the scene." );
- } else {
- staticListenerPosition = audioListenerObject.transform;
- }
-
- // we allocate maxSoundEmitters + reserved channels
- soundEmitters = new SoundEmitter[maxSoundEmitters+(int)EmitterChannel.Any];
-
- // see if the sound emitters have already been created, if so, nuke it, it shouldn't exist in the scene upon load
- soundEmitterParent = GameObject.Find( "__SoundEmitters__" );
- if ( soundEmitterParent != null ) {
- // delete any sound emitters hanging around
- Destroy( soundEmitterParent );
- }
-
- // create them all
- soundEmitterParent = new GameObject( "__SoundEmitters__" );
- for ( int i = 0; i < maxSoundEmitters + (int)EmitterChannel.Any; i++ ) {
- GameObject emitterObject = new GameObject( "SoundEmitter_" + i );
- emitterObject.transform.parent = soundEmitterParent.transform;
- emitterObject.transform.position = Vector3.zero;
- // don't ever save this to the scene
- emitterObject.hideFlags = HideFlags.DontSaveInEditor;
- // add the sound emitter components
- soundEmitters[i] = emitterObject.AddComponent();
- soundEmitters[i].SetDefaultParent( soundEmitterParent.transform );
- soundEmitters[i].SetChannel( i );
- soundEmitters[i].Stop();
- // save off the original index
- soundEmitters[i].originalIdx = i;
- }
- // reset the free emitter lists
- ResetFreeEmitters();
- soundEmitterParent.hideFlags = HideFlags.DontSaveInEditor;
-
- audioMaxFallOffDistanceSqr = audioMaxFallOffDistance * audioMaxFallOffDistance;
- }
-
- /*
- -----------------------
- UpdateFreeEmitters()
- -----------------------
- */
- void UpdateFreeEmitters() {
- if ( verboseLogging ) {
- if ( Input.GetKeyDown( KeyCode.A ) ) {
- forceShowEmitterCount = !forceShowEmitterCount;
- }
- if ( forceShowEmitterCount ) {
- showPlayingEmitterCount = true;
- }
- }
- // display playing emitter count when the sound system is overwhelmed
- int total = 0, veryLow = 0, low = 0, def = 0, high = 0, veryHigh = 0;
-
- // find emitters that are done playing and add them to the nextFreeEmitters list
- for ( int i = 0; i < playingEmitters.size; ) {
- if ( playingEmitters[i] == null ) {
- Debug.LogError( "[AudioManager] ERROR: playingEmitters list had a null emitter! Something nuked a sound emitter!!!" );
- playingEmitters.RemoveAtFast( i );
- return;
- }
- if ( !playingEmitters[i].IsPlaying() ) {
- // add to the free list and remove from the playing list
- if ( verboseLogging ) {
- if ( nextFreeEmitters.Contains( playingEmitters[i] ) ) {
- Debug.LogError( "[AudioManager] ERROR: playing sound emitter already in the free emitters list!" );
- }
- }
- playingEmitters[i].Stop();
- nextFreeEmitters.Add( playingEmitters[i] );
- playingEmitters.RemoveAtFast( i );
- continue;
- }
- // debugging/profiling
- if ( verboseLogging && showPlayingEmitterCount ) {
- total++;
- switch ( playingEmitters[i].priority ) {
- case SoundPriority.VeryLow: veryLow++; break;
- case SoundPriority.Low: low++; break;
- case SoundPriority.Default: def++; break;
- case SoundPriority.High: high++; break;
- case SoundPriority.VeryHigh: veryHigh++; break;
- }
- }
- i++;
- }
- if ( verboseLogging && showPlayingEmitterCount ) {
- Debug.LogWarning( string.Format( "[AudioManager] Playing sounds: Total {0} | VeryLow {1} | Low {2} | Default {3} | High {4} | VeryHigh {5} | Free {6}", Fmt( total ), Fmt( veryLow ), Fmt( low ), Fmt( def ), Fmt( high ), Fmt( veryHigh ), FmtFree( nextFreeEmitters.Count ) ) );
- showPlayingEmitterCount = false;
- }
- }
-
- /*
- -----------------------
- Fmt()
- -----------------------
- */
- string Fmt( int count ) {
- float t = count / (float)theAudioManager.maxSoundEmitters;
- if ( t < 0.5f ) {
- return "" + count.ToString() + "";
- } else if ( t < 0.7 ) {
- return "" + count.ToString() + "";
- } else {
- return "" + count.ToString() + "";
- }
- }
-
- /*
- -----------------------
- FmtFree()
- -----------------------
- */
- string FmtFree( int count ) {
- float t = count / (float)theAudioManager.maxSoundEmitters;
- if ( t < 0.2f ) {
- return "" + count.ToString() + "";
- } else if ( t < 0.3 ) {
- return "" + count.ToString() + "";
- } else {
- return "" + count.ToString() + "";
- }
- }
-
- /*
- -----------------------
- OnPreSceneLoad()
- -----------------------
- */
- void OnPreSceneLoad() {
- // move any attached sounds back to the sound emitters parent before changing levels so they don't get destroyed
- Debug.Log( "[AudioManager] OnPreSceneLoad cleanup" );
- for ( int i = 0; i < soundEmitters.Length; i++ ) {
- soundEmitters[i].Stop();
- soundEmitters[i].ResetParent( soundEmitterParent.transform );
- }
- // reset our emitter lists
- ResetFreeEmitters();
- }
-
- /*
- -----------------------
- ResetFreeEmitters()
- -----------------------
- */
- void ResetFreeEmitters() {
- nextFreeEmitters.Clear();
- playingEmitters.Clear();
- for ( int i = (int)EmitterChannel.Any; i < soundEmitters.Length; i++ ) {
- nextFreeEmitters.Add( soundEmitters[i] );
- }
- }
-
- /*
- -----------------------
- FadeOutSoundChannel()
- utility function to fade out a playing sound channel
- -----------------------
- */
- static public void FadeOutSoundChannel( int channel, float delaySecs, float fadeTime ) {
- theAudioManager.soundEmitters[channel].FadeOutDelayed( delaySecs, fadeTime );
- }
-
- /*
- -----------------------
- StopSound()
- -----------------------
- */
- static public bool StopSound( int idx, bool fadeOut = true, bool stopReserved = false ) {
- if ( !stopReserved && ( idx == (int)EmitterChannel.Reserved ) ) {
- return false;
- }
- if ( !fadeOut ) {
- theAudioManager.soundEmitters[idx].Stop();
- }
- else {
- theAudioManager.soundEmitters[idx].FadeOut( theAudioManager.soundFxFadeSecs );
- }
-
- return true;
- }
-
- /*
- -----------------------
- FadeInSound()
- -----------------------
- */
- public static void FadeInSound( int idx, float fadeTime, float volume ) {
- theAudioManager.soundEmitters[idx].FadeIn( fadeTime, volume );
- }
-
- /*
- -----------------------
- FadeInSound()
- -----------------------
- */
- public static void FadeInSound( int idx, float fadeTime ) {
- theAudioManager.soundEmitters[idx].FadeIn( fadeTime );
- }
-
- /*
- -----------------------
- FadeOutSound()
- -----------------------
- */
- public static void FadeOutSound( int idx, float fadeTime ) {
- theAudioManager.soundEmitters[idx].FadeOut( fadeTime );
- }
-
- /*
- -----------------------
- StopAllSounds()
- -----------------------
- */
- public static void StopAllSounds( bool fadeOut, bool stopReserved = false ) {
- for ( int i = 0; i < theAudioManager.soundEmitters.Length; i++ ) {
- StopSound( i, fadeOut, stopReserved );
- }
- }
-
- /*
- -----------------------
- MuteAllSounds()
- -----------------------
- */
- public void MuteAllSounds( bool mute, bool muteReserved = false ) {
- for ( int i = 0; i < soundEmitters.Length; i++ ) {
- if ( !muteReserved && ( i == (int)EmitterChannel.Reserved ) ) {
- continue;
- }
- soundEmitters[i].audioSource.mute = true;
- }
- }
-
- /*
- -----------------------
- UnMuteAllSounds()
- -----------------------
- */
- public void UnMuteAllSounds( bool unmute, bool unmuteReserved = false ) {
- for ( int i = 0; i < soundEmitters.Length; i++ ) {
- if ( !unmuteReserved && ( i == (int)EmitterChannel.Reserved ) ) {
- continue;
- }
- if ( soundEmitters[i].audioSource.isPlaying ) {
- soundEmitters[i].audioSource.mute = false;
- }
- }
- }
-
- /*
- -----------------------
- GetEmitterEndTime()
- -----------------------
- */
- static public float GetEmitterEndTime( int idx ) {
- return theAudioManager.soundEmitters[idx].endPlayTime;
- }
-
- /*
- -----------------------
- SetEmitterTime()
- -----------------------
- */
- static public float SetEmitterTime( int idx, float time ) {
- return theAudioManager.soundEmitters[idx].time = time;
- }
-
- /*
- -----------------------
- PlaySound()
- -----------------------
- */
- static public int PlaySound( AudioClip clip, float volume, EmitterChannel src = EmitterChannel.Any, float delay = 0.0f, float pitchVariance = 1.0f, bool loop = false ) {
- if ( !SoundEnabled ) {
- return -1;
- }
- return PlaySoundAt( ( staticListenerPosition != null ) ? staticListenerPosition.position : Vector3.zero, clip, volume, src, delay, pitchVariance, loop );
- }
-
- /*
- -----------------------
- FindFreeEmitter()
- -----------------------
- */
- static private int FindFreeEmitter( EmitterChannel src, SoundPriority priority ) {
- // default to the reserved emitter
- SoundEmitter next = theAudioManager.soundEmitters[0];
- if ( src == EmitterChannel.Any ) {
- // pull from the free emitter list if possible
- if ( theAudioManager.nextFreeEmitters.size > 0 ) {
- // return the first in the list
- next = theAudioManager.nextFreeEmitters[0];
- // remove it from the free list
- theAudioManager.nextFreeEmitters.RemoveAtFast( 0 );
- } else {
- // no free emitters available so pull from the lowest priority sound
- if ( priority == SoundPriority.VeryLow ) {
- // skip low priority sounds
- return -1;
- } else {
- // find a playing emitter that has a lower priority than what we're requesting
- // TODO - we could first search for Very Low, then Low, etc ... TBD if it's worth the effort
- next = theAudioManager.playingEmitters.Find( item => item != null && item.priority < priority );
- if ( next == null ) {
- // last chance to find a free emitter
- if ( priority < SoundPriority.Default ) {
- // skip sounds less than the default priority
- if ( theAudioManager.verboseLogging ) {
- Debug.LogWarning( "[AudioManager] skipping sound " + priority );
- }
- return -1;
- } else {
- // grab a default priority emitter so that we don't cannabalize a high priority sound
- next = theAudioManager.playingEmitters.Find( item => item != null && item.priority <= SoundPriority.Default ); ;
- }
- }
- if ( next != null ) {
- if ( theAudioManager.verboseLogging ) {
- Debug.LogWarning( "[AudioManager] cannabalizing " + next.originalIdx + " Time: " + Time.time );
- }
- // remove it from the playing list
- next.Stop();
- theAudioManager.playingEmitters.RemoveFast( next );
- }
- }
- }
- }
- if ( next == null ) {
- Debug.LogError( "[AudioManager] ERROR - absolutely couldn't find a free emitter! Priority = " + priority + " TOO MANY PlaySound* calls!" );
- showPlayingEmitterCount = true;
- return -1;
- }
- return next.originalIdx;
- }
-
- /*
- -----------------------
- PlaySound()
- -----------------------
- */
- static public int PlaySound( SoundFX soundFX, EmitterChannel src = EmitterChannel.Any, float delay = 0.0f ) {
- if ( !SoundEnabled ) {
- return -1;
- }
- return PlaySoundAt( ( staticListenerPosition != null ) ? staticListenerPosition.position : Vector3.zero, soundFX, src, delay );
- }
-
- /*
- -----------------------
- PlaySoundAt()
- -----------------------
- */
- static public int PlaySoundAt( Vector3 position, SoundFX soundFX, EmitterChannel src = EmitterChannel.Any, float delay = 0.0f, float volumeOverride = 1.0f, float pitchMultiplier = 1.0f ) {
- if ( !SoundEnabled ) {
- return -1;
- }
-
- AudioClip clip = soundFX.GetClip();
- if ( clip == null ) {
- return -1;
- }
-
- // check the distance from the local player and ignore sounds out of range
- if ( staticListenerPosition != null ) {
- float distFromListener = ( staticListenerPosition.position - position ).sqrMagnitude;
- if ( distFromListener > theAudioManager.audioMaxFallOffDistanceSqr ) {
- return -1;
- }
- if ( distFromListener > soundFX.MaxFalloffDistSquared ) {
- return -1;
- }
- }
-
- // check max playing sounds
- if ( soundFX.ReachedGroupPlayLimit() ) {
- if ( theAudioManager.verboseLogging ) {
- Debug.Log( "[AudioManager] PlaySoundAt() with " + soundFX.name + " skipped due to group play limit" );
- }
- return -1;
- }
-
- int idx = FindFreeEmitter( src, soundFX.priority );
- if ( idx == -1 ) {
- // no free emitters - should only happen on very low priority sounds
- return -1;
- }
- SoundEmitter emitter = theAudioManager.soundEmitters[idx];
-
- // make sure to detach the emitter from a previous parent
- emitter.ResetParent( soundEmitterParent.transform );
- emitter.gameObject.SetActive( true );
-
- // set up the sound emitter
- AudioSource audioSource = emitter.audioSource;
- ONSPAudioSource osp = emitter.osp;
-
- audioSource.enabled = true;
- audioSource.volume = Mathf.Clamp01( Mathf.Clamp01( theAudioManager.volumeSoundFX * soundFX.volume ) * volumeOverride * soundFX.GroupVolumeOverride );
- audioSource.pitch = soundFX.GetPitch() * pitchMultiplier;
- audioSource.time = 0.0f;
- audioSource.spatialBlend = 1.0f;
- audioSource.rolloffMode = soundFX.falloffCurve;
- if ( soundFX.falloffCurve == AudioRolloffMode.Custom ) {
- audioSource.SetCustomCurve( AudioSourceCurveType.CustomRolloff, soundFX.volumeFalloffCurve );
- }
- audioSource.SetCustomCurve( AudioSourceCurveType.ReverbZoneMix, soundFX.reverbZoneMix );
- audioSource.dopplerLevel = 0;
- audioSource.clip = clip;
- audioSource.spread = soundFX.spread;
- audioSource.loop = soundFX.looping;
- audioSource.mute = false;
- audioSource.minDistance = soundFX.falloffDistance.x;
- audioSource.maxDistance = soundFX.falloffDistance.y;
- audioSource.outputAudioMixerGroup = soundFX.GetMixerGroup( AudioManager.EmitterGroup );
- // set the play time so we can check when sounds are done
- emitter.endPlayTime = Time.time + clip.length + delay;
- // cache the default volume for fading
- emitter.defaultVolume = audioSource.volume;
- // sound priority
- emitter.priority = soundFX.priority;
- // reset this
- emitter.onFinished = null;
- // update the sound group limits
- emitter.SetPlayingSoundGroup( soundFX.Group );
- // add to the playing list
- if ( src == EmitterChannel.Any ) {
- theAudioManager.playingEmitters.AddUnique( emitter );
- }
-
- // OSP properties
- if ( osp != null ) {
- osp.EnableSpatialization = soundFX.ospProps.enableSpatialization;
- osp.EnableRfl = theAudioManager.enableSpatializedFastOverride || soundFX.ospProps.useFastOverride ? true : false;
- osp.Gain = soundFX.ospProps.gain;
- osp.UseInvSqr = soundFX.ospProps.enableInvSquare;
- osp.Near = soundFX.ospProps.invSquareFalloff.x;
- osp.Far = soundFX.ospProps.invSquareFalloff.y;
- audioSource.spatialBlend = (soundFX.ospProps.enableSpatialization) ? 1.0f : 0.8f;
-
- // make sure to set the properties in the audio source before playing
- osp.SetParameters(ref audioSource);
- }
-
- audioSource.transform.position = position;
-
- if ( theAudioManager.verboseLogging ) {
- Debug.Log( "[AudioManager] PlaySoundAt() channel = " + idx + " soundFX = " + soundFX.name + " volume = " + emitter.volume + " Delay = " + delay + " time = " + Time.time + "\n" );
- }
-
- // play the sound
- if ( delay > 0f ) {
- audioSource.PlayDelayed( delay );
- } else {
- audioSource.Play();
- }
-
- return idx;
- }
-
- /*
- -----------------------
- PlayRandomSoundAt()
- -----------------------
- */
- static public int PlayRandomSoundAt( Vector3 position, AudioClip[] clips, float volume, EmitterChannel src = EmitterChannel.Any, float delay = 0.0f, float pitch = 1.0f, bool loop = false ) {
- if ( ( clips == null ) || ( clips.Length == 0 ) ) {
- return -1;
- }
- int idx = Random.Range( 0, clips.Length );
- return PlaySoundAt( position, clips[idx], volume, src, delay, pitch, loop );
- }
-
- /*
- -----------------------
- PlaySoundAt()
- -----------------------
- */
- static public int PlaySoundAt( Vector3 position, AudioClip clip, float volume = 1.0f, EmitterChannel src = EmitterChannel.Any, float delay = 0.0f, float pitch = 1.0f, bool loop = false ) {
- if ( !SoundEnabled ) {
- return -1;
- }
-
- if ( clip == null ) {
- return -1;
- }
-
- // check the distance from the local player and ignore sounds out of range
- if ( staticListenerPosition != null ) {
- if ( ( staticListenerPosition.position - position ).sqrMagnitude > theAudioManager.audioMaxFallOffDistanceSqr ) {
- // no chance of being heard
- return -1;
- }
- }
-
- int idx = FindFreeEmitter( src, 0 );
- if ( idx == -1 ) {
- // no free emitters - should only happen on very low priority sounds
- return -1;
- }
- SoundEmitter emitter = theAudioManager.soundEmitters[idx];
-
- // make sure to detach the emitter from a previous parent
- emitter.ResetParent( soundEmitterParent.transform );
- emitter.gameObject.SetActive( true );
-
- // set up the sound emitter
- AudioSource audioSource = emitter.audioSource;
- ONSPAudioSource osp = emitter.osp;
-
- audioSource.enabled = true;
- audioSource.volume = Mathf.Clamp01( theAudioManager.volumeSoundFX * volume );
- audioSource.pitch = pitch;
- audioSource.spatialBlend = 0.8f;
- audioSource.rolloffMode = AudioRolloffMode.Linear;
- audioSource.SetCustomCurve( AudioSourceCurveType.ReverbZoneMix, defaultReverbZoneMix );
- audioSource.dopplerLevel = 0.0f;
- audioSource.clip = clip;
- audioSource.spread = 0.0f;
- audioSource.loop = loop;
- audioSource.mute = false;
- audioSource.minDistance = theAudioManager.audioMinFallOffDistance;
- audioSource.maxDistance = theAudioManager.audioMaxFallOffDistance;
- audioSource.outputAudioMixerGroup = AudioManager.EmitterGroup;
- // set the play time so we can check when sounds are done
- emitter.endPlayTime = Time.time + clip.length + delay;
- // cache the default volume for fading
- emitter.defaultVolume = audioSource.volume;
- // default priority
- emitter.priority = 0;
- // reset this
- emitter.onFinished = null;
- // update the sound group limits
- emitter.SetPlayingSoundGroup( null );
- // add to the playing list
- if ( src == EmitterChannel.Any ) {
- theAudioManager.playingEmitters.AddUnique( emitter );
- }
-
- // disable spatialization (by default for regular AudioClips)
- if ( osp != null ) {
- osp.EnableSpatialization = false;
- }
-
- audioSource.transform.position = position;
-
- if ( theAudioManager.verboseLogging ) {
- Debug.Log( "[AudioManager] PlaySoundAt() channel = " + idx + " clip = " + clip.name + " volume = " + emitter.volume + " Delay = " + delay + " time = " + Time.time + "\n" );
- }
-
- // play the sound
- if ( delay > 0f ) {
- audioSource.PlayDelayed( delay );
- } else {
- audioSource.Play();
- }
-
- return idx;
- }
-
- /*
- -----------------------
- SetOnFinished()
- -----------------------
- */
- public static void SetOnFinished( int emitterIdx, System.Action onFinished ) {
- if ( emitterIdx >= 0 && emitterIdx < theAudioManager.maxSoundEmitters ) {
- theAudioManager.soundEmitters[emitterIdx].SetOnFinished( onFinished );
- }
- }
-
- /*
- -----------------------
- SetOnFinished()
- -----------------------
- */
- public static void SetOnFinished( int emitterIdx, System.Action