#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms. ////////////////////////////////////////////////////////////////////// // // Copyright (c) 2017 Audiokinetic Inc. / All Rights Reserved // ////////////////////////////////////////////////////////////////////// /// @brief Contains C# functions exposed from the Wwise C++ API. /// /// The AkSoundEngine class contains functions converted to C# from the following C++ namespaces: /// - AK::Monitor /// - AK::MusicEngine /// - AK::SoundEngine /// - AK::SoundEngine::DynamicDialogue /// - AK::SoundEngine::Query /// - AK::SpatialAudio public partial class AkSoundEngine { #region String Marshalling /// /// Converts "char*" C-strings to C# strings. /// /// "char*" memory pointer passed to C# as an IntPtr. /// Converted string. public static string StringFromIntPtrString(System.IntPtr ptr) { return System.Runtime.InteropServices.Marshal.PtrToStringAnsi(ptr); } /// /// Converts "wchar_t*" C-strings to C# strings. /// /// "wchar_t*" memory pointer passed to C# as an IntPtr. /// Converted string. public static string StringFromIntPtrWString(System.IntPtr ptr) { return System.Runtime.InteropServices.Marshal.PtrToStringUni(ptr); } #endregion #region GameObject Hash Function /// /// The type for hash functions used to convert a Unity Game Object into an integer. /// /// The Unity Game Object. /// The AkGameObjectID used by the sound engine. public delegate ulong GameObjectHashFunction(UnityEngine.GameObject gameObject); private static ulong InternalGameObjectHash(UnityEngine.GameObject gameObject) { return gameObject == null ? AK_INVALID_GAME_OBJECT : (ulong) gameObject.GetInstanceID(); } /// /// The user assignable hash function used to convert a Unity Game Object into an AkGameObjectID used by the sound /// engine. Used by GetAkGameObjectID(). /// public static GameObjectHashFunction GameObjectHash { set { gameObjectHash = value == null ? InternalGameObjectHash : value; } } private static GameObjectHashFunction gameObjectHash = InternalGameObjectHash; /// /// The hash function used to convert a Unity Game Object into an AkGameObjectID used by the sound engine. /// public static ulong GetAkGameObjectID(UnityEngine.GameObject gameObject) { return gameObjectHash(gameObject); } #endregion #region Registration Functions /// /// Registers a Unity Game Object with an ID obtained from GetAkGameObjectID(). /// /// The Unity Game Object. /// public static AKRESULT RegisterGameObj(UnityEngine.GameObject gameObject) { var id = GetAkGameObjectID(gameObject); var res = (AKRESULT) AkSoundEnginePINVOKE.CSharp_RegisterGameObjInternal(id); PostRegisterGameObjUserHook(res, gameObject, id); return res; } /// /// Registers a Unity Game Object with an ID obtained from GetAkGameObjectID(). /// /// The Unity Game Object. /// The name that is visible in the Wwise Profiler. /// public static AKRESULT RegisterGameObj(UnityEngine.GameObject gameObject, string name) { var id = GetAkGameObjectID(gameObject); var res = (AKRESULT) AkSoundEnginePINVOKE.CSharp_RegisterGameObjInternal_WithName(id, name); PostRegisterGameObjUserHook(res, gameObject, id); return res; } /// /// Unregisters a Unity Game Object with an ID obtained from GetAkGameObjectID(). /// /// The Unity Game Object. /// public static AKRESULT UnregisterGameObj(UnityEngine.GameObject gameObject) { var id = GetAkGameObjectID(gameObject); var res = (AKRESULT) AkSoundEnginePINVOKE.CSharp_UnregisterGameObjInternal(id); PostUnregisterGameObjUserHook(res, gameObject, id); return res; } #endregion #region Helper Functions public static string WwiseVersion { get { var majorMinor = GetMajorMinorVersion(); var subminorBuild = GetSubminorBuildVersion(); var major = majorMinor >> 16; var minor = majorMinor & 0xFFFF; var subMinor = subminorBuild >> 16; var build = subminorBuild & 0xFFFF; return string.Format("{0}.{1}.{2} Build {3}", major, minor, subMinor, build); } } public static AKRESULT SetObjectPosition(UnityEngine.GameObject gameObject, UnityEngine.Transform transform) { var id = GetAkGameObjectID(gameObject); return (AKRESULT)AkSoundEnginePINVOKE.CSharp_SetObjectPosition(id, transform.position, transform.forward, transform.up); } public static AKRESULT SetObjectPosition(UnityEngine.GameObject gameObject, float posX, float posY, float posZ, float frontX, float frontY, float frontZ, float topX, float topY, float topZ) { var id = GetAkGameObjectID(gameObject); var position = new UnityEngine.Vector3(posX, posY, posZ); var forward = new UnityEngine.Vector3(frontX, frontY, frontZ); var up = new UnityEngine.Vector3(topX, topY, topZ); return (AKRESULT)AkSoundEnginePINVOKE.CSharp_SetObjectPosition(id, position, forward, up); } #endregion #region User Hooks public static void PreGameObjectAPICall(UnityEngine.GameObject gameObject, ulong id) { PreGameObjectAPICallUserHook(gameObject, id); } /// /// User hook called within all Wwise integration functions that receive GameObjects and do not perform /// (un)registration. This is called /// before values are sent to the native plugin code. An example use could be to register game objects that were not /// previously registered. /// /// The GameObject being processed. /// The ulong returned from GameObjectHash that represents this GameObject in Wwise. static partial void PreGameObjectAPICallUserHook(UnityEngine.GameObject gameObject, ulong id); /// /// User hook called after RegisterGameObj(). An example use could be to add the id and gameObject to a dictionary upon /// AK_Success. /// /// The result from calling RegisterGameObj() on gameObject. /// The GameObject that RegisterGameObj() was called on. /// The ulong returned from GameObjectHash that represents this GameObject in Wwise. static partial void PostRegisterGameObjUserHook(AKRESULT result, UnityEngine.GameObject gameObject, ulong id); /// /// User hook called after UnregisterGameObj(). An example use could be to remove the id and gameObject from a /// dictionary upon AK_Success. /// /// The result from calling UnregisterGameObj() on gameObject. /// The GameObject that UnregisterGameObj() was called on. /// The ulong returned from GameObjectHash that represents this GameObject in Wwise. static partial void PostUnregisterGameObjUserHook(AKRESULT result, UnityEngine.GameObject gameObject, ulong id); #endregion #region Deprecation Strings public const string Deprecation_2018_1_2 = "This functionality is deprecated as of Wwise v2018.1.2 and will be removed in a future release."; public const string Deprecation_2018_1_6 = "This functionality is deprecated as of Wwise v2018.1.6 and will be removed in a future release."; public const string Deprecation_2019_2_0 = "This functionality is deprecated as of Wwise v2019.2.0 and will be removed in a future release."; public const string Deprecation_2019_2_2 = "This functionality is deprecated as of Wwise v2019.2.2 and will be removed in a future release."; #endregion } #endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.