2021-02-27 20:53:36 +00:00
|
|
|
#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
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2021-04-30 07:09:07 +01:00
|
|
|
using System;
|
|
|
|
|
|
2021-02-27 20:53:36 +00:00
|
|
|
public partial class AkSoundEngine
|
|
|
|
|
{
|
|
|
|
|
#region User Hooks - Extended for Auto-Registration
|
|
|
|
|
|
2021-04-30 07:09:07 +01:00
|
|
|
private const string AkGameObjTypeString = "AkGameObj, AK.Wwise.Unity.MonoBehaviour";
|
|
|
|
|
|
2021-02-27 20:53:36 +00:00
|
|
|
private class AutoObject
|
|
|
|
|
{
|
|
|
|
|
private readonly UnityEngine.GameObject gameObject;
|
|
|
|
|
|
|
|
|
|
public AutoObject(UnityEngine.GameObject go)
|
|
|
|
|
{
|
|
|
|
|
gameObject = go;
|
|
|
|
|
RegisterGameObj(gameObject, gameObject != null ? "AkAutoObject for " + gameObject.name : "AkAutoObject");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~AutoObject()
|
|
|
|
|
{
|
|
|
|
|
UnregisterGameObj(gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void AutoRegister(UnityEngine.GameObject gameObject, ulong id)
|
|
|
|
|
{
|
2021-04-30 07:09:07 +01:00
|
|
|
Type AkGameObjectType = Type.GetType(AkGameObjTypeString);
|
|
|
|
|
|
2021-02-27 20:53:36 +00:00
|
|
|
if (gameObject == null || !gameObject.activeInHierarchy)
|
2021-04-30 07:09:07 +01:00
|
|
|
{
|
2021-02-27 20:53:36 +00:00
|
|
|
new AutoObject(gameObject);
|
2021-04-30 07:09:07 +01:00
|
|
|
}
|
|
|
|
|
else if (gameObject.GetComponent(AkGameObjectType) == null)
|
|
|
|
|
{
|
|
|
|
|
gameObject.AddComponent(AkGameObjectType);
|
|
|
|
|
}
|
2021-02-27 20:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static partial void PreGameObjectAPICallUserHook(UnityEngine.GameObject gameObject, ulong id)
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
if (!UnityEngine.Application.isPlaying)
|
|
|
|
|
{
|
|
|
|
|
AutoRegister(gameObject, id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (!IsInRegisteredList(id) && IsInitialized())
|
|
|
|
|
AutoRegister(gameObject, id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static readonly System.Collections.Generic.HashSet<ulong> RegisteredGameObjects =
|
|
|
|
|
new System.Collections.Generic.HashSet<ulong>();
|
|
|
|
|
|
|
|
|
|
static partial void PostRegisterGameObjUserHook(AKRESULT result, UnityEngine.GameObject gameObject, ulong id)
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
if (!UnityEngine.Application.isPlaying)
|
|
|
|
|
return;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (result == AKRESULT.AK_Success)
|
|
|
|
|
RegisteredGameObjects.Add(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static partial void PostUnregisterGameObjUserHook(AKRESULT result, UnityEngine.GameObject gameObject, ulong id)
|
|
|
|
|
{
|
|
|
|
|
if (result == AKRESULT.AK_Success)
|
|
|
|
|
RegisteredGameObjects.Remove(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper method that a user might want to implement
|
|
|
|
|
private static bool IsInRegisteredList(ulong id)
|
|
|
|
|
{
|
|
|
|
|
return RegisteredGameObjects.Contains(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Helper method that a user might want to implement
|
|
|
|
|
public static bool IsGameObjectRegistered(UnityEngine.GameObject in_gameObject)
|
|
|
|
|
{
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
if (!UnityEngine.Application.isPlaying)
|
2021-04-30 07:09:07 +01:00
|
|
|
{
|
|
|
|
|
return in_gameObject.GetComponent(AkGameObjTypeString) != null;
|
|
|
|
|
}
|
2021-02-27 20:53:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return IsInRegisteredList(GetAkGameObjectID(in_gameObject));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
#endif // #if !(UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|