9 public class EventNotFoundException : Exception
13 public EventNotFoundException(string path)
14 : base("[FMOD] Event not found '" + path + "'")
19 public EventNotFoundException(Guid guid)
20 : base("[FMOD] Event not found " + guid.ToString("b") + "")
26 public class BusNotFoundException : Exception
29 public BusNotFoundException(string path)
30 : base("[FMOD] Bus not found '" + path + "'")
36 public class VCANotFoundException : Exception
39 public VCANotFoundException(string path)
40 : base("[FMOD] VCA not found '" + path + "'")
46 public class BankLoadException : Exception
49 public FMOD.RESULT Result;
51 public BankLoadException(string path, FMOD.RESULT result)
52 : base(string.Format("[FMOD] Could not load bank '{0}' : {1} : {2}", path, result.ToString(), FMOD.Error.String(result)))
57 public BankLoadException(string path, string error)
58 : base(string.Format("[FMOD] Could not load bank '{0}' : {1}", path, error))
61 Result = FMOD.RESULT.ERR_INTERNAL;
65 public class SystemNotInitializedException : Exception
67 public FMOD.RESULT Result;
68 public string Location;
70 public SystemNotInitializedException(FMOD.RESULT result, string location)
71 : base(string.Format("[FMOD] Initialization failed : {2} : {0} : {1}", result.ToString(), FMOD.Error.String(result), location))
77 public SystemNotInitializedException(Exception inner)
78 : base("[FMOD] Initialization failed", inner)
83 public enum EmitterGameEvent : int
104 public enum LoaderGameEvent : int
115 public static class RuntimeUtils
117 public static string GetCommonPlatformPath(string path)
119 if (string.IsNullOrEmpty(path))
124 return path.Replace('\\', '/');
127 public static FMOD.VECTOR ToFMODVector(this Vector3 vec)
137 public static FMOD.ATTRIBUTES_3D To3DAttributes(this Vector3 pos)
139 FMOD.ATTRIBUTES_3D attributes = new FMOD.ATTRIBUTES_3D();
140 attributes.forward = ToFMODVector(Vector3.forward);
141 attributes.up = ToFMODVector(Vector3.up);
142 attributes.position = ToFMODVector(pos);
147 public static FMOD.ATTRIBUTES_3D To3DAttributes(this Transform transform)
149 FMOD.ATTRIBUTES_3D attributes = new FMOD.ATTRIBUTES_3D();
150 attributes.forward = transform.forward.ToFMODVector();
151 attributes.up = transform.up.ToFMODVector();
152 attributes.position = transform.position.ToFMODVector();
157 public static FMOD.ATTRIBUTES_3D To3DAttributes(Transform transform, Rigidbody rigidbody = null)
159 FMOD.ATTRIBUTES_3D attributes = transform.To3DAttributes();
163 attributes.velocity = rigidbody.velocity.ToFMODVector();
169 public static FMOD.ATTRIBUTES_3D To3DAttributes(GameObject go, Rigidbody rigidbody = null)
171 FMOD.ATTRIBUTES_3D attributes = go.transform.To3DAttributes();
175 attributes.velocity = rigidbody.velocity.ToFMODVector();
181 public static FMOD.ATTRIBUTES_3D To3DAttributes(Transform transform, Rigidbody2D rigidbody)
183 FMOD.ATTRIBUTES_3D attributes = transform.To3DAttributes();
188 vel.x = rigidbody.velocity.x;
189 vel.y = rigidbody.velocity.y;
191 attributes.velocity = vel;
197 public static FMOD.ATTRIBUTES_3D To3DAttributes(GameObject go, Rigidbody2D rigidbody)
199 FMOD.ATTRIBUTES_3D attributes = go.transform.To3DAttributes();
204 vel.x = rigidbody.velocity.x;
205 vel.y = rigidbody.velocity.y;
207 attributes.velocity = vel;
213 // Internal Helper Functions
214 internal static FMODPlatform GetCurrentPlatform()
217 return FMODPlatform.PlayInEditor;
218 #elif UNITY_STANDALONE_WIN
219 return FMODPlatform.Windows;
220 #elif UNITY_STANDALONE_OSX
221 return FMODPlatform.Mac;
222 #elif UNITY_STANDALONE_LINUX
223 return FMODPlatform.Linux;
225 return FMODPlatform.AppleTV;
228 switch (UnityEngine.iOS.Device.generation)
230 case UnityEngine.iOS.DeviceGeneration.iPad1Gen:
231 case UnityEngine.iOS.DeviceGeneration.iPad2Gen:
232 case UnityEngine.iOS.DeviceGeneration.iPad3Gen:
233 case UnityEngine.iOS.DeviceGeneration.iPadMini1Gen:
234 case UnityEngine.iOS.DeviceGeneration.iPhone:
235 case UnityEngine.iOS.DeviceGeneration.iPhone3G:
236 case UnityEngine.iOS.DeviceGeneration.iPhone3GS:
237 case UnityEngine.iOS.DeviceGeneration.iPhone4:
238 case UnityEngine.iOS.DeviceGeneration.iPhone4S:
239 result = FMODPlatform.MobileLow;
242 result = FMODPlatform.MobileHigh;
246 UnityEngine.Debug.Log(String.Format("FMOD Studio: Device {0} classed as {1}", SystemInfo.deviceModel, result.ToString()));
250 if (SystemInfo.processorCount <= 2)
252 result = FMODPlatform.MobileLow;
254 else if (SystemInfo.processorCount >= 8)
256 result = FMODPlatform.MobileHigh;
260 // check the clock rate on quad core systems
261 string freqinfo = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
264 using (global::System.IO.TextReader reader = new global::System.IO.StreamReader(freqinfo))
266 string line = reader.ReadLine();
267 int khz = Int32.Parse(line) / 1000;
270 result = FMODPlatform.MobileHigh;
274 result = FMODPlatform.MobileLow;
280 result = FMODPlatform.MobileLow;
284 UnityEngine.Debug.Log(String.Format("[FMOD] Device {0} classed as {1}", SystemInfo.deviceModel, result.ToString()));
286 #elif UNITY_WINRT_8_1
288 if (SystemInfo.processorCount <= 2)
290 result = FMODPlatform.MobileLow;
294 result = FMODPlatform.MobileHigh;
297 UnityEngine.Debug.Log(String.Format("[FMOD] Device {0} classed as {1}", SystemInfo.deviceModel, result.ToString()));
301 return FMODPlatform.PS4;
303 return FMODPlatform.XboxOne;
305 return FMODPlatform.UWP;
307 return FMODPlatform.Switch;
309 return FMODPlatform.WebGL;
311 return FMODPlatform.Stadia;
315 const string BankExtension = ".bank";
316 internal static string GetBankPath(string bankName)
319 // For play in editor use original asset location because streaming asset folder will contain platform specific banks
320 string bankFolder = Settings.Instance.SourceBankPath;
321 if (Settings.Instance.HasPlatforms)
323 bankFolder = global::System.IO.Path.Combine(bankFolder, Settings.Instance.GetBankPlatform(FMODPlatform.PlayInEditor));
326 string bankFolder = null;
327 if (System.IO.Path.GetExtension(Application.dataPath) == ".apk")
329 bankFolder = "file:///android_asset";
333 bankFolder = String.Format("jar:file://{0}!/assets", Application.dataPath);
335 #elif UNITY_WINRT_8_1 || UNITY_WSA_10_0
336 string bankFolder = "ms-appx:///Data/StreamingAssets";
338 string bankFolder = Application.streamingAssetsPath;
341 // Special case for Switch, remove / at start if needed.
343 if (bankFolder[0] == '/')
344 bankFolder = bankFolder.Substring(1);
347 if (System.IO.Path.GetExtension(bankName) != BankExtension)
349 return string.Format("{0}/{1}.bank", bankFolder, bankName);
353 return string.Format("{0}/{1}", bankFolder, bankName);
357 internal static string GetPluginPath(string pluginName)
359 #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_XBOXONE || UNITY_WINRT_8_1 || UNITY_WSA_10_0
360 string pluginFileName = pluginName + ".dll";
361 #elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
362 string pluginFileName = pluginName + ".bundle";
364 string pluginFileName = pluginName + ".prx";
365 #elif UNITY_ANDROID || UNITY_STANDALONE_LINUX
366 string pluginFileName = "lib" + pluginName + ".so";
368 string pluginFileName = pluginName + ".bc";
371 string fmodLibPath = "/Plugins/FMOD/lib";
372 #if UNITY_EDITOR_WIN && UNITY_EDITOR_64
373 string pluginFolder = Application.dataPath + fmodLibPath + "/win/X86_64/";
374 #elif UNITY_EDITOR_WIN
375 string pluginFolder = Application.dataPath + fmodLibPath + "/win/X86/";
376 #elif UNITY_EDITOR_OSX
377 string pluginFolder = Application.dataPath + fmodLibPath + "/mac/";
378 #elif UNITY_STANDALONE_WIN || UNITY_PS4 || UNITY_XBOXONE || UNITY_STANDALONE_OSX || UNITY_WEBGL
379 string pluginFolder = Application.dataPath + "/Plugins/";
380 #elif UNITY_STANDALONE_LINUX
381 string pluginFolder = Application.dataPath + fmodLibPath + ((IntPtr.Size == 8) ? "/linux/x86_64/" : "/linux/x86/");
382 #elif UNITY_WSA || UNITY_ANDROID
383 string pluginFolder = "";
385 string pluginFileName = "";
386 string pluginFolder = "";
389 return pluginFolder + pluginFileName;
392 public static void EnforceLibraryOrder()
394 #if UNITY_ANDROID && !UNITY_EDITOR
396 AndroidJavaClass jSystem = new AndroidJavaClass("java.lang.System");
397 jSystem.CallStatic("loadLibrary", FMOD.VERSION.dll);
398 jSystem.CallStatic("loadLibrary", FMOD.Studio.STUDIO_VERSION.dll);
402 // Call a function in fmod.dll to make sure it's loaded before fmodstudio.dll
404 FMOD.Memory.GetStats(out temp1, out temp2);
407 FMOD.Studio.Util.parseID("", out temp3);
411 public static FMODPlatform GetEditorFMODPlatform()
413 switch (EditorUserBuildSettings.activeBuildTarget)
415 case BuildTarget.Android:
416 return FMODPlatform.Android;
417 case BuildTarget.iOS:
418 return FMODPlatform.iOS;
419 case BuildTarget.PS4:
420 return FMODPlatform.PS4;
421 #if !UNITY_2019_2_OR_NEWER
422 case BuildTarget.StandaloneLinux:
424 case BuildTarget.StandaloneLinuxUniversal:
425 case BuildTarget.StandaloneLinux64:
426 return FMODPlatform.Linux;
427 case BuildTarget.StandaloneOSX:
428 return FMODPlatform.Mac;
429 case BuildTarget.StandaloneWindows:
430 case BuildTarget.StandaloneWindows64:
431 return FMODPlatform.Windows;
432 case BuildTarget.XboxOne:
433 return FMODPlatform.XboxOne;
434 case BuildTarget.WSAPlayer:
435 return FMODPlatform.UWP;
436 case BuildTarget.tvOS:
437 return FMODPlatform.AppleTV;
439 case BuildTarget.Switch:
440 return FMODPlatform.Switch;
443 case BuildTarget.WebGL:
444 return FMODPlatform.WebGL;
447 case BuildTarget.Stadia:
448 return FMODPlatform.Stadia;
451 return FMODPlatform.None;