Initial Wwise Integration
Created wwise project Integrated inventory UI sounds Improved projectile weapon behavior (randomized start position, stopped them from self-destructing at target range when airburst is disabled)
This commit is contained in:
parent
b53e4aec8c
commit
db8c3c7779
1019 changed files with 76372 additions and 110 deletions
270
Assets/Wwise/Deployment/Components/AkAmbient.cs
Normal file
270
Assets/Wwise/Deployment/Components/AkAmbient.cs
Normal file
|
|
@ -0,0 +1,270 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public enum MultiPositionTypeLabel
|
||||
{
|
||||
Simple_Mode,
|
||||
Large_Mode,
|
||||
MultiPosition_Mode
|
||||
}
|
||||
|
||||
public class AkMultiPosEvent
|
||||
{
|
||||
public bool eventIsPlaying;
|
||||
public System.Collections.Generic.List<AkAmbient> list = new System.Collections.Generic.List<AkAmbient>();
|
||||
|
||||
public void FinishedPlaying(object in_cookie, AkCallbackType in_type, object in_info)
|
||||
{
|
||||
eventIsPlaying = false;
|
||||
}
|
||||
}
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkAmbient")]
|
||||
/// @brief Use this component to attach a Wwise Event to any object in a scene.
|
||||
/// The sound can be started at various moments, dependent on the selected Unity trigger. This component is more useful for ambient sounds (sounds related to scene-bound objects) but could also be used for other purposes.
|
||||
/// Since AkAmbient has AkEvent as its base class, it features the play/stop, play multiple, stop multiple and stop all buttons for previewing the associated Wwise event.
|
||||
/// \sa
|
||||
/// - \ref unity_use_AkEvent_AkAmbient
|
||||
/// - \ref AkGameObj
|
||||
/// - \ref AkEvent
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__events.html" target="_blank">Integration Details - Events</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
public class AkAmbient : AkEvent
|
||||
{
|
||||
public static System.Collections.Generic.Dictionary<uint, AkMultiPosEvent> multiPosEventTree =
|
||||
new System.Collections.Generic.Dictionary<uint, AkMultiPosEvent>();
|
||||
|
||||
public AkMultiPositionType MultiPositionType = AkMultiPositionType.MultiPositionType_MultiSources;
|
||||
public MultiPositionTypeLabel multiPositionTypeLabel = MultiPositionTypeLabel.Simple_Mode;
|
||||
|
||||
public AkAmbientLargeModePositioner[] LargeModePositions;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (multiPositionTypeLabel == MultiPositionTypeLabel.MultiPosition_Mode)
|
||||
{
|
||||
var gameObj = gameObject.GetComponents<AkGameObj>();
|
||||
for (var i = 0; i < gameObj.Length; i++)
|
||||
gameObj[i].enabled = false;
|
||||
|
||||
AkMultiPosEvent eventPosList;
|
||||
|
||||
if (multiPosEventTree.TryGetValue(data.Id, out eventPosList))
|
||||
{
|
||||
if (!eventPosList.list.Contains(this))
|
||||
eventPosList.list.Add(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventPosList = new AkMultiPosEvent();
|
||||
eventPosList.list.Add(this);
|
||||
multiPosEventTree.Add(data.Id, eventPosList);
|
||||
}
|
||||
|
||||
var positionArray = BuildMultiDirectionArray(eventPosList);
|
||||
|
||||
//Set multiple positions
|
||||
AkSoundEngine.SetMultiplePositions(eventPosList.list[0].gameObject, positionArray, (ushort) positionArray.Count,
|
||||
MultiPositionType);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
if (multiPositionTypeLabel == MultiPositionTypeLabel.Simple_Mode)
|
||||
{
|
||||
var gameObj = gameObject.GetComponents<AkGameObj>();
|
||||
for (var i = 0; i < gameObj.Length; i++)
|
||||
gameObj[i].enabled = true;
|
||||
}
|
||||
else if (multiPositionTypeLabel == MultiPositionTypeLabel.Large_Mode)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
var gameObj = gameObject.GetComponents<AkGameObj>();
|
||||
for (var i = 0; i < gameObj.Length; i++)
|
||||
gameObj[i].enabled = false;
|
||||
|
||||
var positionArray = BuildAkPositionArray();
|
||||
AkSoundEngine.SetMultiplePositions(gameObject, positionArray, (ushort)positionArray.Count, MultiPositionType);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (multiPositionTypeLabel == MultiPositionTypeLabel.MultiPosition_Mode)
|
||||
{
|
||||
var eventPosList = multiPosEventTree[data.Id];
|
||||
|
||||
if (eventPosList.list.Count == 1)
|
||||
multiPosEventTree.Remove(data.Id);
|
||||
else
|
||||
{
|
||||
eventPosList.list.Remove(this);
|
||||
|
||||
var positionArray = BuildMultiDirectionArray(eventPosList);
|
||||
AkSoundEngine.SetMultiplePositions(eventPosList.list[0].gameObject, positionArray, (ushort) positionArray.Count,
|
||||
MultiPositionType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleEvent(UnityEngine.GameObject in_gameObject)
|
||||
{
|
||||
if (multiPositionTypeLabel != MultiPositionTypeLabel.MultiPosition_Mode)
|
||||
{
|
||||
base.HandleEvent(in_gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
var multiPositionSoundEmitter = multiPosEventTree[data.Id];
|
||||
if (multiPositionSoundEmitter.eventIsPlaying)
|
||||
return;
|
||||
|
||||
multiPositionSoundEmitter.eventIsPlaying = true;
|
||||
|
||||
soundEmitterObject = multiPositionSoundEmitter.list[0].gameObject;
|
||||
|
||||
if (enableActionOnEvent)
|
||||
data.ExecuteAction(soundEmitterObject, actionOnEventType, (int)transitionDuration * 1000, curveInterpolation);
|
||||
else
|
||||
playingId = data.Post(soundEmitterObject, (uint)AkCallbackType.AK_EndOfEvent, multiPositionSoundEmitter.FinishedPlaying);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnDrawGizmosSelected()
|
||||
{
|
||||
UnityEngine.Gizmos.DrawIcon(transform.position, "WwiseAudioSpeaker.png", false);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (multiPositionTypeLabel == MultiPositionTypeLabel.Large_Mode)
|
||||
{
|
||||
foreach (var entry in LargeModePositions)
|
||||
{
|
||||
if (entry != null)
|
||||
{
|
||||
UnityEngine.Gizmos.color = UnityEngine.Color.green;
|
||||
UnityEngine.Gizmos.DrawSphere(entry.transform.position, 0.1f);
|
||||
|
||||
UnityEditor.Handles.Label(entry.transform.position, entry.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public AkPositionArray BuildMultiDirectionArray(AkMultiPosEvent eventPosList)
|
||||
{
|
||||
var positionArray = new AkPositionArray((uint) eventPosList.list.Count);
|
||||
for (var i = 0; i < eventPosList.list.Count; i++)
|
||||
{
|
||||
positionArray.Add(eventPosList.list[i].transform.position, eventPosList.list[i].transform.forward,
|
||||
eventPosList.list[i].transform.up);
|
||||
}
|
||||
|
||||
return positionArray;
|
||||
}
|
||||
|
||||
private AkPositionArray BuildAkPositionArray()
|
||||
{
|
||||
var validPositionList = new System.Collections.Generic.List<AkAmbientLargeModePositioner>();
|
||||
|
||||
for( int i= 0; i < LargeModePositions.Length; ++i)
|
||||
{
|
||||
if (LargeModePositions[i] != null)
|
||||
{
|
||||
if (!validPositionList.Contains(LargeModePositions[i]))
|
||||
{
|
||||
validPositionList.Add(LargeModePositions[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var positionArray = new AkPositionArray((uint)validPositionList.Count);
|
||||
for (int i = 0; i < validPositionList.Count; ++i)
|
||||
{
|
||||
positionArray.Add(validPositionList[i].Position, validPositionList[i].Forward, validPositionList[i].Up);
|
||||
}
|
||||
|
||||
return positionArray;
|
||||
}
|
||||
|
||||
#region WwiseMigration
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
public System.Collections.Generic.List<UnityEngine.Vector3> multiPositionArray = null;
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public override bool Migrate(UnityEditor.SerializedObject obj)
|
||||
{
|
||||
var hasMigrated = base.Migrate(obj);
|
||||
|
||||
if (!AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.AkAmbient_v2019_1_0))
|
||||
{
|
||||
return hasMigrated;
|
||||
}
|
||||
|
||||
var multiPositionTypeLabelProperty = obj.FindProperty("multiPositionTypeLabel");
|
||||
if (multiPositionTypeLabelProperty == null)
|
||||
{
|
||||
return hasMigrated;
|
||||
}
|
||||
|
||||
if (multiPositionTypeLabelProperty.intValue != (int)MultiPositionTypeLabel.Large_Mode)
|
||||
{
|
||||
return hasMigrated;
|
||||
}
|
||||
|
||||
var multiPositionArrayProperty = obj.FindProperty("multiPositionArray");
|
||||
if (multiPositionArrayProperty == null)
|
||||
{
|
||||
return hasMigrated;
|
||||
}
|
||||
|
||||
if (multiPositionArrayProperty.arraySize == 0)
|
||||
{
|
||||
return hasMigrated;
|
||||
}
|
||||
|
||||
var largeModePositionsProperty = obj.FindProperty("LargeModePositions");
|
||||
if (largeModePositionsProperty == null)
|
||||
{
|
||||
return hasMigrated;
|
||||
}
|
||||
|
||||
largeModePositionsProperty.arraySize = multiPositionArrayProperty.arraySize;
|
||||
|
||||
for (int point = 0; point < multiPositionArrayProperty.arraySize; ++point)
|
||||
{
|
||||
var elementProperty = multiPositionArrayProperty.GetArrayElementAtIndex(point);
|
||||
|
||||
var largeModePositionElementProperty = largeModePositionsProperty.GetArrayElementAtIndex(point);
|
||||
if (largeModePositionElementProperty != null)
|
||||
{
|
||||
var newPoint = new UnityEngine.GameObject("AkAmbientPoint" + point.ToString());
|
||||
newPoint.AddComponent<AkAmbientLargeModePositioner>();
|
||||
newPoint.transform.SetParent(transform);
|
||||
newPoint.transform.position = transform.TransformPoint(elementProperty.vector3Value);
|
||||
|
||||
largeModePositionElementProperty.objectReferenceValue = newPoint.GetComponent<AkAmbientLargeModePositioner>();
|
||||
}
|
||||
}
|
||||
|
||||
multiPositionArrayProperty.arraySize = 0;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkAmbient.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkAmbient.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e6a98c45007fbec48b47b122c40889c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
||||
/// @brief Use this component to add a Large Mode position to any AkAmbient in a Scene.
|
||||
/// \sa
|
||||
/// - \ref unity_use_AkEvent_AkAmbient
|
||||
/// - \ref AkAmbient
|
||||
public class AkAmbientLargeModePositioner : UnityEngine.MonoBehaviour
|
||||
{
|
||||
public UnityEngine.Vector3 Position
|
||||
{
|
||||
get
|
||||
{
|
||||
return transform.position;
|
||||
}
|
||||
}
|
||||
|
||||
public UnityEngine.Vector3 Forward
|
||||
{
|
||||
get
|
||||
{
|
||||
return transform.forward;
|
||||
}
|
||||
}
|
||||
|
||||
public UnityEngine.Vector3 Up
|
||||
{
|
||||
get
|
||||
{
|
||||
return transform.up;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnDrawGizmosSelected()
|
||||
{
|
||||
UnityEngine.Gizmos.color = UnityEngine.Color.green;
|
||||
UnityEngine.Gizmos.DrawSphere(transform.position, 0.1f);
|
||||
|
||||
UnityEditor.Handles.Label(transform.position, name);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: da37d49e036a3cf4bb6a17e6f506ccc3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
188
Assets/Wwise/Deployment/Components/AkAudioListener.cs
Normal file
188
Assets/Wwise/Deployment/Components/AkAudioListener.cs
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
#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
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkAudioListener")]
|
||||
[UnityEngine.RequireComponent(typeof(AkGameObj))]
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
[UnityEngine.DefaultExecutionOrder(-50)]
|
||||
///@brief Add this script on the game object that represent a listener. This is normally added to the Camera object or the Player object, but can be added to any game object when implementing 3D busses. \c isDefaultListener determines whether the game object will be considered a default listener - a listener that automatically listens to all game objects that do not have listeners attached to their AkGameObjListenerList's.
|
||||
/// \sa
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__listeners.html" target="_blank">Integrating Listeners</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
public class AkAudioListener : UnityEngine.MonoBehaviour
|
||||
{
|
||||
private static readonly DefaultListenerList defaultListeners = new DefaultListenerList();
|
||||
private ulong akGameObjectID = AkSoundEngine.AK_INVALID_GAME_OBJECT;
|
||||
private System.Collections.Generic.List<AkGameObj> EmittersToStartListeningTo =
|
||||
new System.Collections.Generic.List<AkGameObj>();
|
||||
private System.Collections.Generic.List<AkGameObj> EmittersToStopListeningTo =
|
||||
new System.Collections.Generic.List<AkGameObj>();
|
||||
|
||||
public bool isDefaultListener = true;
|
||||
|
||||
public static DefaultListenerList DefaultListeners
|
||||
{
|
||||
get { return defaultListeners; }
|
||||
}
|
||||
|
||||
public void StartListeningToEmitter(AkGameObj emitter)
|
||||
{
|
||||
EmittersToStartListeningTo.Add(emitter);
|
||||
EmittersToStopListeningTo.Remove(emitter);
|
||||
}
|
||||
|
||||
public void StopListeningToEmitter(AkGameObj emitter)
|
||||
{
|
||||
EmittersToStartListeningTo.Remove(emitter);
|
||||
EmittersToStopListeningTo.Add(emitter);
|
||||
}
|
||||
|
||||
public void SetIsDefaultListener(bool isDefault)
|
||||
{
|
||||
if (isDefaultListener != isDefault)
|
||||
{
|
||||
isDefaultListener = isDefault;
|
||||
|
||||
if (isDefault)
|
||||
DefaultListeners.Add(this);
|
||||
else
|
||||
DefaultListeners.Remove(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var akGameObj = GetComponent<AkGameObj>();
|
||||
UnityEngine.Debug.Assert(akGameObj != null);
|
||||
if (akGameObj)
|
||||
akGameObj.Register();
|
||||
|
||||
akGameObjectID = AkSoundEngine.GetAkGameObjectID(gameObject);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (isDefaultListener)
|
||||
DefaultListeners.Add(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (isDefaultListener)
|
||||
DefaultListeners.Remove(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
for (var i = 0; i < EmittersToStartListeningTo.Count; ++i)
|
||||
EmittersToStartListeningTo[i].AddListener(this);
|
||||
EmittersToStartListeningTo.Clear();
|
||||
|
||||
for (var i = 0; i < EmittersToStopListeningTo.Count; ++i)
|
||||
EmittersToStopListeningTo[i].RemoveListener(this);
|
||||
EmittersToStopListeningTo.Clear();
|
||||
}
|
||||
|
||||
public ulong GetAkGameObjectID()
|
||||
{
|
||||
return akGameObjectID;
|
||||
}
|
||||
|
||||
public class BaseListenerList
|
||||
{
|
||||
// @todo: Use HashSet<ulong> and CopyTo() with a private ulong[]
|
||||
private readonly System.Collections.Generic.List<ulong> listenerIdList = new System.Collections.Generic.List<ulong>();
|
||||
|
||||
private readonly System.Collections.Generic.List<AkAudioListener> listenerList =
|
||||
new System.Collections.Generic.List<AkAudioListener>();
|
||||
|
||||
public System.Collections.Generic.List<AkAudioListener> ListenerList
|
||||
{
|
||||
get { return listenerList; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uniquely adds listeners to the list
|
||||
/// </summary>
|
||||
/// <param name="listener"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool Add(AkAudioListener listener)
|
||||
{
|
||||
if (listener == null)
|
||||
return false;
|
||||
|
||||
var gameObjectId = listener.GetAkGameObjectID();
|
||||
if (listenerIdList.Contains(gameObjectId))
|
||||
return false;
|
||||
|
||||
listenerIdList.Add(gameObjectId);
|
||||
listenerList.Add(listener);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes listeners from the list
|
||||
/// </summary>
|
||||
/// <param name="listener"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool Remove(AkAudioListener listener)
|
||||
{
|
||||
if (listener == null)
|
||||
return false;
|
||||
|
||||
var gameObjectId = listener.GetAkGameObjectID();
|
||||
if (!listenerIdList.Remove(gameObjectId))
|
||||
return false;
|
||||
|
||||
listenerList.Remove(listener);
|
||||
return true;
|
||||
}
|
||||
|
||||
public ulong[] GetListenerIds()
|
||||
{
|
||||
return listenerIdList.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public class DefaultListenerList : BaseListenerList
|
||||
{
|
||||
public override bool Add(AkAudioListener listener)
|
||||
{
|
||||
var ret = base.Add(listener);
|
||||
if (ret && AkSoundEngine.IsInitialized())
|
||||
AkSoundEngine.AddDefaultListener(listener.gameObject);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override bool Remove(AkAudioListener listener)
|
||||
{
|
||||
var ret = base.Remove(listener);
|
||||
if (ret && AkSoundEngine.IsInitialized())
|
||||
AkSoundEngine.RemoveDefaultListener(listener.gameObject);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
#region WwiseMigration
|
||||
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
|
||||
[UnityEngine.SerializeField]
|
||||
// Wwise v2016.2 and below supported up to 8 listeners[0-7].
|
||||
public int listenerId = 0;
|
||||
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
public void Migrate14()
|
||||
{
|
||||
var wasDefaultListener = listenerId == 0;
|
||||
UnityEngine.Debug.Log("WwiseUnity: AkAudioListener.Migrate14 for " + gameObject.name);
|
||||
isDefaultListener = wasDefaultListener;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkAudioListener.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkAudioListener.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4ae335524e949404bb57f1612ec4b9b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
134
Assets/Wwise/Deployment/Components/AkBank.cs
Normal file
134
Assets/Wwise/Deployment/Components/AkBank.cs
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkBank")]
|
||||
[UnityEngine.ExecuteInEditMode]
|
||||
[UnityEngine.DefaultExecutionOrder(-75)]
|
||||
/// @brief Loads and unloads a SoundBank at a specified moment. Vorbis sounds can be decompressed at a specified moment using the decode compressed data option. In that case, the SoundBank will be prepared.
|
||||
public class AkBank : AkTriggerHandler
|
||||
#if UNITY_EDITOR
|
||||
, AK.Wwise.IMigratable
|
||||
#endif
|
||||
{
|
||||
public AK.Wwise.Bank data = new AK.Wwise.Bank();
|
||||
|
||||
/// Decode this SoundBank upon load
|
||||
public bool decodeBank = false;
|
||||
|
||||
/// Check this to load the SoundBank in the background. Be careful, if Events are triggered and the SoundBank hasn't finished loading, you'll have "Event not found" errors.
|
||||
public bool loadAsynchronous = false;
|
||||
|
||||
/// Save the decoded SoundBank to disk for faster loads in the future
|
||||
public bool saveDecodedBank = false;
|
||||
|
||||
/// Reserved.
|
||||
public System.Collections.Generic.List<int> unloadTriggerList =
|
||||
new System.Collections.Generic.List<int> { DESTROY_TRIGGER_ID };
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating)
|
||||
return;
|
||||
|
||||
var reference = AkUtilities.DragAndDropObjectReference;
|
||||
if (reference)
|
||||
{
|
||||
UnityEngine.GUIUtility.hotControl = 0;
|
||||
data.ObjectReference = reference;
|
||||
}
|
||||
#endif
|
||||
|
||||
base.Awake();
|
||||
|
||||
RegisterTriggers(unloadTriggerList, UnloadBank);
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating)
|
||||
return;
|
||||
#endif
|
||||
|
||||
base.Start();
|
||||
|
||||
//Call the UnloadBank function if registered to the Start Trigger
|
||||
if (unloadTriggerList.Contains(START_TRIGGER_ID))
|
||||
UnloadBank(null);
|
||||
}
|
||||
|
||||
/// Loads the SoundBank
|
||||
public override void HandleEvent(UnityEngine.GameObject in_gameObject)
|
||||
{
|
||||
if (!loadAsynchronous)
|
||||
data.Load(decodeBank, saveDecodedBank);
|
||||
else
|
||||
data.LoadAsync();
|
||||
}
|
||||
|
||||
/// Unloads a SoundBank
|
||||
public void UnloadBank(UnityEngine.GameObject in_gameObject)
|
||||
{
|
||||
data.Unload();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating)
|
||||
return;
|
||||
#endif
|
||||
|
||||
base.OnDestroy();
|
||||
|
||||
UnregisterTriggers(unloadTriggerList, UnloadBank);
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public string bankName { get { return data == null ? string.Empty : data.Name; } }
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public byte[] valueGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var objRef = data.ObjectReference;
|
||||
return !objRef ? null : objRef.Guid.ToByteArray();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WwiseMigration
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("bankName")]
|
||||
private string bankNameInternal;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("valueGuid")]
|
||||
private byte[] valueGuidInternal;
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
bool AK.Wwise.IMigratable.Migrate(UnityEditor.SerializedObject obj)
|
||||
{
|
||||
if (!AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.WwiseTypes_v2018_1_6))
|
||||
return false;
|
||||
|
||||
return AK.Wwise.TypeMigration.ProcessSingleGuidType(obj.FindProperty("data.WwiseObjectReference"), WwiseObjectType.Soundbank,
|
||||
obj.FindProperty("valueGuidInternal"), obj.FindProperty("bankNameInternal"));
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkBank.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkBank.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d1f1a89fa3598c644a67edc70006ab8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/Wwise/Deployment/Components/AkEarlyReflections.cs
Normal file
40
Assets/Wwise/Deployment/Components/AkEarlyReflections.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkEarlyReflections")]
|
||||
[UnityEngine.RequireComponent(typeof(AkGameObj))]
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
///@brief Set an early reflections auxiliary bus and send volume for a particular game object.
|
||||
public class AkEarlyReflections : UnityEngine.MonoBehaviour
|
||||
{
|
||||
[UnityEngine.Tooltip("The early reflections auxiliary bus for all sounds playing on this particular game object. The early reflection auxiliary bus specified in the authoring tool has precedence.")]
|
||||
/// The early reflections auxiliary bus for this particular game object.
|
||||
/// Geometrical reflection calculation inside spatial audio is enabled for a game object if any sound playing on the game object has a valid early reflections aux bus specified in the authoring tool,
|
||||
/// or if an aux bus is specified via this parameter. The early reflection auxiliary bus specified in the authoring tool has precedence.
|
||||
/// Users may apply this function to avoid duplicating sounds in the actor-mixer hierarchy solely for the sake of specifying a unique early reflection bus, or in any situation where the same
|
||||
/// sound should be played on different game objects with different early reflection aux buses (the early reflection bus must be left blank in the authoring tool if the user intends to specify it through the API).
|
||||
public AK.Wwise.AuxBus reflectionsAuxBus = new AK.Wwise.AuxBus();
|
||||
|
||||
[UnityEngine.Range(0, 1)]
|
||||
[UnityEngine.Tooltip("The early reflections send volume for all sounds playing on this particular game object. It is combined with the early reflections volume specified in the authoring tool.")]
|
||||
/// The early reflections send volume for this particular game object.
|
||||
/// This parameter is used to control the volume of the early reflections send. It is combined with the early reflections volume specified in the authoring tool, and is applied to all sounds playing on the game object.
|
||||
/// Setting to 0.f will disable all reflection processing for this game object. Valid range 0.f-1.f.
|
||||
public float reflectionsVolume = 1;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (reflectionsAuxBus != null)
|
||||
AkSoundEngine.SetEarlyReflectionsAuxSend(gameObject, reflectionsAuxBus.Id);
|
||||
|
||||
AkSoundEngine.SetEarlyReflectionsVolume(gameObject, reflectionsVolume);
|
||||
}
|
||||
|
||||
public void SetEarlyReflectionsVolume(float volume)
|
||||
{
|
||||
if (reflectionsVolume != volume)
|
||||
{
|
||||
AkSoundEngine.SetEarlyReflectionsVolume(gameObject, volume);
|
||||
reflectionsVolume = volume;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d47632552aa0da4428ba10a9f6e1cfc5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkEmitterObstructionOcclusion")]
|
||||
[UnityEngine.RequireComponent(typeof(AkGameObj))]
|
||||
/// @brief Completely obstructs/occludes the emitter of the current game object from its listeners if at least one object is between them.
|
||||
public class AkEmitterObstructionOcclusion : AkObstructionOcclusion
|
||||
{
|
||||
private AkGameObj m_gameObj;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitIntervalsAndFadeRates();
|
||||
m_gameObj = GetComponent<AkGameObj>();
|
||||
}
|
||||
|
||||
protected override void UpdateCurrentListenerList()
|
||||
{
|
||||
if (AkSpatialAudioListener.TheSpatialAudioListener != null && AkRoom.RoomCount > 0)
|
||||
{
|
||||
currentListenerList.Add(AkSpatialAudioListener.TheSpatialAudioListener);
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_gameObj.IsUsingDefaultListeners)
|
||||
currentListenerList.AddRange(AkAudioListener.DefaultListeners.ListenerList);
|
||||
currentListenerList.AddRange(m_gameObj.ListenerList);
|
||||
}
|
||||
|
||||
protected override void SetObstructionOcclusion(
|
||||
System.Collections.Generic.KeyValuePair<AkAudioListener, ObstructionOcclusionValue> ObsOccPair)
|
||||
{
|
||||
if (AkSpatialAudioListener.TheSpatialAudioListener != null && AkRoom.RoomCount > 0)
|
||||
AkSoundEngine.SetObjectObstructionAndOcclusion(gameObject, ObsOccPair.Key.gameObject, ObsOccPair.Value.currentValue, 0.0f);
|
||||
else
|
||||
AkSoundEngine.SetObjectObstructionAndOcclusion(gameObject, ObsOccPair.Key.gameObject, 0.0f, ObsOccPair.Value.currentValue);
|
||||
}
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 696b0e79afa8c8f488bc5457df688a7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
146
Assets/Wwise/Deployment/Components/AkEnvironment.cs
Normal file
146
Assets/Wwise/Deployment/Components/AkEnvironment.cs
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkEnvironment")]
|
||||
[UnityEngine.RequireComponent(typeof(UnityEngine.Collider))]
|
||||
[UnityEngine.ExecuteInEditMode]
|
||||
/// @brief Use this component to define a reverb zone. This needs to be added to a collider object to work properly. See \ref unity_use_AkEnvironment_AknEvironmentPortal.
|
||||
/// @details This component can be attached to any collider. You can specify a roll-off to fade-in/out of the reverb.
|
||||
/// The reverb parameters will be defined in the Wwise project, by the sound designer. All AkGameObj that are
|
||||
/// "environment"-aware will receive a send value when entering the attached collider.
|
||||
/// \sa
|
||||
/// - \ref unity_use_AkEnvironment_AkEnvironmentPortal
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=integrating__elements__environments.html" target="_blank">Integrating Environments and Game-defined Auxiliary Sends</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=namespace_a_k_1_1_sound_engine_a18f56e8e0e881c4efb9080545efbb233.html#a18f56e8e0e881c4efb9080545efbb233" target="_blank">AK::SoundEngine::SetGameObjectAuxSendValues</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
public class AkEnvironment : UnityEngine.MonoBehaviour
|
||||
#if UNITY_EDITOR
|
||||
, AK.Wwise.IMigratable
|
||||
#endif
|
||||
{
|
||||
public const int MAX_NB_ENVIRONMENTS = 4;
|
||||
|
||||
public static AkEnvironment_CompareByPriority s_compareByPriority = new AkEnvironment_CompareByPriority();
|
||||
|
||||
public static AkEnvironment_CompareBySelectionAlgorithm s_compareBySelectionAlgorithm =
|
||||
new AkEnvironment_CompareBySelectionAlgorithm();
|
||||
|
||||
//if excludeOthers, then only the environment with the excludeOthers flag set to true and with the highest priority will be active
|
||||
public bool excludeOthers = false;
|
||||
|
||||
//if isDefault, then this environment will be bumped out if any other is present
|
||||
public bool isDefault = false;
|
||||
|
||||
public AK.Wwise.AuxBus data = new AK.Wwise.AuxBus();
|
||||
|
||||
//Cache of the colliders for this environment, to avoid calls to GetComponent.
|
||||
public UnityEngine.Collider Collider { get; private set; }
|
||||
|
||||
//smaller number has a higher priority
|
||||
public int priority = 0;
|
||||
|
||||
public void Awake()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var reference = AkUtilities.DragAndDropObjectReference;
|
||||
if (reference)
|
||||
{
|
||||
UnityEngine.GUIUtility.hotControl = 0;
|
||||
data.ObjectReference = reference;
|
||||
}
|
||||
#endif
|
||||
|
||||
Collider = GetComponent<UnityEngine.Collider>();
|
||||
}
|
||||
|
||||
/// @brief Sorts AkEnvironments based on their priorities.
|
||||
public class AkEnvironment_CompareByPriority : System.Collections.Generic.IComparer<AkEnvironment>
|
||||
{
|
||||
public virtual int Compare(AkEnvironment a, AkEnvironment b)
|
||||
{
|
||||
var result = a.priority.CompareTo(b.priority);
|
||||
return result == 0 && a != b ? 1 : result;
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief Sorts AkEnvironments based on the selection algorithm.
|
||||
/// The selection algorithm is as follows:
|
||||
/// -# Environments have priorities.
|
||||
/// -# Environments have a "Default" flag. This flag effectively says that this environment will be bumped out if any other is present.
|
||||
/// -# Environments have an "Exclude Other" flag. This flag will tell that this env is not overlappable with others. So, only one (the highest priority) should be selected.
|
||||
public class AkEnvironment_CompareBySelectionAlgorithm : AkEnvironment_CompareByPriority
|
||||
{
|
||||
public override int Compare(AkEnvironment a, AkEnvironment b)
|
||||
{
|
||||
if (a.isDefault)
|
||||
return b.isDefault ? base.Compare(a, b) : 1;
|
||||
|
||||
if (b.isDefault)
|
||||
return -1;
|
||||
|
||||
if (a.excludeOthers)
|
||||
return b.excludeOthers ? base.Compare(a, b) : -1;
|
||||
|
||||
return b.excludeOthers ? 1 : base.Compare(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_2)]
|
||||
public int m_auxBusID { get { return (int)(data == null ? AkSoundEngine.AK_INVALID_UNIQUE_ID : data.Id); } }
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public byte[] valueGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var objRef = data.ObjectReference;
|
||||
return !objRef ? null : objRef.Guid.ToByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_2)]
|
||||
public uint GetAuxBusID()
|
||||
{
|
||||
return data.Id;
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public UnityEngine.Collider GetCollider()
|
||||
{
|
||||
return Collider;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WwiseMigration
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("m_auxBusID")]
|
||||
private int auxBusIdInternal = (int)AkSoundEngine.AK_INVALID_UNIQUE_ID;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("valueGuid")]
|
||||
private byte[] valueGuidInternal;
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
bool AK.Wwise.IMigratable.Migrate(UnityEditor.SerializedObject obj)
|
||||
{
|
||||
if (!AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.WwiseTypes_v2018_1_6))
|
||||
return false;
|
||||
|
||||
return AK.Wwise.TypeMigration.ProcessSingleGuidType(obj.FindProperty("data.WwiseObjectReference"), WwiseObjectType.AuxBus,
|
||||
obj.FindProperty("valueGuidInternal"), obj.FindProperty("auxBusIdInternal"));
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkEnvironment.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkEnvironment.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 692e16fdf21b6ae468a8a3cd39348200
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
93
Assets/Wwise/Deployment/Components/AkEnvironmentPortal.cs
Normal file
93
Assets/Wwise/Deployment/Components/AkEnvironmentPortal.cs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// @brief Use this component to define an area that straddles two different AkEnvironment's zones and allow mixing between both zones. \ref unity_use_AkEvironment_AkEvironmentPortal
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkEnvironmentPortal")]
|
||||
[UnityEngine.RequireComponent(typeof(UnityEngine.BoxCollider))]
|
||||
[UnityEngine.ExecuteInEditMode]
|
||||
public class AkEnvironmentPortal : UnityEngine.MonoBehaviour
|
||||
{
|
||||
public const int MAX_ENVIRONMENTS_PER_PORTAL = 2;
|
||||
|
||||
///The axis used to find the contribution of each environment
|
||||
public UnityEngine.Vector3 axis = UnityEngine.Vector3.right;
|
||||
|
||||
///The array is already sorted by position.
|
||||
///The first environment is on the negative side of the portal(opposite to the direction of the chosen axis)
|
||||
///The second environment is on the positive side of the portal
|
||||
public AkEnvironment[] environments = new AkEnvironment[MAX_ENVIRONMENTS_PER_PORTAL];
|
||||
|
||||
private UnityEngine.BoxCollider m_BoxCollider;
|
||||
private UnityEngine.BoxCollider BoxCollider
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!m_BoxCollider)
|
||||
m_BoxCollider = GetComponent<UnityEngine.BoxCollider>();
|
||||
|
||||
return m_BoxCollider;
|
||||
}
|
||||
}
|
||||
|
||||
public bool EnvironmentsShareAuxBus
|
||||
{
|
||||
get
|
||||
{
|
||||
if (environments[0] == null)
|
||||
return environments[1] == null;
|
||||
|
||||
if (environments[1] == null)
|
||||
return false;
|
||||
|
||||
if (environments[0].data == null)
|
||||
return environments[1].data == null;
|
||||
|
||||
if (environments[1].data == null)
|
||||
return false;
|
||||
|
||||
return environments[0].data.Id == environments[1].data.Id;
|
||||
}
|
||||
}
|
||||
|
||||
public float GetAuxSendValueForPosition(UnityEngine.Vector3 in_position, int index)
|
||||
{
|
||||
//total length of the portal in the direction of axis
|
||||
var portalLength = UnityEngine.Vector3.Dot(UnityEngine.Vector3.Scale(BoxCollider.size, transform.lossyScale), axis);
|
||||
|
||||
//transform axis to world coordinates
|
||||
var axisWorld = UnityEngine.Vector3.Normalize(transform.rotation * axis);
|
||||
|
||||
//Get distance form left side of the portal(opposite to the direction of axis) to the game object in the direction of axisWorld
|
||||
var dist = UnityEngine.Vector3.Dot(in_position - (transform.position - portalLength * 0.5f * axisWorld), axisWorld);
|
||||
dist = UnityEngine.Mathf.Clamp(dist, 0, portalLength);
|
||||
|
||||
//calculate value of the environment referred by index
|
||||
if (index == 0)
|
||||
return (portalLength - dist) * (portalLength - dist) / (portalLength * portalLength);
|
||||
|
||||
return dist * dist / (portalLength * portalLength);
|
||||
}
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
/// This enables us to detect intersections between portals and environments in the editor
|
||||
[System.Serializable]
|
||||
public class EnvListWrapper
|
||||
{
|
||||
public System.Collections.Generic.List<AkEnvironment> list = new System.Collections.Generic.List<AkEnvironment>();
|
||||
}
|
||||
|
||||
/// Unity can't serialize an array of list so we wrap the list in a serializable class
|
||||
public EnvListWrapper[] envList =
|
||||
{
|
||||
new EnvListWrapper(), //All environments on the negative side of each portal(opposite to the direction of the chosen axis)
|
||||
new EnvListWrapper() //All environments on the positive side of each portal(same direction as the chosen axis)
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f6f4eb19bf6e9624c8c0668af83d0b59
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
218
Assets/Wwise/Deployment/Components/AkEvent.cs
Normal file
218
Assets/Wwise/Deployment/Components/AkEvent.cs
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// <summary>
|
||||
/// Event callback information.
|
||||
/// Event callback functions can receive this structure as a parameter
|
||||
/// </summary>
|
||||
public class AkEventCallbackMsg
|
||||
{
|
||||
///For more information about the event callback, see the classes derived from AkCallbackInfo.
|
||||
public AkCallbackInfo info;
|
||||
|
||||
/// GameObject from whom the callback function was called
|
||||
public UnityEngine.GameObject sender;
|
||||
|
||||
///AkSoundEngine.PostEvent callback flags. See the AkCallbackType enumeration for a list of all callbacks
|
||||
public AkCallbackType type;
|
||||
}
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkEvent")]
|
||||
[UnityEngine.RequireComponent(typeof(AkGameObj))]
|
||||
/// @brief Helper class that knows a Wwise Event and when to trigger it in Unity. As of 2017.2.0, the AkEvent inspector has buttons for play/stop, play multiple, stop multiple, and stop all.
|
||||
/// Play/Stop will play or stop the event such that it can be previewed both in edit mode and play mode. When multiple objects are selected, Play Multiple and Stop Multiple will play or stop the associated AkEvent for each object.
|
||||
/// \sa
|
||||
/// - \ref sect_edit_mode
|
||||
/// - \ref unity_use_AkEvent_AkAmbient
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__events.html" target="_blank">Integration Details - Events</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
public class AkEvent : AkDragDropTriggerHandler
|
||||
#if UNITY_EDITOR
|
||||
, AK.Wwise.IMigratable
|
||||
#endif
|
||||
{
|
||||
/// Replacement action. See AK::SoundEngine::ExecuteEventOnAction()
|
||||
public AkActionOnEventType actionOnEventType = AkActionOnEventType.AkActionOnEventType_Stop;
|
||||
|
||||
/// Fade curve to use with the new Action. See AK::SoundEngine::ExecuteEventOnAction()
|
||||
public AkCurveInterpolation curveInterpolation = AkCurveInterpolation.AkCurveInterpolation_Linear;
|
||||
|
||||
/// Enables additional options to reuse existing events. Use it to transform a Play event into a Stop event without having to define one in the Wwise Project.
|
||||
public bool enableActionOnEvent = false;
|
||||
|
||||
public AK.Wwise.Event data = new AK.Wwise.Event();
|
||||
protected override AK.Wwise.BaseType WwiseType { get { return data; } }
|
||||
|
||||
[System.Serializable]
|
||||
public class CallbackData
|
||||
{
|
||||
public AK.Wwise.CallbackFlags Flags;
|
||||
public string FunctionName;
|
||||
public UnityEngine.GameObject GameObject;
|
||||
|
||||
public void CallFunction(AkEventCallbackMsg eventCallbackMsg)
|
||||
{
|
||||
if (((uint)eventCallbackMsg.type & Flags.value) != 0 && GameObject)
|
||||
GameObject.SendMessage(FunctionName, eventCallbackMsg);
|
||||
}
|
||||
}
|
||||
|
||||
public bool useCallbacks = false;
|
||||
public System.Collections.Generic.List<CallbackData> Callbacks = new System.Collections.Generic.List<CallbackData>();
|
||||
|
||||
public uint playingId = AkSoundEngine.AK_INVALID_PLAYING_ID;
|
||||
|
||||
/// Game object onto which the Event will be posted. By default, when empty, it is posted on the same object on which the component was added.
|
||||
public UnityEngine.GameObject soundEmitterObject;
|
||||
|
||||
/// Duration of the fade. See AK::SoundEngine::ExecuteEventOnAction()
|
||||
public float transitionDuration = 0.0f;
|
||||
|
||||
private AkEventCallbackMsg EventCallbackMsg = null;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating || !UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (useCallbacks)
|
||||
EventCallbackMsg = new AkEventCallbackMsg { sender = gameObject };
|
||||
|
||||
base.Start();
|
||||
}
|
||||
|
||||
private void Callback(object in_cookie, AkCallbackType in_type, AkCallbackInfo in_info)
|
||||
{
|
||||
EventCallbackMsg.type = in_type;
|
||||
EventCallbackMsg.info = in_info;
|
||||
|
||||
for (var i = 0; i < Callbacks.Count; ++i)
|
||||
Callbacks[i].CallFunction(EventCallbackMsg);
|
||||
}
|
||||
|
||||
public override void HandleEvent(UnityEngine.GameObject in_gameObject)
|
||||
{
|
||||
var gameObj = useOtherObject && in_gameObject != null ? in_gameObject : gameObject;
|
||||
soundEmitterObject = gameObj;
|
||||
|
||||
if (enableActionOnEvent)
|
||||
{
|
||||
data.ExecuteAction(gameObj, actionOnEventType, (int)transitionDuration * 1000, curveInterpolation);
|
||||
return;
|
||||
}
|
||||
|
||||
if (useCallbacks)
|
||||
{
|
||||
uint flags = 0;
|
||||
for (var i = 0; i < Callbacks.Count; ++i)
|
||||
{
|
||||
if (Callbacks[i].GameObject && !string.IsNullOrEmpty(Callbacks[i].FunctionName))
|
||||
flags |= Callbacks[i].Flags.value;
|
||||
}
|
||||
|
||||
if (flags != 0)
|
||||
{
|
||||
playingId = data.Post(gameObj, flags, Callback);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
playingId = data.Post(gameObj);
|
||||
}
|
||||
|
||||
public void Stop(int _transitionDuration)
|
||||
{
|
||||
Stop(_transitionDuration, AkCurveInterpolation.AkCurveInterpolation_Linear);
|
||||
}
|
||||
|
||||
public void Stop(int _transitionDuration, AkCurveInterpolation _curveInterpolation)
|
||||
{
|
||||
data.Stop(soundEmitterObject, _transitionDuration, _curveInterpolation);
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_2)]
|
||||
public int eventID { get { return (int)(data == null ? AkSoundEngine.AK_INVALID_UNIQUE_ID : data.Id); } }
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public byte[] valueGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var objRef = data.ObjectReference;
|
||||
return !objRef ? null : objRef.Guid.ToByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public AkEventCallbackData m_callbackData { get { return m_callbackDataInternal; } }
|
||||
#endregion
|
||||
|
||||
#region WwiseMigration
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("eventID")]
|
||||
private int eventIdInternal = (int)AkSoundEngine.AK_INVALID_UNIQUE_ID;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("valueGuid")]
|
||||
private byte[] valueGuidInternal;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("m_callbackData")]
|
||||
private AkEventCallbackData m_callbackDataInternal = null;
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public virtual bool Migrate(UnityEditor.SerializedObject obj)
|
||||
{
|
||||
var hasMigrated = false;
|
||||
if (AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.WwiseTypes_v2018_1_6))
|
||||
{
|
||||
hasMigrated = AK.Wwise.TypeMigration.ProcessSingleGuidType(obj.FindProperty("data.WwiseObjectReference"), WwiseObjectType.Event,
|
||||
obj.FindProperty("valueGuidInternal"), obj.FindProperty("eventIdInternal"));
|
||||
}
|
||||
|
||||
if (!AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.AkEventCallback_v2018_1_6))
|
||||
return hasMigrated;
|
||||
|
||||
var oldCallbackDataProperty = obj.FindProperty("m_callbackDataInternal");
|
||||
var oldCallbackData = oldCallbackDataProperty.objectReferenceValue as AkEventCallbackData;
|
||||
if (!oldCallbackData)
|
||||
return hasMigrated;
|
||||
|
||||
var count = oldCallbackData.callbackFlags.Count;
|
||||
if (count != oldCallbackData.callbackFunc.Count || count != oldCallbackData.callbackGameObj.Count)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning("WwiseUnity: Inconsistent callback data!");
|
||||
return hasMigrated;
|
||||
}
|
||||
|
||||
var newCallbackData = obj.FindProperty("Callbacks");
|
||||
newCallbackData.arraySize = count;
|
||||
obj.FindProperty("useCallbacks").boolValue = true;
|
||||
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
var data = newCallbackData.GetArrayElementAtIndex(i);
|
||||
data.FindPropertyRelative("GameObject").objectReferenceValue = oldCallbackData.callbackGameObj[i];
|
||||
data.FindPropertyRelative("FunctionName").stringValue = oldCallbackData.callbackFunc[i];
|
||||
data.FindPropertyRelative("Flags.value").intValue = oldCallbackData.callbackFlags[i];
|
||||
UnityEngine.Debug.Log("WwiseUnity: Migrated Callback for function \"" + oldCallbackData.callbackFunc[i] + "\" on <" + oldCallbackData.callbackGameObj[i] + "> with flags <" + (AkCallbackType)oldCallbackData.callbackFlags[i] + ">.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkEvent.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkEvent.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: db32bda40fdd612469c878cf01da5105
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Wwise/Deployment/Components/AkEventCallbackData.cs
Normal file
24
Assets/Wwise/Deployment/Components/AkEventCallbackData.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public class AkEventCallbackData : UnityEngine.ScriptableObject
|
||||
{
|
||||
////AkSoundEngine.PostEvent callback flags. See the AkCallbackType enumeration for a list of all callbacks
|
||||
public System.Collections.Generic.List<int> callbackFlags = new System.Collections.Generic.List<int>();
|
||||
|
||||
////Names of the callback functions.
|
||||
public System.Collections.Generic.List<string> callbackFunc = new System.Collections.Generic.List<string>();
|
||||
|
||||
////GameObject that will receive the callback
|
||||
public System.Collections.Generic.List<UnityEngine.GameObject> callbackGameObj =
|
||||
new System.Collections.Generic.List<UnityEngine.GameObject>();
|
||||
|
||||
////The sum of the flags of all game objects. This is the flag that will be passed to AkSoundEngine.PostEvent
|
||||
public int uFlags = 0;
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8022e50aa139bfb4e86bd242328af5d1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
83
Assets/Wwise/Deployment/Components/AkEventPlayable.cs
Normal file
83
Assets/Wwise/Deployment/Components/AkEventPlayable.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
#if !AK_DISABLE_TIMELINE
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2017 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// @brief A playable asset containing a Wwise event that can be placed within a \ref AkEventTrack in a timeline.
|
||||
/// @details Use this class to play Wwise events from a timeline and synchronise them to the animation. Events will be emitted from the GameObject that is bound to the AkEventTrack. Use the overrideTrackEmitterObject option to choose a different GameObject from which to emit the Wwise event.
|
||||
/// \sa
|
||||
/// - \ref AkEventTrack
|
||||
/// - \ref AkEventPlayableBehavior
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public class AkEventPlayable : UnityEngine.Playables.PlayableAsset, UnityEngine.Timeline.ITimelineClipAsset
|
||||
{
|
||||
public AK.Wwise.Event akEvent = new AK.Wwise.Event();
|
||||
|
||||
[UnityEngine.SerializeField]
|
||||
private AkCurveInterpolation blendInCurve = AkCurveInterpolation.AkCurveInterpolation_Linear;
|
||||
[UnityEngine.SerializeField]
|
||||
private AkCurveInterpolation blendOutCurve = AkCurveInterpolation.AkCurveInterpolation_Linear;
|
||||
|
||||
[UnityEngine.SerializeField]
|
||||
private UnityEngine.ExposedReference<UnityEngine.GameObject> emitterObjectRef;
|
||||
|
||||
public float eventDurationMax = -1f;
|
||||
public float eventDurationMin = -1f;
|
||||
|
||||
[System.NonSerialized]
|
||||
public UnityEngine.Timeline.TimelineClip owningClip;
|
||||
|
||||
[UnityEngine.SerializeField]
|
||||
private bool retriggerEvent = false;
|
||||
|
||||
public bool UseWwiseEventDuration = true;
|
||||
|
||||
[UnityEngine.SerializeField]
|
||||
private bool StopEventAtClipEnd = true;
|
||||
|
||||
UnityEngine.Timeline.ClipCaps UnityEngine.Timeline.ITimelineClipAsset.clipCaps
|
||||
{
|
||||
get { return UnityEngine.Timeline.ClipCaps.Looping | UnityEngine.Timeline.ClipCaps.Blending; }
|
||||
}
|
||||
|
||||
public override UnityEngine.Playables.Playable CreatePlayable(UnityEngine.Playables.PlayableGraph graph, UnityEngine.GameObject owner)
|
||||
{
|
||||
var playable = UnityEngine.Playables.ScriptPlayable<AkEventPlayableBehavior>.Create(graph);
|
||||
|
||||
var eventObject = emitterObjectRef.Resolve(graph.GetResolver());
|
||||
if (eventObject == null)
|
||||
eventObject = owner;
|
||||
|
||||
if (eventObject == null || akEvent == null)
|
||||
return playable;
|
||||
|
||||
var b = playable.GetBehaviour();
|
||||
b.akEvent = akEvent;
|
||||
b.blendInCurve = blendInCurve;
|
||||
b.blendOutCurve = blendOutCurve;
|
||||
|
||||
if (owningClip != null)
|
||||
{
|
||||
b.easeInDuration = (float)owningClip.easeInDuration;
|
||||
b.easeOutDuration = (float)owningClip.easeOutDuration;
|
||||
b.blendInDuration = (float)owningClip.blendInDuration;
|
||||
b.blendOutDuration = (float)owningClip.blendOutDuration;
|
||||
}
|
||||
else
|
||||
b.easeInDuration = b.easeOutDuration = b.blendInDuration = b.blendOutDuration = 0;
|
||||
|
||||
b.retriggerEvent = retriggerEvent;
|
||||
b.StopEventAtClipEnd = StopEventAtClipEnd;
|
||||
b.eventObject = eventObject;
|
||||
b.overrideTrackEmitterObject = eventObject != null;
|
||||
b.eventDurationMin = eventDurationMin;
|
||||
b.eventDurationMax = eventDurationMax;
|
||||
return playable;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !AK_DISABLE_TIMELINE
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkEventPlayable.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkEventPlayable.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a9de598acfbc7a54c85091c89428811d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
367
Assets/Wwise/Deployment/Components/AkEventPlayableBehavior.cs
Normal file
367
Assets/Wwise/Deployment/Components/AkEventPlayableBehavior.cs
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
#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 Defines the behavior of a \ref AkEventPlayable within a \ref AkEventTrack.
|
||||
/// \sa
|
||||
/// - \ref AkEventTrack
|
||||
/// - \ref AkEventPlayable
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public class AkEventPlayableBehavior : UnityEngine.Playables.PlayableBehaviour
|
||||
{
|
||||
private float currentDuration = -1f;
|
||||
private float currentDurationProportion = 1f;
|
||||
private bool eventIsPlaying;
|
||||
private bool fadeinTriggered;
|
||||
private bool fadeoutTriggered;
|
||||
private float previousEventStartTime;
|
||||
|
||||
private const uint CallbackFlags = (uint)(AkCallbackType.AK_EndOfEvent | AkCallbackType.AK_Duration);
|
||||
|
||||
private void CallbackHandler(object in_cookie, AkCallbackType in_type, AkCallbackInfo in_info)
|
||||
{
|
||||
if (in_type == AkCallbackType.AK_EndOfEvent)
|
||||
{
|
||||
eventIsPlaying = fadeinTriggered = fadeoutTriggered = false;
|
||||
}
|
||||
else if (in_type == AkCallbackType.AK_Duration)
|
||||
{
|
||||
var estimatedDuration = (in_info as AkDurationCallbackInfo).fEstimatedDuration;
|
||||
currentDuration = estimatedDuration * currentDurationProportion / 1000f;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private static bool CanPostEvents
|
||||
{
|
||||
get { return UnityEditor.SessionState.GetBool("AkEventPlayableBehavior.CanPostEvents", true); }
|
||||
set { UnityEditor.SessionState.SetBool("AkEventPlayableBehavior.CanPostEvents", value); }
|
||||
}
|
||||
|
||||
[UnityEditor.InitializeOnLoadMethod]
|
||||
private static void DetermineCanPostEvents()
|
||||
{
|
||||
UnityEditor.Compilation.CompilationPipeline.assemblyCompilationFinished += (string text, UnityEditor.Compilation.CompilerMessage[] messages) =>
|
||||
{
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
CanPostEvents = false;
|
||||
};
|
||||
|
||||
UnityEditor.EditorApplication.playModeStateChanged += (UnityEditor.PlayModeStateChange playMode) =>
|
||||
{
|
||||
if (playMode == UnityEditor.PlayModeStateChange.ExitingEditMode)
|
||||
CanPostEvents = true;
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
[System.Flags]
|
||||
private enum Actions
|
||||
{
|
||||
None = 0,
|
||||
Playback = 1 << 0,
|
||||
Retrigger = 1 << 1,
|
||||
DelayedStop = 1 << 2,
|
||||
Seek = 1 << 3,
|
||||
FadeIn = 1 << 4,
|
||||
FadeOut = 1 << 5
|
||||
}
|
||||
private Actions requiredActions;
|
||||
|
||||
private const int scrubPlaybackLengthMs = 100;
|
||||
|
||||
public AK.Wwise.Event akEvent;
|
||||
|
||||
public float eventDurationMax;
|
||||
public float eventDurationMin;
|
||||
|
||||
public float blendInDuration;
|
||||
public float blendOutDuration;
|
||||
public float easeInDuration;
|
||||
public float easeOutDuration;
|
||||
|
||||
public AkCurveInterpolation blendInCurve;
|
||||
public AkCurveInterpolation blendOutCurve;
|
||||
|
||||
public UnityEngine.GameObject eventObject;
|
||||
|
||||
public bool retriggerEvent;
|
||||
private bool wasScrubbingAndRequiresRetrigger;
|
||||
public bool StopEventAtClipEnd;
|
||||
|
||||
public bool overrideTrackEmitterObject;
|
||||
|
||||
private bool IsScrubbing(UnityEngine.Playables.FrameData info)
|
||||
{
|
||||
#if !UNITY_2018_2_OR_NEWER
|
||||
// We disable scrubbing in edit mode, due to an issue with how FrameData.EvaluationType is handled in edit mode.
|
||||
// This is a known issue and Unity are aware of it: https://fogbugz.unity3d.com/default.asp?953109_kitf7pso0vmjm0m0
|
||||
if (!UnityEngine.Application.isPlaying)
|
||||
return false;
|
||||
#endif
|
||||
return info.evaluationType == UnityEngine.Playables.FrameData.EvaluationType.Evaluate;
|
||||
}
|
||||
|
||||
public override void PrepareFrame(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
|
||||
{
|
||||
base.PrepareFrame(playable, info);
|
||||
|
||||
if (akEvent == null)
|
||||
return;
|
||||
|
||||
var shouldPlay = ShouldPlay(playable);
|
||||
if (IsScrubbing(info) && shouldPlay)
|
||||
{
|
||||
requiredActions |= Actions.Seek;
|
||||
|
||||
if (!eventIsPlaying)
|
||||
{
|
||||
requiredActions |= Actions.Playback | Actions.DelayedStop;
|
||||
CheckForFadeInFadeOut(playable);
|
||||
}
|
||||
}
|
||||
else if (!eventIsPlaying && (requiredActions & Actions.Playback) == 0)
|
||||
{
|
||||
// The clip is playing but the event hasn't been triggered. We need to start the event and jump to the correct time.
|
||||
requiredActions |= Actions.Retrigger;
|
||||
CheckForFadeInFadeOut(playable);
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckForFadeOut(playable, UnityEngine.Playables.PlayableExtensions.GetTime(playable));
|
||||
}
|
||||
}
|
||||
|
||||
private const float alph = 0.05f;
|
||||
|
||||
public override void OnBehaviourPlay(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
|
||||
{
|
||||
base.OnBehaviourPlay(playable, info);
|
||||
|
||||
if (akEvent == null)
|
||||
return;
|
||||
|
||||
var shouldPlay = ShouldPlay(playable);
|
||||
if (!shouldPlay)
|
||||
return;
|
||||
|
||||
requiredActions |= Actions.Playback;
|
||||
|
||||
if (IsScrubbing(info))
|
||||
{
|
||||
wasScrubbingAndRequiresRetrigger = true;
|
||||
// If we've explicitly set the playhead, only play a small snippet.
|
||||
requiredActions |= Actions.DelayedStop;
|
||||
}
|
||||
else if (GetProportionalTime(playable) > alph)
|
||||
{
|
||||
// we need to jump to the correct position in the case where the event is played from some non-start position.
|
||||
requiredActions |= Actions.Seek;
|
||||
}
|
||||
|
||||
CheckForFadeInFadeOut(playable);
|
||||
}
|
||||
|
||||
public override void OnBehaviourPause(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info)
|
||||
{
|
||||
wasScrubbingAndRequiresRetrigger = false;
|
||||
|
||||
base.OnBehaviourPause(playable, info);
|
||||
if (eventObject != null && akEvent != null && StopEventAtClipEnd)
|
||||
{
|
||||
StopEvent();
|
||||
}
|
||||
}
|
||||
|
||||
public override void ProcessFrame(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info, object playerData)
|
||||
{
|
||||
base.ProcessFrame(playable, info, playerData);
|
||||
|
||||
if (akEvent == null)
|
||||
return;
|
||||
|
||||
if (!overrideTrackEmitterObject)
|
||||
{
|
||||
var obj = playerData as UnityEngine.GameObject;
|
||||
if (obj != null)
|
||||
eventObject = obj;
|
||||
}
|
||||
|
||||
if (eventObject == null)
|
||||
return;
|
||||
|
||||
if ((requiredActions & Actions.Playback) != 0)
|
||||
PlayEvent();
|
||||
|
||||
if ((requiredActions & Actions.Seek) != 0)
|
||||
SeekToTime(playable);
|
||||
|
||||
if ((retriggerEvent || wasScrubbingAndRequiresRetrigger) && (requiredActions & Actions.Retrigger) != 0)
|
||||
RetriggerEvent(playable);
|
||||
|
||||
if ((requiredActions & Actions.DelayedStop) != 0)
|
||||
StopEvent(scrubPlaybackLengthMs);
|
||||
|
||||
if (!fadeinTriggered && (requiredActions & Actions.FadeIn) != 0)
|
||||
TriggerFadeIn(playable);
|
||||
|
||||
if (!fadeoutTriggered && (requiredActions & Actions.FadeOut) != 0)
|
||||
TriggerFadeOut(playable);
|
||||
|
||||
requiredActions = Actions.None;
|
||||
}
|
||||
|
||||
/** Check the playable time against the Wwise event duration to see if playback should occur.
|
||||
*/
|
||||
private bool ShouldPlay(UnityEngine.Playables.Playable playable)
|
||||
{
|
||||
var previousTime = UnityEngine.Playables.PlayableExtensions.GetPreviousTime(playable);
|
||||
var currentTime = UnityEngine.Playables.PlayableExtensions.GetTime(playable);
|
||||
if (previousTime == 0.0 && System.Math.Abs(currentTime - previousTime) > 1.0)
|
||||
return false;
|
||||
|
||||
if (retriggerEvent)
|
||||
return true;
|
||||
|
||||
// If max and min duration values from metadata are equal, we can assume a deterministic event.
|
||||
if (eventDurationMax == eventDurationMin && eventDurationMin != -1f)
|
||||
return currentTime < eventDurationMax;
|
||||
|
||||
currentTime -= previousEventStartTime;
|
||||
|
||||
var maxDuration = currentDuration == -1f ? (float)UnityEngine.Playables.PlayableExtensions.GetDuration(playable) : currentDuration;
|
||||
return currentTime < maxDuration;
|
||||
}
|
||||
|
||||
private void CheckForFadeInFadeOut(UnityEngine.Playables.Playable playable)
|
||||
{
|
||||
var currentClipTime = UnityEngine.Playables.PlayableExtensions.GetTime(playable);
|
||||
if (blendInDuration > currentClipTime || easeInDuration > currentClipTime)
|
||||
requiredActions |= Actions.FadeIn;
|
||||
|
||||
CheckForFadeOut(playable, currentClipTime);
|
||||
}
|
||||
|
||||
private void CheckForFadeOut(UnityEngine.Playables.Playable playable, double currentClipTime)
|
||||
{
|
||||
var timeLeft = UnityEngine.Playables.PlayableExtensions.GetDuration(playable) - currentClipTime;
|
||||
if (blendOutDuration >= timeLeft || easeOutDuration >= timeLeft)
|
||||
requiredActions |= Actions.FadeOut;
|
||||
}
|
||||
|
||||
private void TriggerFadeIn(UnityEngine.Playables.Playable playable)
|
||||
{
|
||||
var currentClipTime = UnityEngine.Playables.PlayableExtensions.GetTime(playable);
|
||||
var fadeDuration = UnityEngine.Mathf.Max(easeInDuration, blendInDuration) - currentClipTime;
|
||||
if (fadeDuration > 0)
|
||||
{
|
||||
fadeinTriggered = true;
|
||||
akEvent.ExecuteAction(eventObject, AkActionOnEventType.AkActionOnEventType_Pause, 0, blendOutCurve);
|
||||
akEvent.ExecuteAction(eventObject, AkActionOnEventType.AkActionOnEventType_Resume, (int)(fadeDuration * 1000), blendInCurve);
|
||||
}
|
||||
}
|
||||
|
||||
private void TriggerFadeOut(UnityEngine.Playables.Playable playable)
|
||||
{
|
||||
fadeoutTriggered = true;
|
||||
|
||||
var fadeDuration = UnityEngine.Playables.PlayableExtensions.GetDuration(playable) - UnityEngine.Playables.PlayableExtensions.GetTime(playable);
|
||||
akEvent.ExecuteAction(eventObject, AkActionOnEventType.AkActionOnEventType_Stop, (int)(fadeDuration * 1000), blendOutCurve);
|
||||
}
|
||||
|
||||
private void StopEvent(int transition = 0)
|
||||
{
|
||||
if (!eventIsPlaying)
|
||||
return;
|
||||
|
||||
akEvent.Stop(eventObject, transition);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
eventIsPlaying = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
private bool PostEvent()
|
||||
{
|
||||
fadeinTriggered = fadeoutTriggered = false;
|
||||
|
||||
uint playingID;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!CanPostEvents)
|
||||
{
|
||||
playingID = AkSoundEngine.AK_INVALID_PLAYING_ID;
|
||||
}
|
||||
else if (!UnityEditor.EditorApplication.isPlaying)
|
||||
{
|
||||
playingID = akEvent.Post(eventObject);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
playingID = akEvent.Post(eventObject, CallbackFlags, CallbackHandler, null);
|
||||
}
|
||||
|
||||
eventIsPlaying = playingID != AkSoundEngine.AK_INVALID_PLAYING_ID;
|
||||
return eventIsPlaying;
|
||||
}
|
||||
|
||||
private void PlayEvent()
|
||||
{
|
||||
if (!PostEvent())
|
||||
return;
|
||||
|
||||
currentDurationProportion = 1f;
|
||||
previousEventStartTime = 0f;
|
||||
}
|
||||
|
||||
private void RetriggerEvent(UnityEngine.Playables.Playable playable)
|
||||
{
|
||||
wasScrubbingAndRequiresRetrigger = false;
|
||||
|
||||
if (!PostEvent())
|
||||
return;
|
||||
|
||||
currentDurationProportion = 1f - SeekToTime(playable);
|
||||
previousEventStartTime = (float)UnityEngine.Playables.PlayableExtensions.GetTime(playable);
|
||||
}
|
||||
|
||||
private float GetProportionalTime(UnityEngine.Playables.Playable playable)
|
||||
{
|
||||
// If max and min duration values from metadata are equal, we can assume a deterministic event.
|
||||
if (eventDurationMax == eventDurationMin && eventDurationMin != -1f)
|
||||
{
|
||||
// If the timeline clip has length greater than the event duration, we want to loop.
|
||||
return (float)UnityEngine.Playables.PlayableExtensions.GetTime(playable) % eventDurationMax / eventDurationMax;
|
||||
}
|
||||
|
||||
var currentTime = (float)UnityEngine.Playables.PlayableExtensions.GetTime(playable) - previousEventStartTime;
|
||||
var maxDuration = currentDuration == -1f ? (float)UnityEngine.Playables.PlayableExtensions.GetDuration(playable) : currentDuration;
|
||||
// If the timeline clip has length greater than the event duration, we want to loop.
|
||||
return currentTime % maxDuration / maxDuration;
|
||||
}
|
||||
|
||||
// Seek to the current time, taking looping into account.
|
||||
private float SeekToTime(UnityEngine.Playables.Playable playable)
|
||||
{
|
||||
var proportionalTime = GetProportionalTime(playable);
|
||||
if (proportionalTime >= 1f) // Avoids Wwise "seeking beyond end of event: audio will stop" error.
|
||||
return 1f;
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!CanPostEvents)
|
||||
return proportionalTime;
|
||||
#endif
|
||||
|
||||
if (eventIsPlaying)
|
||||
AkSoundEngine.SeekOnEvent(akEvent.Id, eventObject, proportionalTime);
|
||||
|
||||
return proportionalTime;
|
||||
}
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 113bb9ce9e3ffd5439e59243cad7e522
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
37
Assets/Wwise/Deployment/Components/AkEventTrack.cs
Normal file
37
Assets/Wwise/Deployment/Components/AkEventTrack.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
#if !AK_DISABLE_TIMELINE
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2017 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.Timeline.TrackColor(0.855f, 0.8623f, 0.870f)]
|
||||
[UnityEngine.Timeline.TrackClipType(typeof(AkEventPlayable))]
|
||||
[UnityEngine.Timeline.TrackBindingType(typeof(UnityEngine.GameObject))]
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
/// @brief A track within timeline that holds \ref AkEventPlayable clips.
|
||||
/// @details AkEventTracks are bound to a specific GameObject, which is the default emitter for all of the \ref AkEventPlayable clips. There is an option to override this in /ref AkEventPlayable.
|
||||
/// \sa
|
||||
/// - \ref AkEventPlayable
|
||||
/// - \ref AkEventPlayableBehavior
|
||||
public class AkEventTrack : UnityEngine.Timeline.TrackAsset
|
||||
{
|
||||
public override UnityEngine.Playables.Playable CreateTrackMixer(UnityEngine.Playables.PlayableGraph graph, UnityEngine.GameObject go, int inputCount)
|
||||
{
|
||||
var playable = UnityEngine.Playables.ScriptPlayable<AkEventPlayableBehavior>.Create(graph);
|
||||
UnityEngine.Playables.PlayableExtensions.SetInputCount(playable, inputCount);
|
||||
|
||||
var clips = GetClips();
|
||||
foreach (var clip in clips)
|
||||
{
|
||||
var akEventPlayable = clip.asset as AkEventPlayable;
|
||||
akEventPlayable.owningClip = clip;
|
||||
}
|
||||
|
||||
return playable;
|
||||
}
|
||||
}
|
||||
#endif // !AK_DISABLE_TIMELINE
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkEventTrack.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkEventTrack.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ba455072133a0544aad15c27f57514ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
410
Assets/Wwise/Deployment/Components/AkGameObj.cs
Normal file
410
Assets/Wwise/Deployment/Components/AkGameObj.cs
Normal file
|
|
@ -0,0 +1,410 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkGameObj")]
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
[UnityEngine.ExecuteInEditMode] //ExecuteInEditMode necessary to maintain proper state of isStaticObject.
|
||||
[UnityEngine.DefaultExecutionOrder(-25)]
|
||||
///@brief This component represents a sound object in your scene tracking its position and other game syncs such as Switches, RTPC and environment values. You can add this to any object that will emit sound, and it will be added to any object that an AkAudioListener is attached to. Note that if it is not present, Wwise will add it automatically, with the default values, to any Unity Game Object that is passed to Wwise.
|
||||
/// \sa
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__gameobj.html" target="_blank">Integration Details - Game Objects</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__events.html" target="_blank">Integration Details - Events</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__listeners.html" target="_blank">Integrating Listeners</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__switch.html" target="_blank">Integration Details - Switches</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__states.html" target="_blank">Integration Details - States</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__environments.html" target="_blank">Integration Details - Environments and Game-defined Auxiliary Sends</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
public class AkGameObj : UnityEngine.MonoBehaviour
|
||||
{
|
||||
[UnityEngine.SerializeField] private AkGameObjListenerList m_listeners = new AkGameObjListenerList();
|
||||
|
||||
/// Is this object affected by Environment changes? Set to false if not affected in order to save some useless calls. Default is true.
|
||||
public bool isEnvironmentAware = true;
|
||||
|
||||
/// Maintains and persists the Static setting of the gameobject, which is available only in the editor.
|
||||
[UnityEngine.SerializeField] private bool isStaticObject = false;
|
||||
|
||||
/// Cache the bounds to avoid calls to GetComponent()
|
||||
private UnityEngine.Collider m_Collider;
|
||||
|
||||
private AkGameObjEnvironmentData m_envData;
|
||||
|
||||
private AkGameObjPositionData m_posData;
|
||||
|
||||
/// When not set to null, the position will be offset relative to the Game Object position by the Position Offset
|
||||
public AkGameObjPositionOffsetData m_positionOffsetData;
|
||||
|
||||
public bool IsUsingDefaultListeners
|
||||
{
|
||||
get { return m_listeners.useDefaultListeners; }
|
||||
}
|
||||
|
||||
public System.Collections.Generic.List<AkAudioListener> ListenerList
|
||||
{
|
||||
get { return m_listeners.ListenerList; }
|
||||
}
|
||||
|
||||
private bool isRegistered = false;
|
||||
|
||||
internal void AddListener(AkAudioListener listener)
|
||||
{
|
||||
m_listeners.Add(listener);
|
||||
}
|
||||
|
||||
internal void RemoveListener(AkAudioListener listener)
|
||||
{
|
||||
m_listeners.Remove(listener);
|
||||
}
|
||||
|
||||
public AKRESULT Register()
|
||||
{
|
||||
if (isRegistered)
|
||||
return AKRESULT.AK_Success;
|
||||
|
||||
isRegistered = true;
|
||||
return AkSoundEngine.RegisterGameObj(gameObject, gameObject.name);
|
||||
}
|
||||
|
||||
private void SetPosition()
|
||||
{
|
||||
var position = GetPosition();
|
||||
var forward = GetForward();
|
||||
var up = GetUpward();
|
||||
|
||||
if (m_posData != null)
|
||||
{
|
||||
if (m_posData.position == position && m_posData.forward == forward && m_posData.up == up)
|
||||
return;
|
||||
|
||||
m_posData.position = position;
|
||||
m_posData.forward = forward;
|
||||
m_posData.up = up;
|
||||
}
|
||||
|
||||
AkSoundEngine.SetObjectPosition(gameObject, position, forward, up);
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!AkSoundEngineController.Instance.IsSoundEngineLoaded || AkUtilities.IsMigrating)
|
||||
return;
|
||||
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
UnityEditor.EditorApplication.update += CheckStaticStatus;
|
||||
#endif
|
||||
|
||||
// If the object was marked as static, don't update its position to save cycles.
|
||||
if (!isStaticObject)
|
||||
m_posData = new AkGameObjPositionData();
|
||||
|
||||
// Cache the bounds to avoid calls to GetComponent()
|
||||
m_Collider = GetComponent<UnityEngine.Collider>();
|
||||
|
||||
//Register a Game Object in the sound engine, with its name.
|
||||
if (Register() == AKRESULT.AK_Success)
|
||||
{
|
||||
SetPosition();
|
||||
|
||||
if (isEnvironmentAware)
|
||||
{
|
||||
m_envData = new AkGameObjEnvironmentData();
|
||||
|
||||
if (m_Collider)
|
||||
m_envData.AddAkEnvironment(m_Collider, m_Collider);
|
||||
|
||||
m_envData.UpdateAuxSend(gameObject, transform.position);
|
||||
}
|
||||
|
||||
m_listeners.Init(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckStaticStatus()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (AkUtilities.IsMigrating)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (gameObject != null && isStaticObject != gameObject.isStatic)
|
||||
{
|
||||
isStaticObject = gameObject.isStatic;
|
||||
UnityEditor.EditorUtility.SetDirty(this);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
UnityEditor.EditorApplication.update -= CheckStaticStatus;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (AkUtilities.IsMigrating)
|
||||
return;
|
||||
#endif
|
||||
|
||||
//if enabled is set to false, then the update function wont be called
|
||||
enabled = !isStaticObject;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDisable()
|
||||
{
|
||||
if (!UnityEditor.EditorApplication.isPlaying &&AkSoundEngine.IsInitialized())
|
||||
AkSoundEngine.UnregisterGameObj(gameObject);
|
||||
}
|
||||
#endif
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!AkSoundEngineController.Instance.IsSoundEngineLoaded || AkUtilities.IsMigrating)
|
||||
return;
|
||||
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
UnityEditor.EditorApplication.update -= CheckStaticStatus;
|
||||
#endif
|
||||
|
||||
// We can't do the code in OnDestroy if the gameObj is unregistered, so do it now.
|
||||
var eventHandlers = gameObject.GetComponents<AkTriggerHandler>();
|
||||
foreach (var handler in eventHandlers)
|
||||
{
|
||||
if (handler.triggerList.Contains(AkTriggerHandler.DESTROY_TRIGGER_ID))
|
||||
handler.DoDestroy();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (AkSoundEngine.IsInitialized())
|
||||
AkSoundEngine.UnregisterGameObj(gameObject);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!AkSoundEngineController.Instance.IsSoundEngineLoaded || AkUtilities.IsMigrating ||
|
||||
!UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (m_envData != null)
|
||||
m_envData.UpdateAuxSend(gameObject, transform.position);
|
||||
|
||||
if (!isStaticObject)
|
||||
SetPosition();
|
||||
}
|
||||
|
||||
/// Gets the position including the position offset, if applyPositionOffset is enabled. User can also override this method to calculate an arbitrary position.
|
||||
/// \return The position.
|
||||
public virtual UnityEngine.Vector3 GetPosition()
|
||||
{
|
||||
if (m_positionOffsetData == null)
|
||||
return transform.position;
|
||||
|
||||
var worldOffset = transform.rotation * m_positionOffsetData.positionOffset;
|
||||
return transform.position + worldOffset;
|
||||
}
|
||||
|
||||
/// Gets the orientation forward vector. User can also override this method to calculate an arbitrary vector.
|
||||
/// \return The forward vector of orientation.
|
||||
public virtual UnityEngine.Vector3 GetForward()
|
||||
{
|
||||
return transform.forward;
|
||||
}
|
||||
|
||||
/// Gets the orientation upward vector. User can also override this method to calculate an arbitrary vector.
|
||||
/// \return The upward vector of orientation.
|
||||
public virtual UnityEngine.Vector3 GetUpward()
|
||||
{
|
||||
return transform.up;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(UnityEngine.Collider other)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (AkUtilities.IsMigrating || !UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (isEnvironmentAware && m_envData != null)
|
||||
m_envData.AddAkEnvironment(other, m_Collider);
|
||||
}
|
||||
|
||||
private void OnTriggerExit(UnityEngine.Collider other)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (AkUtilities.IsMigrating || !UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (isEnvironmentAware && m_envData != null)
|
||||
m_envData.RemoveAkEnvironment(other, m_Collider);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void OnDrawGizmosSelected()
|
||||
{
|
||||
if (AkUtilities.IsMigrating)
|
||||
return;
|
||||
|
||||
var position = GetPosition();
|
||||
UnityEngine.Gizmos.DrawIcon(position, "WwiseAudioSpeaker.png", false);
|
||||
}
|
||||
#endif
|
||||
|
||||
#region WwiseMigration
|
||||
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
private AkGameObjPosOffsetData m_posOffsetData;
|
||||
|
||||
// Wwise v2016.2 and below supported up to 8 listeners[0-7].
|
||||
private const int AK_NUM_LISTENERS = 8;
|
||||
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
/// Listener 0 by default.
|
||||
private int listenerMask = 1;
|
||||
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void Migrate9()
|
||||
{
|
||||
UnityEngine.Debug.Log("WwiseUnity: AkGameObj.Migrate9 for " + gameObject.name);
|
||||
|
||||
const int ALL_LISTENER_MASK = (1 << AK_NUM_LISTENERS) - 1;
|
||||
if ((listenerMask & ALL_LISTENER_MASK) == ALL_LISTENER_MASK)
|
||||
listenerMask = 1;
|
||||
}
|
||||
|
||||
public void Migrate10()
|
||||
{
|
||||
UnityEngine.Debug.Log("WwiseUnity: AkGameObj.Migrate10 for " + gameObject.name);
|
||||
|
||||
if (m_posOffsetData != null)
|
||||
{
|
||||
m_positionOffsetData = new AkGameObjPositionOffsetData(true);
|
||||
m_positionOffsetData.positionOffset = m_posOffsetData.positionOffset;
|
||||
m_posOffsetData = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class Migration14Data
|
||||
{
|
||||
private readonly System.Collections.Generic.List<AkAudioListener>[] listeners =
|
||||
new System.Collections.Generic.List<AkAudioListener>[AK_NUM_LISTENERS];
|
||||
|
||||
public Migration14Data()
|
||||
{
|
||||
var fullSceneListenerMask = 0;
|
||||
|
||||
// Get all AkAudioListeners in the scene.
|
||||
var listenerObjects = FindObjectsOfType<AkAudioListener>();
|
||||
foreach (var listener in listenerObjects)
|
||||
{
|
||||
// Add AkGameObj to AkAudioListeners
|
||||
if (listener.GetComponent<AkGameObj>() == null)
|
||||
{
|
||||
var akGameObj = listener.gameObject.AddComponent<AkGameObj>();
|
||||
if (akGameObj)
|
||||
{
|
||||
akGameObj.isEnvironmentAware = false;
|
||||
UnityEngine.Debug.Log("WwiseUnity: Added AkGameObj to <" + listener.gameObject.name + ">.");
|
||||
}
|
||||
else
|
||||
UnityEngine.Debug.LogError("WwiseUnity: Failed to add AkGameObj to <" + listener.gameObject.name + ">.");
|
||||
}
|
||||
|
||||
var listenerId = listener.listenerId;
|
||||
if (listenerId >= 0 && listenerId < AK_NUM_LISTENERS)
|
||||
{
|
||||
if (listeners[listenerId] == null)
|
||||
listeners[listenerId] = new System.Collections.Generic.List<AkAudioListener>();
|
||||
|
||||
listeners[listenerId].Add(listener);
|
||||
fullSceneListenerMask |= 1 << listenerId;
|
||||
}
|
||||
else
|
||||
UnityEngine.Debug.LogError("WwiseUnity: Invalid listenerId <" + listenerId + "> found during migration.");
|
||||
}
|
||||
|
||||
if (fullSceneListenerMask == 0)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning("WwiseUnity: Listeners were not added via components within this Scene.");
|
||||
listeners = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var ii = 0; ii < AK_NUM_LISTENERS; ++ii)
|
||||
{
|
||||
if (listeners[ii] != null && listeners[ii].Count > 1)
|
||||
{
|
||||
UnityEngine.Debug.LogWarning("WwiseUnity: Multiple listeners <" + listeners[ii].Count +
|
||||
"> with same listenerId <" + ii + "> found during migration.");
|
||||
}
|
||||
}
|
||||
|
||||
if (fullSceneListenerMask == 1)
|
||||
{
|
||||
UnityEngine.Debug.Log("WwiseUnity: Default listeners will be used for this Scene.");
|
||||
listeners = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Migrate(AkGameObj akGameObj)
|
||||
{
|
||||
if (listeners != null)
|
||||
{
|
||||
for (var ii = 0; ii < AK_NUM_LISTENERS; ++ii)
|
||||
{
|
||||
var idMask = 1 << ii;
|
||||
if ((akGameObj.listenerMask & idMask) != 0 && listeners[ii] != null)
|
||||
{
|
||||
foreach (var listener in listeners[ii])
|
||||
akGameObj.m_listeners.AddToInitialListenerList(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Migration14Data migration14data;
|
||||
|
||||
public static void PreMigration14()
|
||||
{
|
||||
migration14data = new Migration14Data();
|
||||
}
|
||||
|
||||
public void Migrate14()
|
||||
{
|
||||
UnityEngine.Debug.Log("WwiseUnity: AkGameObj.Migrate14 for " + gameObject.name);
|
||||
|
||||
if (migration14data != null)
|
||||
migration14data.Migrate(this);
|
||||
}
|
||||
|
||||
public static void PostMigration14()
|
||||
{
|
||||
migration14data = null;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkGameObj.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkGameObj.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f27db6b94e477054e96392f94dc50c9d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
192
Assets/Wwise/Deployment/Components/AkGameObjEnvironmentData.cs
Normal file
192
Assets/Wwise/Deployment/Components/AkGameObjEnvironmentData.cs
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public class AkGameObjEnvironmentData
|
||||
{
|
||||
/// Contains all active environments sorted by default, excludeOthers and priority, even those inside a portal.
|
||||
private readonly System.Collections.Generic.List<AkEnvironment> activeEnvironments =
|
||||
new System.Collections.Generic.List<AkEnvironment>();
|
||||
|
||||
/// Contains all active environments sorted by priority, even those inside a portal.
|
||||
private readonly System.Collections.Generic.List<AkEnvironment> activeEnvironmentsFromPortals =
|
||||
new System.Collections.Generic.List<AkEnvironment>();
|
||||
|
||||
/// Contains all active portals.
|
||||
private readonly System.Collections.Generic.List<AkEnvironmentPortal> activePortals =
|
||||
new System.Collections.Generic.List<AkEnvironmentPortal>();
|
||||
|
||||
private readonly AkAuxSendArray auxSendValues = new AkAuxSendArray();
|
||||
private UnityEngine.Vector3 lastPosition = UnityEngine.Vector3.zero;
|
||||
private bool hasEnvironmentListChanged = true;
|
||||
private bool hasActivePortalListChanged = true;
|
||||
private bool hasSentZero = false;
|
||||
|
||||
private void AddHighestPriorityEnvironmentsFromPortals(UnityEngine.Vector3 position)
|
||||
{
|
||||
for (var i = 0; i < activePortals.Count; i++)
|
||||
{
|
||||
var portal = activePortals[i];
|
||||
if (portal.EnvironmentsShareAuxBus)
|
||||
{
|
||||
var env = portal.environments[0];
|
||||
if (env == null)
|
||||
continue;
|
||||
|
||||
var index = activeEnvironmentsFromPortals.BinarySearch(env, AkEnvironment.s_compareByPriority);
|
||||
if (index < 0 || index >= AkEnvironment.MAX_NB_ENVIRONMENTS)
|
||||
continue;
|
||||
|
||||
var auxBusID = env.data.Id;
|
||||
if (!auxSendValues.Contains(auxBusID))
|
||||
{
|
||||
auxSendValues.Add(auxBusID, 1.0f);
|
||||
if (auxSendValues.isFull)
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var j = 0; j < AkEnvironmentPortal.MAX_ENVIRONMENTS_PER_PORTAL; j++)
|
||||
{
|
||||
var env = portal.environments[j];
|
||||
if (env == null)
|
||||
continue;
|
||||
|
||||
var index = activeEnvironmentsFromPortals.BinarySearch(env, AkEnvironment.s_compareByPriority);
|
||||
if (index < 0 || index >= AkEnvironment.MAX_NB_ENVIRONMENTS)
|
||||
continue;
|
||||
|
||||
var auxBusID = env.data.Id;
|
||||
if (!auxSendValues.Contains(auxBusID))
|
||||
{
|
||||
auxSendValues.Add(auxBusID, portal.GetAuxSendValueForPosition(position, j));
|
||||
if (auxSendValues.isFull)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void AddHighestPriorityEnvironments(UnityEngine.Vector3 position)
|
||||
{
|
||||
if (!auxSendValues.isFull && auxSendValues.Count() < activeEnvironments.Count)
|
||||
{
|
||||
for (var i = 0; i < activeEnvironments.Count; i++)
|
||||
{
|
||||
var env = activeEnvironments[i];
|
||||
var auxBusID = env.data.Id;
|
||||
|
||||
if ((!env.isDefault || i == 0) && !auxSendValues.Contains(auxBusID))
|
||||
{
|
||||
auxSendValues.Add(auxBusID, 1.0f);
|
||||
|
||||
//No other environment can be added after an environment with the excludeOthers flag set to true
|
||||
if (env.excludeOthers || auxSendValues.isFull)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateAuxSend(UnityEngine.GameObject gameObject, UnityEngine.Vector3 position)
|
||||
{
|
||||
if (!hasEnvironmentListChanged && !hasActivePortalListChanged && lastPosition == position)
|
||||
return;
|
||||
|
||||
auxSendValues.Reset();
|
||||
AddHighestPriorityEnvironmentsFromPortals(position);
|
||||
AddHighestPriorityEnvironments(position);
|
||||
|
||||
bool isSendingZero = auxSendValues.Count() == 0;
|
||||
if (!hasSentZero || !isSendingZero)
|
||||
auxSendValues.SetValues(gameObject);
|
||||
|
||||
hasSentZero = isSendingZero;
|
||||
lastPosition = position;
|
||||
hasActivePortalListChanged = false;
|
||||
hasEnvironmentListChanged = false;
|
||||
}
|
||||
|
||||
private void TryAddEnvironment(AkEnvironment env)
|
||||
{
|
||||
if (env == null)
|
||||
return;
|
||||
|
||||
var index = activeEnvironmentsFromPortals.BinarySearch(env, AkEnvironment.s_compareByPriority);
|
||||
if (index >= 0)
|
||||
return;
|
||||
|
||||
activeEnvironmentsFromPortals.Insert(~index, env);
|
||||
|
||||
index = activeEnvironments.BinarySearch(env, AkEnvironment.s_compareBySelectionAlgorithm);
|
||||
if (index < 0)
|
||||
activeEnvironments.Insert(~index, env);
|
||||
|
||||
hasEnvironmentListChanged = true;
|
||||
}
|
||||
|
||||
private void RemoveEnvironment(AkEnvironment env)
|
||||
{
|
||||
activeEnvironmentsFromPortals.Remove(env);
|
||||
activeEnvironments.Remove(env);
|
||||
hasEnvironmentListChanged = true;
|
||||
}
|
||||
|
||||
public void AddAkEnvironment(UnityEngine.Collider environmentCollider, UnityEngine.Collider gameObjectCollider)
|
||||
{
|
||||
var portal = environmentCollider.GetComponent<AkEnvironmentPortal>();
|
||||
if (portal == null)
|
||||
{
|
||||
var env = environmentCollider.GetComponent<AkEnvironment>();
|
||||
TryAddEnvironment(env);
|
||||
return;
|
||||
}
|
||||
|
||||
activePortals.Add(portal);
|
||||
hasActivePortalListChanged = true;
|
||||
|
||||
for (var i = 0; i < AkEnvironmentPortal.MAX_ENVIRONMENTS_PER_PORTAL; i++)
|
||||
TryAddEnvironment(portal.environments[i]);
|
||||
}
|
||||
|
||||
private bool AkEnvironmentBelongsToActivePortals(AkEnvironment env)
|
||||
{
|
||||
for (var i = 0; i < activePortals.Count; i++)
|
||||
for (var j = 0; j < AkEnvironmentPortal.MAX_ENVIRONMENTS_PER_PORTAL; j++)
|
||||
{
|
||||
if (env == activePortals[i].environments[j])
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveAkEnvironment(UnityEngine.Collider environmentCollider, UnityEngine.Collider gameObjectCollider)
|
||||
{
|
||||
var portal = environmentCollider.GetComponent<AkEnvironmentPortal>();
|
||||
if (portal != null)
|
||||
{
|
||||
for (var i = 0; i < AkEnvironmentPortal.MAX_ENVIRONMENTS_PER_PORTAL; i++)
|
||||
{
|
||||
var env = portal.environments[i];
|
||||
if (env != null && !gameObjectCollider.bounds.Intersects(env.Collider.bounds))
|
||||
RemoveEnvironment(env);
|
||||
}
|
||||
|
||||
activePortals.Remove(portal);
|
||||
hasActivePortalListChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var env = environmentCollider.GetComponent<AkEnvironment>();
|
||||
if (env != null && !AkEnvironmentBelongsToActivePortals(env))
|
||||
RemoveEnvironment(env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: adcfa58950ada274581dcaadc423c852
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
80
Assets/Wwise/Deployment/Components/AkGameObjListenerList.cs
Normal file
80
Assets/Wwise/Deployment/Components/AkGameObjListenerList.cs
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#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
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[System.Serializable]
|
||||
public class AkGameObjListenerList : AkAudioListener.BaseListenerList
|
||||
{
|
||||
[System.NonSerialized] private AkGameObj akGameObj;
|
||||
|
||||
[UnityEngine.SerializeField]
|
||||
public System.Collections.Generic.List<AkAudioListener> initialListenerList =
|
||||
new System.Collections.Generic.List<AkAudioListener>();
|
||||
|
||||
[UnityEngine.SerializeField] public bool useDefaultListeners = true;
|
||||
|
||||
public void SetUseDefaultListeners(bool useDefault)
|
||||
{
|
||||
if (useDefaultListeners != useDefault)
|
||||
{
|
||||
useDefaultListeners = useDefault;
|
||||
|
||||
if (useDefault)
|
||||
{
|
||||
AkSoundEngine.ResetListenersToDefault(akGameObj.gameObject);
|
||||
for (var i = 0; i < ListenerList.Count; ++i)
|
||||
AkSoundEngine.AddListener(akGameObj.gameObject, ListenerList[i].gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
var Ids = GetListenerIds();
|
||||
AkSoundEngine.SetListeners(akGameObj.gameObject, Ids, Ids == null ? 0 : (uint) Ids.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Init(AkGameObj akGameObj)
|
||||
{
|
||||
this.akGameObj = akGameObj;
|
||||
|
||||
if (!useDefaultListeners)
|
||||
AkSoundEngine.SetListeners(akGameObj.gameObject, null, 0);
|
||||
|
||||
for (var ii = 0; ii < initialListenerList.Count; ++ii)
|
||||
initialListenerList[ii].StartListeningToEmitter(akGameObj);
|
||||
}
|
||||
|
||||
public override bool Add(AkAudioListener listener)
|
||||
{
|
||||
var ret = base.Add(listener);
|
||||
if (ret && AkSoundEngine.IsInitialized())
|
||||
AkSoundEngine.AddListener(akGameObj.gameObject, listener.gameObject);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override bool Remove(AkAudioListener listener)
|
||||
{
|
||||
var ret = base.Remove(listener);
|
||||
if (ret && AkSoundEngine.IsInitialized())
|
||||
AkSoundEngine.RemoveListener(akGameObj.gameObject, listener.gameObject);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public void AddToInitialListenerList(AkAudioListener listener)
|
||||
{
|
||||
if (!initialListenerList.Contains(listener))
|
||||
initialListenerList.Add(listener);
|
||||
}
|
||||
|
||||
public void RemoveFromInitialListenerList(AkAudioListener listener)
|
||||
{
|
||||
initialListenerList.Remove(listener);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 66382d6c68a15ef4fadf9154d33bb8e9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Wwise/Deployment/Components/AkGameObjPosOffsetData.cs
Normal file
17
Assets/Wwise/Deployment/Components/AkGameObjPosOffsetData.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
// *** THIS FILE IS KEPT FOR THE MIGRATION SYSTEM, DO NOT USE THIS CLASS !!! ***
|
||||
|
||||
|
||||
// DEPRECATED
|
||||
public class AkGameObjPosOffsetData : UnityEngine.ScriptableObject
|
||||
{
|
||||
public UnityEngine.Vector3 positionOffset;
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9d9cbd2cf98d7844ba120ac0a6a50ed0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
15
Assets/Wwise/Deployment/Components/AkGameObjPositionData.cs
Normal file
15
Assets/Wwise/Deployment/Components/AkGameObjPositionData.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public class AkGameObjPositionData
|
||||
{
|
||||
public UnityEngine.Vector3 forward;
|
||||
public UnityEngine.Vector3 position;
|
||||
public UnityEngine.Vector3 up;
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 84c659295ef41a144b35166fb09680b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[System.Serializable]
|
||||
public class AkGameObjPositionOffsetData
|
||||
{
|
||||
public bool KeepMe;
|
||||
public UnityEngine.Vector3 positionOffset;
|
||||
|
||||
// Unity tries to construct a AkGameObjPositionOffsetData all the time. Need this ugly workaround
|
||||
// to prevent it from doing this.
|
||||
public AkGameObjPositionOffsetData(bool IReallyWantToBeConstructed = false)
|
||||
{
|
||||
KeepMe = IReallyWantToBeConstructed;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e02507456ba3ebb4b8633735008da5d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
170
Assets/Wwise/Deployment/Components/AkInitializer.cs
Normal file
170
Assets/Wwise/Deployment/Components/AkInitializer.cs
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2012 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkInitializer")]
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
[UnityEngine.ExecuteInEditMode]
|
||||
[UnityEngine.DefaultExecutionOrder(-100)]
|
||||
/// @brief This script deals with initialization, and frame updates of the Wwise audio engine.
|
||||
/// It is marked as \c DontDestroyOnLoad so it stays active for the life of the game,
|
||||
/// not only one scene. Double-click the Initialization Settings entry, AkWwiseInitializationSettings,
|
||||
/// to review and edit Wwise initialization settings.
|
||||
/// \sa
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=workingwithsdks__initialization.html" target="_blank">Initialize the Different Modules of the Sound Engine</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=namespace_a_k_1_1_sound_engine_a27257629833b9481dcfdf5e793d9d037.html#a27257629833b9481dcfdf5e793d9d037" target="_blank">AK::SoundEngine::Init()</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=namespace_a_k_1_1_sound_engine_a9176602bbe972da4acc1f8ebdb37f2bf.html#a9176602bbe972da4acc1f8ebdb37f2bf" target="_blank">AK::SoundEngine::Term()</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
/// - AkCallbackManager
|
||||
public class AkInitializer : UnityEngine.MonoBehaviour
|
||||
{
|
||||
private static AkInitializer ms_Instance;
|
||||
|
||||
public AkWwiseInitializationSettings InitializationSettings;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (ms_Instance)
|
||||
{
|
||||
DestroyImmediate(this);
|
||||
return;
|
||||
}
|
||||
|
||||
ms_Instance = this;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
DontDestroyOnLoad(this);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
InitializationSettings = AkWwiseInitializationSettings.Instance;
|
||||
|
||||
if (ms_Instance == this)
|
||||
AkSoundEngineController.Instance.Init(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (ms_Instance == this)
|
||||
AkSoundEngineController.Instance.OnDisable();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (ms_Instance == this)
|
||||
ms_Instance = null;
|
||||
}
|
||||
|
||||
private void OnApplicationPause(bool pauseStatus)
|
||||
{
|
||||
if (ms_Instance == this)
|
||||
AkSoundEngineController.Instance.OnApplicationPause(pauseStatus);
|
||||
}
|
||||
|
||||
private void OnApplicationFocus(bool focus)
|
||||
{
|
||||
if (ms_Instance == this)
|
||||
AkSoundEngineController.Instance.OnApplicationFocus(focus);
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
if (ms_Instance == this)
|
||||
AkSoundEngineController.Instance.Terminate();
|
||||
}
|
||||
|
||||
//Use LateUpdate instead of Update() to ensure all gameobjects positions, listener positions, environements, RTPC, etc are set before finishing the audio frame.
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (ms_Instance == this)
|
||||
AkSoundEngineController.Instance.LateUpdate();
|
||||
}
|
||||
|
||||
#region WwiseMigration
|
||||
#if UNITY_EDITOR
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
|
||||
// previously serialized data that will be consumed by migration
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private string basePath = string.Empty;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private string language = string.Empty;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private int defaultPoolSize = 0;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private int lowerPoolSize = 0;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private int streamingPoolSize = 0;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private float memoryCutoffThreshold = 0f;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private int monitorPoolSize = 0;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private int monitorQueuePoolSize = 0;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private int callbackManagerBufferSize = 0;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private int spatialAudioPoolSize = 0;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private uint maxSoundPropagationDepth = 0;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private AkDiffractionFlags diffractionFlags = AkDiffractionFlags.DefaultDiffractionFlags;
|
||||
[UnityEngine.HideInInspector][UnityEngine.SerializeField] private bool engineLogging = false;
|
||||
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
private class Migration15Data
|
||||
{
|
||||
bool hasMigrated = false;
|
||||
|
||||
public void Migrate(AkInitializer akInitializer)
|
||||
{
|
||||
if (hasMigrated)
|
||||
return;
|
||||
|
||||
var initializationSettings = akInitializer.InitializationSettings;
|
||||
if (!initializationSettings)
|
||||
{
|
||||
initializationSettings = AkWwiseInitializationSettings.Instance;
|
||||
if (!initializationSettings)
|
||||
return;
|
||||
}
|
||||
|
||||
initializationSettings.UserSettings.m_BasePath = akInitializer.basePath;
|
||||
initializationSettings.UserSettings.m_StartupLanguage = akInitializer.language;
|
||||
|
||||
initializationSettings.AdvancedSettings.m_MonitorQueuePoolSize = (uint)akInitializer.monitorQueuePoolSize * 1024;
|
||||
|
||||
initializationSettings.CallbackManagerInitializationSettings.BufferSize = akInitializer.callbackManagerBufferSize * 1024;
|
||||
|
||||
initializationSettings.UserSettings.m_SpatialAudioSettings.m_MaxSoundPropagationDepth = akInitializer.maxSoundPropagationDepth;
|
||||
initializationSettings.UserSettings.m_SpatialAudioSettings.m_DiffractionFlags = (AkCommonUserSettings.SpatialAudioSettings.DiffractionFlags)akInitializer.diffractionFlags;
|
||||
|
||||
initializationSettings.CallbackManagerInitializationSettings.IsLoggingEnabled = akInitializer.engineLogging;
|
||||
|
||||
UnityEditor.EditorUtility.SetDirty(initializationSettings);
|
||||
UnityEditor.AssetDatabase.SaveAssets();
|
||||
|
||||
UnityEngine.Debug.Log("WwiseUnity: Converted from AkInitializer to AkWwiseInitializationSettings.");
|
||||
hasMigrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static Migration15Data migration15data;
|
||||
|
||||
public static void PreMigration15()
|
||||
{
|
||||
migration15data = new Migration15Data();
|
||||
}
|
||||
|
||||
public void Migrate15()
|
||||
{
|
||||
UnityEngine.Debug.Log("WwiseUnity: AkInitializer.Migrate15 for " + gameObject.name);
|
||||
|
||||
if (migration15data != null)
|
||||
migration15data.Migrate(this);
|
||||
}
|
||||
|
||||
public static void PostMigration15()
|
||||
{
|
||||
migration15data = null;
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkInitializer.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkInitializer.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a4eab75687879a445a2a2397d86a2172
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
137
Assets/Wwise/Deployment/Components/AkMemBankLoader.cs
Normal file
137
Assets/Wwise/Deployment/Components/AkMemBankLoader.cs
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2012 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// @brief This class is an example of how to load banks in Wwise, if the bank data was preloaded in memory.
|
||||
/// This would be useful for situations where you use the WWW class
|
||||
public class AkMemBankLoader : UnityEngine.MonoBehaviour
|
||||
{
|
||||
private const int WaitMs = 50;
|
||||
private const long AK_BANK_PLATFORM_DATA_ALIGNMENT = AkSoundEngine.AK_BANK_PLATFORM_DATA_ALIGNMENT;
|
||||
private const long AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK = AK_BANK_PLATFORM_DATA_ALIGNMENT - 1;
|
||||
|
||||
/// Name of the bank to load
|
||||
public string bankName = "";
|
||||
|
||||
/// Is the bank localized (situated in the language-specific folders)
|
||||
public bool isLocalizedBank = false;
|
||||
|
||||
private string m_bankPath;
|
||||
|
||||
[UnityEngine.HideInInspector] public uint ms_bankID = AkSoundEngine.AK_INVALID_BANK_ID;
|
||||
|
||||
private System.IntPtr ms_pInMemoryBankPtr = System.IntPtr.Zero;
|
||||
private System.Runtime.InteropServices.GCHandle ms_pinnedArray;
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
private UnityEngine.Networking.UnityWebRequest ms_www;
|
||||
#else
|
||||
private UnityEngine.WWW ms_www;
|
||||
#endif
|
||||
|
||||
private void Start()
|
||||
{
|
||||
|
||||
if (isLocalizedBank)
|
||||
LoadLocalizedBank(bankName);
|
||||
else
|
||||
LoadNonLocalizedBank(bankName);
|
||||
}
|
||||
|
||||
/// Load a SoundBank from WWW object
|
||||
public void LoadNonLocalizedBank(string in_bankFilename)
|
||||
{
|
||||
var bankPath = "file://" + System.IO.Path.Combine(AkBasePathGetter.SoundBankBasePath, in_bankFilename);
|
||||
DoLoadBank(bankPath);
|
||||
}
|
||||
|
||||
/// Load a language-specific bank from WWW object
|
||||
public void LoadLocalizedBank(string in_bankFilename)
|
||||
{
|
||||
var bankPath = "file://" + System.IO.Path.Combine(
|
||||
System.IO.Path.Combine(AkBasePathGetter.SoundBankBasePath, AkSoundEngine.GetCurrentLanguage()),
|
||||
in_bankFilename);
|
||||
DoLoadBank(bankPath);
|
||||
}
|
||||
|
||||
private uint AllocateAlignedBuffer(byte[] data)
|
||||
{
|
||||
uint uInMemoryBankSize = 0;
|
||||
|
||||
// Allocate an aligned buffer
|
||||
try
|
||||
{
|
||||
ms_pinnedArray =
|
||||
System.Runtime.InteropServices.GCHandle.Alloc(data, System.Runtime.InteropServices.GCHandleType.Pinned);
|
||||
ms_pInMemoryBankPtr = ms_pinnedArray.AddrOfPinnedObject();
|
||||
uInMemoryBankSize = (uint)data.Length;
|
||||
|
||||
// Array inside the WWW object is not aligned. Allocate a new array for which we can guarantee the alignment.
|
||||
if ((ms_pInMemoryBankPtr.ToInt64() & AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) != 0)
|
||||
{
|
||||
var alignedBytes = new byte[data.Length + AK_BANK_PLATFORM_DATA_ALIGNMENT];
|
||||
var new_pinnedArray =
|
||||
System.Runtime.InteropServices.GCHandle.Alloc(alignedBytes, System.Runtime.InteropServices.GCHandleType.Pinned);
|
||||
var new_pInMemoryBankPtr = new_pinnedArray.AddrOfPinnedObject();
|
||||
var alignedOffset = 0;
|
||||
|
||||
// New array is not aligned, so we will need to use an offset inside it to align our data.
|
||||
if ((new_pInMemoryBankPtr.ToInt64() & AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) != 0)
|
||||
{
|
||||
var alignedPtr = (new_pInMemoryBankPtr.ToInt64() + AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK) &
|
||||
~AK_BANK_PLATFORM_DATA_ALIGNMENT_MASK;
|
||||
alignedOffset = (int)(alignedPtr - new_pInMemoryBankPtr.ToInt64());
|
||||
new_pInMemoryBankPtr = new System.IntPtr(alignedPtr);
|
||||
}
|
||||
|
||||
// Copy the bank's bytes in our new array, at the correct aligned offset.
|
||||
System.Array.Copy(data, 0, alignedBytes, alignedOffset, data.Length);
|
||||
|
||||
ms_pInMemoryBankPtr = new_pInMemoryBankPtr;
|
||||
ms_pinnedArray.Free();
|
||||
ms_pinnedArray = new_pinnedArray;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return uInMemoryBankSize;
|
||||
}
|
||||
|
||||
private System.Collections.IEnumerator LoadFile()
|
||||
{
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
ms_www = UnityEngine.Networking.UnityWebRequest.Get(m_bankPath);
|
||||
yield return ms_www.SendWebRequest();
|
||||
uint uInMemoryBankSize = AllocateAlignedBuffer(ms_www.downloadHandler.data);
|
||||
#else
|
||||
ms_www = new UnityEngine.WWW(m_bankPath);
|
||||
yield return ms_www;
|
||||
uint uInMemoryBankSize = AllocateAlignedBuffer(ms_www.bytes);
|
||||
#endif
|
||||
|
||||
var result = AkSoundEngine.LoadBankMemoryView(ms_pInMemoryBankPtr, uInMemoryBankSize, out ms_bankID);
|
||||
if (result != AKRESULT.AK_Success)
|
||||
UnityEngine.Debug.LogError("WwiseUnity: AkMemBankLoader: bank loading failed with result " + result);
|
||||
}
|
||||
|
||||
private void DoLoadBank(string in_bankPath)
|
||||
{
|
||||
m_bankPath = in_bankPath;
|
||||
StartCoroutine(LoadFile());
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (ms_pInMemoryBankPtr != System.IntPtr.Zero)
|
||||
{
|
||||
var result = AkSoundEngine.UnloadBank(ms_bankID, ms_pInMemoryBankPtr);
|
||||
if (result == AKRESULT.AK_Success)
|
||||
ms_pinnedArray.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkMemBankLoader.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkMemBankLoader.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f9aca49f53350d43ad236969cf19bdf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
129
Assets/Wwise/Deployment/Components/AkObstructionOcclusion.cs
Normal file
129
Assets/Wwise/Deployment/Components/AkObstructionOcclusion.cs
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public abstract class AkObstructionOcclusion : UnityEngine.MonoBehaviour
|
||||
{
|
||||
private readonly System.Collections.Generic.List<AkAudioListener> listenersToRemove =
|
||||
new System.Collections.Generic.List<AkAudioListener>();
|
||||
|
||||
protected readonly System.Collections.Generic.List<AkAudioListener> currentListenerList = new System.Collections.Generic.List<AkAudioListener>();
|
||||
|
||||
private readonly System.Collections.Generic.Dictionary<AkAudioListener, ObstructionOcclusionValue>
|
||||
ObstructionOcclusionValues = new System.Collections.Generic.Dictionary<AkAudioListener, ObstructionOcclusionValue>();
|
||||
|
||||
protected float fadeRate;
|
||||
|
||||
[UnityEngine.Tooltip("Fade time in seconds")]
|
||||
/// The number of seconds for fade ins and fade outs.
|
||||
public float fadeTime = 0.5f;
|
||||
|
||||
[UnityEngine.Tooltip("Layers of obstructers/occluders")]
|
||||
/// Indicates which layers act as obstructers/occluders.
|
||||
public UnityEngine.LayerMask LayerMask = -1;
|
||||
|
||||
[UnityEngine.Tooltip("Maximum distance to perform the obstruction/occlusion. Negative values mean infinite")]
|
||||
/// The maximum distance at which to perform obstruction/occlusion. A negative value will be interpreted as inifinite distance.
|
||||
public float maxDistance = -1.0f;
|
||||
|
||||
[UnityEngine.Tooltip("The number of seconds between raycasts")]
|
||||
/// The number of seconds between obstruction/occlusion checks.
|
||||
public float refreshInterval = 1;
|
||||
|
||||
private float refreshTime;
|
||||
|
||||
protected void InitIntervalsAndFadeRates()
|
||||
{
|
||||
refreshTime = UnityEngine.Random.Range(0.0f, refreshInterval);
|
||||
fadeRate = 1 / fadeTime;
|
||||
}
|
||||
|
||||
protected abstract void UpdateCurrentListenerList();
|
||||
|
||||
private void UpdateObstructionOcclusionValues()
|
||||
{
|
||||
// add new listeners
|
||||
for (var i = 0; i < currentListenerList.Count; ++i)
|
||||
{
|
||||
if (!ObstructionOcclusionValues.ContainsKey(currentListenerList[i]))
|
||||
ObstructionOcclusionValues.Add(currentListenerList[i], new ObstructionOcclusionValue());
|
||||
}
|
||||
|
||||
// remove listeners
|
||||
foreach (var ObsOccPair in ObstructionOcclusionValues)
|
||||
{
|
||||
if (!currentListenerList.Contains(ObsOccPair.Key))
|
||||
listenersToRemove.Add(ObsOccPair.Key);
|
||||
}
|
||||
|
||||
for (var i = 0; i < listenersToRemove.Count; ++i)
|
||||
ObstructionOcclusionValues.Remove(listenersToRemove[i]);
|
||||
|
||||
listenersToRemove.Clear();
|
||||
}
|
||||
|
||||
private void CastRays()
|
||||
{
|
||||
if (refreshTime > refreshInterval)
|
||||
{
|
||||
refreshTime -= refreshInterval;
|
||||
|
||||
foreach (var ObsOccPair in ObstructionOcclusionValues)
|
||||
{
|
||||
var listener = ObsOccPair.Key;
|
||||
var ObsOccValue = ObsOccPair.Value;
|
||||
|
||||
var difference = listener.transform.position - transform.position;
|
||||
var magnitude = difference.magnitude;
|
||||
|
||||
if (maxDistance > 0 && magnitude > maxDistance)
|
||||
ObsOccValue.targetValue = ObsOccValue.currentValue;
|
||||
else
|
||||
{
|
||||
ObsOccValue.targetValue =
|
||||
UnityEngine.Physics.Raycast(transform.position, difference / magnitude, magnitude, LayerMask.value) ? 1.0f : 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
refreshTime += UnityEngine.Time.deltaTime;
|
||||
}
|
||||
|
||||
protected abstract void SetObstructionOcclusion(
|
||||
System.Collections.Generic.KeyValuePair<AkAudioListener, ObstructionOcclusionValue> ObsOccPair);
|
||||
|
||||
private void Update()
|
||||
{
|
||||
currentListenerList.Clear();
|
||||
UpdateCurrentListenerList();
|
||||
UpdateObstructionOcclusionValues();
|
||||
|
||||
CastRays();
|
||||
|
||||
foreach (var ObsOccPair in ObstructionOcclusionValues)
|
||||
{
|
||||
if (ObsOccPair.Value.Update(fadeRate))
|
||||
SetObstructionOcclusion(ObsOccPair);
|
||||
}
|
||||
}
|
||||
|
||||
protected class ObstructionOcclusionValue
|
||||
{
|
||||
public float currentValue;
|
||||
public float targetValue;
|
||||
|
||||
public bool Update(float fadeRate)
|
||||
{
|
||||
if (UnityEngine.Mathf.Approximately(targetValue, currentValue))
|
||||
return false;
|
||||
|
||||
currentValue += fadeRate * UnityEngine.Mathf.Sign(targetValue - currentValue) * UnityEngine.Time.deltaTime;
|
||||
currentValue = UnityEngine.Mathf.Clamp(currentValue, 0.0f, 1.0f);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b3eb01883a0e7dd47a086ef86d13b0ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
83
Assets/Wwise/Deployment/Components/AkRTPCPlayable.cs
Normal file
83
Assets/Wwise/Deployment/Components/AkRTPCPlayable.cs
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
#if !AK_DISABLE_TIMELINE
|
||||
//--------------------------------------------------------------------------------------------
|
||||
// The representation of the Timeline Clip
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
[System.Serializable]
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public class AkRTPCPlayable : UnityEngine.Playables.PlayableAsset, UnityEngine.Timeline.ITimelineClipAsset
|
||||
{
|
||||
public bool overrideTrackObject = false;
|
||||
public UnityEngine.ExposedReference<UnityEngine.GameObject> RTPCObject;
|
||||
|
||||
public bool setRTPCGlobally = false;
|
||||
public AkRTPCPlayableBehaviour template = new AkRTPCPlayableBehaviour();
|
||||
|
||||
public AK.Wwise.RTPC Parameter { get; set; }
|
||||
|
||||
public UnityEngine.Timeline.TimelineClip OwningClip { get; set; }
|
||||
|
||||
UnityEngine.Timeline.ClipCaps UnityEngine.Timeline.ITimelineClipAsset.clipCaps
|
||||
{
|
||||
get { return UnityEngine.Timeline.ClipCaps.Looping & UnityEngine.Timeline.ClipCaps.Extrapolation & UnityEngine.Timeline.ClipCaps.Blending; }
|
||||
}
|
||||
|
||||
public override UnityEngine.Playables.Playable CreatePlayable(UnityEngine.Playables.PlayableGraph graph, UnityEngine.GameObject go)
|
||||
{
|
||||
var playable = UnityEngine.Playables.ScriptPlayable<AkRTPCPlayableBehaviour>.Create(graph, template);
|
||||
var b = playable.GetBehaviour();
|
||||
b.overrideTrackObject = overrideTrackObject;
|
||||
b.setRTPCGlobally = setRTPCGlobally;
|
||||
b.rtpcObject = overrideTrackObject ? RTPCObject.Resolve(graph.GetResolver()) : go;
|
||||
b.parameter = Parameter;
|
||||
return playable;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
// The behaviour template.
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
[System.Serializable]
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public class AkRTPCPlayableBehaviour : UnityEngine.Playables.PlayableBehaviour
|
||||
{
|
||||
[UnityEngine.SerializeField]
|
||||
private float RTPCValue = 0.0f;
|
||||
|
||||
public bool setRTPCGlobally { set; private get; }
|
||||
|
||||
public bool overrideTrackObject { set; private get; }
|
||||
|
||||
public UnityEngine.GameObject rtpcObject { set; private get; }
|
||||
|
||||
public AK.Wwise.RTPC parameter { set; private get; }
|
||||
|
||||
public override void ProcessFrame(UnityEngine.Playables.Playable playable, UnityEngine.Playables.FrameData info,
|
||||
object playerData)
|
||||
{
|
||||
if (parameter != null)
|
||||
{
|
||||
// If we are overriding the track object, the rtpcObject will have been resolved in AkRTPCPlayable::CreatePlayable().
|
||||
if (!overrideTrackObject)
|
||||
{
|
||||
// At this point, rtpcObject will have been set to the timeline owner object in AkRTPCPlayable::CreatePlayable().
|
||||
// If the track object is null, we keep using the timeline owner object. Otherwise, we swap it for the track object.
|
||||
var obj = playerData as UnityEngine.GameObject;
|
||||
if (obj != null)
|
||||
rtpcObject = obj;
|
||||
}
|
||||
|
||||
if (setRTPCGlobally || rtpcObject == null)
|
||||
parameter.SetGlobalValue(RTPCValue);
|
||||
else
|
||||
parameter.SetValue(rtpcObject, RTPCValue);
|
||||
}
|
||||
|
||||
base.ProcessFrame(playable, info, playerData);
|
||||
}
|
||||
}
|
||||
#endif // !AK_DISABLE_TIMELINE
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkRTPCPlayable.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkRTPCPlayable.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aced2414bbc6a004899e4ae2e874e87a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
46
Assets/Wwise/Deployment/Components/AkRTPCTrack.cs
Normal file
46
Assets/Wwise/Deployment/Components/AkRTPCTrack.cs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
#if !AK_DISABLE_TIMELINE
|
||||
|
||||
[UnityEngine.Timeline.TrackColor(0.32f, 0.13f, 0.13f)]
|
||||
// Specifies the type of Playable Asset this track manages
|
||||
[UnityEngine.Timeline.TrackClipType(typeof(AkRTPCPlayable))]
|
||||
// Use if the track requires a binding to a scene object or asset
|
||||
[UnityEngine.Timeline.TrackBindingType(typeof(UnityEngine.GameObject))]
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public class AkRTPCTrack : UnityEngine.Timeline.TrackAsset
|
||||
{
|
||||
public AK.Wwise.RTPC Parameter;
|
||||
|
||||
// override the type of mixer playable used by this track
|
||||
public override UnityEngine.Playables.Playable CreateTrackMixer(UnityEngine.Playables.PlayableGraph graph,
|
||||
UnityEngine.GameObject go, int inputCount)
|
||||
{
|
||||
var playable = UnityEngine.Playables.ScriptPlayable<AkRTPCPlayableBehaviour>.Create(graph, inputCount);
|
||||
setPlayableProperties();
|
||||
return playable;
|
||||
}
|
||||
|
||||
public void setPlayableProperties()
|
||||
{
|
||||
var clips = GetClips();
|
||||
foreach (var clip in clips)
|
||||
{
|
||||
var clipPlayable = (AkRTPCPlayable) clip.asset;
|
||||
clipPlayable.Parameter = Parameter;
|
||||
clipPlayable.OwningClip = clip;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnValidate()
|
||||
{
|
||||
var clips = GetClips();
|
||||
foreach (var clip in clips)
|
||||
{
|
||||
var clipPlayable = (AkRTPCPlayable) clip.asset;
|
||||
clipPlayable.Parameter = Parameter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !AK_DISABLE_TIMELINE
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkRTPCTrack.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkRTPCTrack.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dca565f6e709b0c4682dbc5eece157f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
224
Assets/Wwise/Deployment/Components/AkRoom.cs
Normal file
224
Assets/Wwise/Deployment/Components/AkRoom.cs
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkRoom")]
|
||||
[UnityEngine.RequireComponent(typeof(UnityEngine.Collider))]
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
/// @brief An AkRoom is an enclosed environment that can only communicate to the outside/other rooms with AkRoomPortals
|
||||
/// @details The AkRoom component uses its required Collider component to determine when AkRoomAwareObjects enter and exit the room using the OnTriggerEnter and OnTriggerExit callbacks.
|
||||
public class AkRoom : AkTriggerHandler
|
||||
{
|
||||
public static ulong INVALID_ROOM_ID = unchecked((ulong)-1.0f);
|
||||
|
||||
public static ulong GetAkRoomID(AkRoom room)
|
||||
{
|
||||
return room == null ? INVALID_ROOM_ID : room.GetID();
|
||||
}
|
||||
|
||||
public static int RoomCount { get; private set; }
|
||||
|
||||
#region Fields
|
||||
[UnityEngine.Tooltip("Higher number has a higher priority")]
|
||||
/// In cases where a game object is in an area with two rooms, the higher priority room will be chosen for AK::SpatialAudio::SetGameObjectInRoom()
|
||||
/// The higher the priority number, the higher the priority of a room.
|
||||
public int priority = 0;
|
||||
|
||||
/// The reverb auxiliary bus.
|
||||
public AK.Wwise.AuxBus reverbAuxBus = new AK.Wwise.AuxBus();
|
||||
|
||||
[UnityEngine.Range(0, 1)]
|
||||
/// The reverb control value for the send to the reverb aux bus.
|
||||
public float reverbLevel = 1;
|
||||
|
||||
[UnityEngine.Range(0, 1)]
|
||||
/// Occlusion level modeling transmission through walls.
|
||||
public float wallOcclusion = 1;
|
||||
|
||||
/// Wwise Event to be posted on the room game object.
|
||||
public AK.Wwise.Event roomToneEvent = new AK.Wwise.Event();
|
||||
|
||||
[UnityEngine.Range(0, 1)]
|
||||
[UnityEngine.Tooltip("Send level for sounds that are posted on the room game object; adds reverb to ambience and room tones. Valid range: (0.f-1.f). A value of 0 disables the aux send.")]
|
||||
/// Send level for sounds that are posted on the room game object; adds reverb to ambience and room tones. Valid range: (0.f-1.f). A value of 0 disables the aux send.
|
||||
public float roomToneAuxSend = 0;
|
||||
|
||||
/// This is the list of AkRoomAwareObjects that have entered this AkRoom
|
||||
private System.Collections.Generic.List<AkRoomAwareObject> roomAwareObjectsEntered = new System.Collections.Generic.List<AkRoomAwareObject>();
|
||||
|
||||
/// This is the list of AkRoomAwareObjects that have entered this AkRoom while it was inactive or disabled.
|
||||
private System.Collections.Generic.List<AkRoomAwareObject> roomAwareObjectsDetectedWhileDisabled = new System.Collections.Generic.List<AkRoomAwareObject>();
|
||||
|
||||
#endregion
|
||||
|
||||
public bool TryEnter(AkRoomAwareObject roomAwareObject)
|
||||
{
|
||||
if (roomAwareObject)
|
||||
{
|
||||
if (isActiveAndEnabled)
|
||||
{
|
||||
if(!roomAwareObjectsEntered.Contains(roomAwareObject))
|
||||
roomAwareObjectsEntered.Add(roomAwareObject);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!roomAwareObjectsDetectedWhileDisabled.Contains(roomAwareObject))
|
||||
roomAwareObjectsDetectedWhileDisabled.Add(roomAwareObject);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Exit(AkRoomAwareObject roomAwareObject)
|
||||
{
|
||||
if (roomAwareObject)
|
||||
{
|
||||
roomAwareObjectsEntered.Remove(roomAwareObject);
|
||||
roomAwareObjectsDetectedWhileDisabled.Remove(roomAwareObject);
|
||||
}
|
||||
}
|
||||
|
||||
/// Access the room's ID
|
||||
public ulong GetID()
|
||||
{
|
||||
return AkSoundEngine.GetAkGameObjectID(gameObject);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
var roomParams = new AkRoomParams
|
||||
{
|
||||
Up = transform.up,
|
||||
Front = transform.forward,
|
||||
|
||||
ReverbAuxBus = reverbAuxBus.Id,
|
||||
ReverbLevel = reverbLevel,
|
||||
WallOcclusion = wallOcclusion,
|
||||
|
||||
RoomGameObj_AuxSendLevelToSelf = roomToneAuxSend,
|
||||
RoomGameObj_KeepRegistered = roomToneEvent.IsValid(),
|
||||
};
|
||||
|
||||
RoomCount++;
|
||||
AkSoundEngine.SetRoom(GetID(), roomParams, name);
|
||||
|
||||
/// In case a room is disabled and re-enabled.
|
||||
AkRoomManager.RegisterRoomUpdate(this);
|
||||
|
||||
// if objects entered the room while disabled, enter them now
|
||||
for (var i = 0; i < roomAwareObjectsDetectedWhileDisabled.Count; ++i)
|
||||
AkRoomAwareManager.ObjectEnteredRoom(roomAwareObjectsDetectedWhileDisabled[i], this);
|
||||
|
||||
roomAwareObjectsDetectedWhileDisabled.Clear();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
for (var i = 0; i < roomAwareObjectsEntered.Count; ++i)
|
||||
{
|
||||
roomAwareObjectsEntered[i].ExitedRoom(this);
|
||||
AkRoomAwareManager.RegisterRoomAwareObjectForUpdate(roomAwareObjectsEntered[i]);
|
||||
roomAwareObjectsDetectedWhileDisabled.Add(roomAwareObjectsEntered[i]);
|
||||
}
|
||||
roomAwareObjectsEntered.Clear();
|
||||
|
||||
AkRoomManager.RegisterRoomUpdate(this);
|
||||
|
||||
// stop sounds applied to the room game object
|
||||
AkSoundEngine.StopAll(gameObject);
|
||||
|
||||
RoomCount--;
|
||||
AkSoundEngine.RemoveRoom(GetID());
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(UnityEngine.Collider in_other)
|
||||
{
|
||||
AkRoomAwareManager.ObjectEnteredRoom(in_other, this);
|
||||
}
|
||||
|
||||
private void OnTriggerExit(UnityEngine.Collider in_other)
|
||||
{
|
||||
AkRoomAwareManager.ObjectExitedRoom(in_other, this);
|
||||
}
|
||||
|
||||
public void PostRoomTone()
|
||||
{
|
||||
if (roomToneEvent.IsValid())
|
||||
AkSoundEngine.PostEventOnRoom(roomToneEvent.Id, GetID());
|
||||
}
|
||||
|
||||
public override void HandleEvent(UnityEngine.GameObject in_gameObject)
|
||||
{
|
||||
PostRoomTone();
|
||||
}
|
||||
|
||||
public class PriorityList
|
||||
{
|
||||
private static readonly CompareByPriority s_compareByPriority = new CompareByPriority();
|
||||
|
||||
/// Contains all active rooms sorted by priority.
|
||||
private System.Collections.Generic.List<AkRoom> rooms = new System.Collections.Generic.List<AkRoom>();
|
||||
|
||||
public ulong GetHighestPriorityActiveAndEnabledRoomID()
|
||||
{
|
||||
var room = GetHighestPriorityActiveAndEnabledRoom();
|
||||
return room == null ? INVALID_ROOM_ID : room.GetID();
|
||||
}
|
||||
public AkRoom GetHighestPriorityActiveAndEnabledRoom()
|
||||
{
|
||||
for (int i = 0; i < rooms.Count; i++)
|
||||
{
|
||||
if (rooms[i].isActiveAndEnabled)
|
||||
return rooms[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int Count { get { return rooms.Count; } }
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
rooms.Clear();
|
||||
}
|
||||
|
||||
public void Add(AkRoom room)
|
||||
{
|
||||
var index = BinarySearch(room);
|
||||
if (index < 0)
|
||||
rooms.Insert(~index, room);
|
||||
}
|
||||
|
||||
public void Remove(AkRoom room)
|
||||
{
|
||||
rooms.Remove(room);
|
||||
}
|
||||
|
||||
public bool Contains(AkRoom room)
|
||||
{
|
||||
return room && rooms.Contains(room);
|
||||
}
|
||||
|
||||
public int BinarySearch(AkRoom room)
|
||||
{
|
||||
return room ? rooms.BinarySearch(room, s_compareByPriority) : -1;
|
||||
}
|
||||
|
||||
public AkRoom this[int index]
|
||||
{
|
||||
get { return rooms[index]; }
|
||||
}
|
||||
|
||||
private class CompareByPriority : System.Collections.Generic.IComparer<AkRoom>
|
||||
{
|
||||
public virtual int Compare(AkRoom a, AkRoom b)
|
||||
{
|
||||
var result = a.priority.CompareTo(b.priority);
|
||||
if (result == 0 && a != b)
|
||||
return 1;
|
||||
|
||||
return -result; // inverted to have highest priority first
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkRoom.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkRoom.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ccc628e0c5921f7479852cfe921ddf1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
85
Assets/Wwise/Deployment/Components/AkRoomAwareObject.cs
Normal file
85
Assets/Wwise/Deployment/Components/AkRoomAwareObject.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
#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
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// <summary>
|
||||
/// This component makes a GameObject aware of AkRoom components.
|
||||
/// When using Spatial Audio rooms, all emitters and the spatial audio listener should have this component.
|
||||
/// </summary>
|
||||
[UnityEngine.RequireComponent(typeof(AkGameObj))]
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
public class AkRoomAwareObject : UnityEngine.MonoBehaviour
|
||||
{
|
||||
private static readonly System.Collections.Generic.Dictionary<UnityEngine.Collider, AkRoomAwareObject> ColliderToRoomAwareObjectMap = new System.Collections.Generic.Dictionary<UnityEngine.Collider, AkRoomAwareObject>();
|
||||
|
||||
public static AkRoomAwareObject GetAkRoomAwareObjectFromCollider(UnityEngine.Collider collider)
|
||||
{
|
||||
AkRoomAwareObject roomAwareObject = null;
|
||||
return ColliderToRoomAwareObjectMap.TryGetValue(collider, out roomAwareObject) ? roomAwareObject : null;
|
||||
}
|
||||
|
||||
public UnityEngine.Collider m_Collider;
|
||||
private readonly AkRoom.PriorityList roomPriorityList = new AkRoom.PriorityList();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_Collider = GetComponent<UnityEngine.Collider>();
|
||||
if (m_Collider != null)
|
||||
ColliderToRoomAwareObjectMap.Add(m_Collider, this);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
AkRoomAwareManager.RegisterRoomAwareObject(this);
|
||||
|
||||
for (int i = 0; i < roomPriorityList.Count; ++i)
|
||||
roomPriorityList[i].TryEnter(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
for (int i = 0; i < roomPriorityList.Count; ++i)
|
||||
roomPriorityList[i].Exit(this);
|
||||
|
||||
AkRoomAwareManager.UnregisterRoomAwareObject(this);
|
||||
|
||||
SetGameObjectInRoom(null);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ColliderToRoomAwareObjectMap.Remove(m_Collider);
|
||||
}
|
||||
|
||||
public void SetGameObjectInHighestPriorityActiveAndEnabledRoom()
|
||||
{
|
||||
SetGameObjectInRoom(roomPriorityList.GetHighestPriorityActiveAndEnabledRoom());
|
||||
}
|
||||
|
||||
private void SetGameObjectInRoom(AkRoom room)
|
||||
{
|
||||
AkSoundEngine.SetGameObjectInRoom(gameObject, room == null ? AkRoom.INVALID_ROOM_ID : room.GetID());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when entering a room.
|
||||
/// </summary>
|
||||
/// <param name="room">The room.</param>
|
||||
public void EnteredRoom(AkRoom room)
|
||||
{
|
||||
roomPriorityList.Add(room);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when exiting a room.
|
||||
/// </summary>
|
||||
/// <param name="room">The room.</param>
|
||||
public void ExitedRoom(AkRoom room)
|
||||
{
|
||||
roomPriorityList.Remove(room);
|
||||
}
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkRoomAwareObject.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkRoomAwareObject.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 993b3937fde4a704eb1c8b379a97410c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
316
Assets/Wwise/Deployment/Components/AkRoomPortal.cs
Normal file
316
Assets/Wwise/Deployment/Components/AkRoomPortal.cs
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkRoomPortal")]
|
||||
[UnityEngine.RequireComponent(typeof(UnityEngine.BoxCollider))]
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
/// @brief An AkRoomPortal can connect two AkRoom components together.
|
||||
/// @details
|
||||
public class AkRoomPortal : AkTriggerHandler
|
||||
{
|
||||
/// AkRoomPortals can only connect a maximum of 2 rooms.
|
||||
public const int MAX_ROOMS_PER_PORTAL = 2;
|
||||
public enum State
|
||||
{
|
||||
Closed,
|
||||
Open
|
||||
}
|
||||
|
||||
public State initialState = State.Closed;
|
||||
|
||||
private bool active = true;
|
||||
public bool portalActive
|
||||
{
|
||||
get
|
||||
{
|
||||
return active;
|
||||
}
|
||||
set
|
||||
{
|
||||
active = value;
|
||||
AkRoomManager.RegisterPortalUpdate(this);
|
||||
}
|
||||
}
|
||||
|
||||
public System.Collections.Generic.List<int> closePortalTriggerList = new System.Collections.Generic.List<int>();
|
||||
|
||||
private ulong frontRoomID { get { return IsRoomActive(frontRoom) ? frontRoom.GetID() : AkRoom.INVALID_ROOM_ID; } }
|
||||
private ulong backRoomID { get { return IsRoomActive(backRoom) ? backRoom.GetID() : AkRoom.INVALID_ROOM_ID; } }
|
||||
|
||||
/// The front and back rooms connected by the portal.
|
||||
/// The first room is on the negative side of the portal(opposite to the direction of the local Z axis)
|
||||
/// The second room is on the positive side of the portal.
|
||||
[UnityEngine.SerializeField]
|
||||
private AkRoom[] rooms = new AkRoom[MAX_ROOMS_PER_PORTAL];
|
||||
|
||||
/// The list of rooms sorted by priority in front and in the back of the portal
|
||||
private AkRoom.PriorityList[] roomList = { new AkRoom.PriorityList(), new AkRoom.PriorityList() };
|
||||
|
||||
public AkRoom GetRoom(int index) { return rooms[index]; }
|
||||
|
||||
public AkRoom frontRoom { get { return rooms[1]; } }
|
||||
public AkRoom backRoom { get { return rooms[0]; } }
|
||||
|
||||
private AkTransform portalTransform;
|
||||
private UnityEngine.BoxCollider portalCollider;
|
||||
private bool portalSet = false;
|
||||
|
||||
private void SetRoomPortal()
|
||||
{
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
if (IsValid)
|
||||
{
|
||||
portalTransform.Set(portalCollider.bounds.center, transform.forward, transform.up);
|
||||
var extent = UnityEngine.Vector3.Scale(portalCollider.size, transform.localScale) / 2;
|
||||
AkSoundEngine.SetRoomPortal(GetID(), portalTransform, extent, active, frontRoomID, backRoomID);
|
||||
portalSet = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.LogError(name + " has identical front and back rooms. It will not be sent to Spatial Audio.");
|
||||
if (portalSet)
|
||||
AkSoundEngine.RemovePortal(GetID());
|
||||
portalSet = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateRoomPortal()
|
||||
{
|
||||
UpdateRooms();
|
||||
SetRoomPortal();
|
||||
}
|
||||
|
||||
public bool Overlaps(AkRoom room)
|
||||
{
|
||||
FindOverlappingRooms(roomList);
|
||||
|
||||
for (int i = 0; i < MAX_ROOMS_PER_PORTAL; ++i)
|
||||
{
|
||||
if (roomList[i].Contains(room))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsValid { get { return frontRoomID != backRoomID; } }
|
||||
|
||||
/// Access the portal's ID
|
||||
public ulong GetID() { return (ulong)GetInstanceID(); }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
portalCollider = GetComponent<UnityEngine.BoxCollider>();
|
||||
portalCollider.isTrigger = true;
|
||||
|
||||
portalTransform = new AkTransform();
|
||||
|
||||
// set portal in it's initial state
|
||||
portalActive = initialState != State.Closed;
|
||||
|
||||
RegisterTriggers(closePortalTriggerList, ClosePortal);
|
||||
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
//Call the ClosePortal function if registered to the Start Trigger
|
||||
if (closePortalTriggerList.Contains(START_TRIGGER_ID))
|
||||
ClosePortal(null);
|
||||
}
|
||||
|
||||
/// Opens the portal on trigger event
|
||||
public override void HandleEvent(UnityEngine.GameObject in_gameObject)
|
||||
{
|
||||
Open();
|
||||
}
|
||||
|
||||
/// Closes the portal on trigger event
|
||||
public void ClosePortal(UnityEngine.GameObject in_gameObject)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
UnregisterTriggers(closePortalTriggerList, ClosePortal);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
UpdateRooms();
|
||||
AkRoomManager.RegisterPortal(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
AkRoomManager.UnregisterPortal(this);
|
||||
if (portalSet)
|
||||
AkSoundEngine.RemovePortal(GetID());
|
||||
portalSet = false;
|
||||
}
|
||||
|
||||
private bool IsRoomActive(AkRoom in_room)
|
||||
{
|
||||
return in_room != null && in_room.isActiveAndEnabled;
|
||||
}
|
||||
|
||||
public void Open()
|
||||
{
|
||||
portalActive = true;
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
portalActive = false;
|
||||
}
|
||||
|
||||
public void FindOverlappingRooms(AkRoom.PriorityList[] roomList)
|
||||
{
|
||||
var portalCollider = gameObject.GetComponent<UnityEngine.BoxCollider>();
|
||||
if (portalCollider == null)
|
||||
return;
|
||||
|
||||
// compute halfExtents and divide the local z extent by 2
|
||||
var halfExtentZ = portalCollider.size.z / 2;
|
||||
|
||||
// move the center backward
|
||||
FillRoomList(UnityEngine.Vector3.forward * -halfExtentZ, roomList[0]);
|
||||
|
||||
// move the center forward
|
||||
FillRoomList(UnityEngine.Vector3.forward * halfExtentZ, roomList[1]);
|
||||
}
|
||||
|
||||
private void FillRoomList(UnityEngine.Vector3 position, AkRoom.PriorityList list)
|
||||
{
|
||||
list.Clear();
|
||||
|
||||
position = transform.TransformPoint(position);
|
||||
var colliders = UnityEngine.Physics.OverlapSphere(position, 0, -1, UnityEngine.QueryTriggerInteraction.Collide);
|
||||
|
||||
foreach (var collider in colliders)
|
||||
{
|
||||
var room = collider.gameObject.GetComponent<AkRoom>();
|
||||
if (room != null && !list.Contains(room))
|
||||
list.Add(room);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateRooms()
|
||||
{
|
||||
FindOverlappingRooms(roomList);
|
||||
|
||||
bool wasUpdated = false;
|
||||
|
||||
for (var i = 0; i < MAX_ROOMS_PER_PORTAL; ++i)
|
||||
{
|
||||
var room = roomList[i].GetHighestPriorityActiveAndEnabledRoom();
|
||||
|
||||
if (room != rooms[i])
|
||||
wasUpdated = true;
|
||||
|
||||
rooms[i] = room;
|
||||
}
|
||||
|
||||
if (wasUpdated)
|
||||
AkRoomManager.RegisterPortalUpdate(this);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (!enabled)
|
||||
return;
|
||||
|
||||
UnityEngine.Gizmos.matrix = transform.localToWorldMatrix;
|
||||
|
||||
var centreOffset = UnityEngine.Vector3.zero;
|
||||
var sizeMultiplier = UnityEngine.Vector3.one;
|
||||
var collider = GetComponent<UnityEngine.BoxCollider>();
|
||||
if (collider)
|
||||
{
|
||||
centreOffset = collider.center;
|
||||
sizeMultiplier = collider.size;
|
||||
}
|
||||
|
||||
// color faces
|
||||
var faceCenterPos = new UnityEngine.Vector3[6];
|
||||
faceCenterPos[0] = UnityEngine.Vector3.Scale(new UnityEngine.Vector3(0.5f, 0.0f, 0.0f), sizeMultiplier);
|
||||
faceCenterPos[1] = UnityEngine.Vector3.Scale(new UnityEngine.Vector3(0.0f, 0.5f, 0.0f), sizeMultiplier);
|
||||
faceCenterPos[2] = UnityEngine.Vector3.Scale(new UnityEngine.Vector3(-0.5f, 0.0f, 0.0f), sizeMultiplier);
|
||||
faceCenterPos[3] = UnityEngine.Vector3.Scale(new UnityEngine.Vector3(0.0f, -0.5f, 0.0f), sizeMultiplier);
|
||||
faceCenterPos[4] = UnityEngine.Vector3.Scale(new UnityEngine.Vector3(0.0f, 0.0f, 0.5f), sizeMultiplier);
|
||||
faceCenterPos[5] = UnityEngine.Vector3.Scale(new UnityEngine.Vector3(0.0f, 0.0f, -0.5f), sizeMultiplier);
|
||||
|
||||
var faceSize = new UnityEngine.Vector3[6];
|
||||
faceSize[0] = new UnityEngine.Vector3(0, 1, 1);
|
||||
faceSize[1] = new UnityEngine.Vector3(1, 0, 1);
|
||||
faceSize[2] = faceSize[0];
|
||||
faceSize[3] = faceSize[1];
|
||||
faceSize[4] = new UnityEngine.Vector3(1, 1, 0);
|
||||
faceSize[5] = faceSize[4];
|
||||
|
||||
UnityEngine.Gizmos.color = new UnityEngine.Color32(255, 204, 0, 100);
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
UnityEngine.Gizmos.DrawCube(faceCenterPos[i] + centreOffset, UnityEngine.Vector3.Scale(faceSize[i], sizeMultiplier));
|
||||
}
|
||||
|
||||
if (!portalActive)
|
||||
{
|
||||
UnityEngine.Gizmos.color = new UnityEngine.Color32(255, 204, 0, 30);
|
||||
UnityEngine.Gizmos.DrawCube(faceCenterPos[4] + centreOffset, UnityEngine.Vector3.Scale(faceSize[4], sizeMultiplier));
|
||||
UnityEngine.Gizmos.DrawCube(faceCenterPos[5] + centreOffset, UnityEngine.Vector3.Scale(faceSize[5], sizeMultiplier));
|
||||
}
|
||||
|
||||
// draw line in the center of the portal
|
||||
var CornerCenterPos = faceCenterPos;
|
||||
CornerCenterPos[0].y += 0.5f * sizeMultiplier.y;
|
||||
CornerCenterPos[1].x -= 0.5f * sizeMultiplier.x;
|
||||
CornerCenterPos[2].y -= 0.5f * sizeMultiplier.y;
|
||||
CornerCenterPos[3].x += 0.5f * sizeMultiplier.x;
|
||||
|
||||
UnityEngine.Gizmos.color = UnityEngine.Color.red;
|
||||
for (var i = 0; i < 4; i++)
|
||||
UnityEngine.Gizmos.DrawLine(CornerCenterPos[i] + centreOffset, CornerCenterPos[(i + 1) % 4] + centreOffset);
|
||||
}
|
||||
#endif
|
||||
|
||||
#region Obsolete
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public void SetRoom(int in_roomIndex, AkRoom in_room)
|
||||
{
|
||||
UnityEngine.Debug.LogFormat("SetRoom is deprecated. Highest priority, active and enabled room will be automatically chosen. Make sure room priorities and game object placements are correct.");
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public void SetFrontRoom(AkRoom room)
|
||||
{
|
||||
UnityEngine.Debug.LogFormat("SetFrontRoom is deprecated. Highest priority, active and enabled room will be automatically chosen. Make sure room priorities and game object placements are correct.");
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public void SetBackRoom(AkRoom room)
|
||||
{
|
||||
UnityEngine.Debug.LogFormat("SetBackRoom is deprecated. Highest priority, active and enabled room will be automatically chosen. Make sure room priorities and game object placements are correct.");
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public void UpdateSoundEngineRoomIDs()
|
||||
{
|
||||
UpdateRoomPortal();
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public void UpdateOverlappingRooms()
|
||||
{
|
||||
UpdateRooms();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkRoomPortal.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkRoomPortal.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e8ebe44e536b3d24190d9bf194f8f6e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkRoomPortalObstruction")]
|
||||
[UnityEngine.RequireComponent(typeof(AkRoomPortal))]
|
||||
/// @brief Completely obstructs the spatial audio portal of the current game object from the spatial audio listener if at least one object is between them.
|
||||
/// @details If no spatial audio listener has been registered, there will be no obstruction.
|
||||
public class AkRoomPortalObstruction : AkObstructionOcclusion
|
||||
{
|
||||
private AkRoomPortal m_portal;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
InitIntervalsAndFadeRates();
|
||||
m_portal = GetComponent<AkRoomPortal>();
|
||||
}
|
||||
|
||||
protected override void UpdateCurrentListenerList()
|
||||
{
|
||||
currentListenerList.Add(AkSpatialAudioListener.TheSpatialAudioListener);
|
||||
}
|
||||
|
||||
protected override void SetObstructionOcclusion(
|
||||
System.Collections.Generic.KeyValuePair<AkAudioListener, ObstructionOcclusionValue> ObsOccPair)
|
||||
{
|
||||
if (m_portal.IsValid)
|
||||
AkSoundEngine.SetPortalObstructionAndOcclusion(m_portal.GetID(), ObsOccPair.Value.currentValue, 0.0f);
|
||||
}
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 53c8f9324e708a3409541798bf8a7473
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
301
Assets/Wwise/Deployment/Components/AkSoundEngineController.cs
Normal file
301
Assets/Wwise/Deployment/Components/AkSoundEngineController.cs
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
public class AkSoundEngineController
|
||||
{
|
||||
private static AkSoundEngineController ms_Instance;
|
||||
|
||||
public static AkSoundEngineController Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ms_Instance == null)
|
||||
ms_Instance = new AkSoundEngineController();
|
||||
|
||||
return ms_Instance;
|
||||
}
|
||||
}
|
||||
|
||||
private AkSoundEngineController()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.pauseStateChanged += OnPauseStateChanged;
|
||||
#endif
|
||||
}
|
||||
|
||||
~AkSoundEngineController()
|
||||
{
|
||||
if (ms_Instance == this)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.EditorApplication.pauseStateChanged -= OnPauseStateChanged;
|
||||
UnityEditor.EditorApplication.update -= LateUpdate;
|
||||
#endif
|
||||
ms_Instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!IsSoundEngineLoaded)
|
||||
return;
|
||||
#endif
|
||||
|
||||
//Execute callbacks that occurred in last frame (not the current update)
|
||||
AkRoomManager.Update();
|
||||
AkRoomAwareManager.UpdateRoomAwareObjects();
|
||||
AkCallbackManager.PostCallbacks();
|
||||
AkBankManager.DoUnloadBanks();
|
||||
AkSoundEngine.RenderAudio();
|
||||
}
|
||||
|
||||
public void Init(AkInitializer akInitializer)
|
||||
{
|
||||
// Only initialize the room mamanger during play.
|
||||
bool initRoomManager = true;
|
||||
#if UNITY_EDITOR
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
initRoomManager = false;
|
||||
#endif
|
||||
if (initRoomManager)
|
||||
AkRoomManager.Init();
|
||||
|
||||
if (akInitializer == null)
|
||||
{
|
||||
UnityEngine.Debug.LogError("WwiseUnity: AkInitializer must not be null. Sound engine will not be initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEngine.Application.isPlaying && !IsTheSingleOwningInitializer(akInitializer))
|
||||
{
|
||||
UnityEngine.Debug.LogError("WwiseUnity: Sound engine is already initialized.");
|
||||
return;
|
||||
}
|
||||
|
||||
var arguments = System.Environment.GetCommandLineArgs();
|
||||
if ((System.Array.IndexOf(arguments, "-nographics") >= 0 || System.Array.IndexOf(arguments, "-batchmode") >= 0) && System.Array.IndexOf(arguments, "-wwiseEnableWithNoGraphics") < 0)
|
||||
return;
|
||||
|
||||
var isInitialized = false;
|
||||
try
|
||||
{
|
||||
isInitialized = AkSoundEngine.IsInitialized();
|
||||
IsSoundEngineLoaded = true;
|
||||
}
|
||||
catch (System.DllNotFoundException)
|
||||
{
|
||||
IsSoundEngineLoaded = false;
|
||||
UnityEngine.Debug.LogWarning("WwiseUnity: AkSoundEngine is not loaded.");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
var isInitialized = AkSoundEngine.IsInitialized();
|
||||
#endif
|
||||
|
||||
AkLogger.Instance.Init();
|
||||
|
||||
if (isInitialized)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (AkWwiseInitializationSettings.ResetSoundEngine(UnityEngine.Application.isPlaying || UnityEditor.BuildPipeline.isBuildingPlayer))
|
||||
{
|
||||
UnityEditor.EditorApplication.update += LateUpdate;
|
||||
}
|
||||
|
||||
if (UnityEditor.EditorApplication.isPaused && UnityEngine.Application.isPlaying)
|
||||
{
|
||||
AkSoundEngine.Suspend(true);
|
||||
}
|
||||
#else
|
||||
UnityEngine.Debug.LogError("WwiseUnity: Sound engine is already initialized.");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (!AkWwiseInitializationSettings.InitializeSoundEngine())
|
||||
return;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
OnEnableEditorListener(akInitializer.gameObject);
|
||||
UnityEditor.EditorApplication.update += LateUpdate;
|
||||
#endif
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!IsSoundEngineLoaded)
|
||||
return;
|
||||
|
||||
OnDisableEditorListener();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
ClearInitializeState();
|
||||
|
||||
if (!IsSoundEngineLoaded)
|
||||
return;
|
||||
#endif
|
||||
|
||||
AkWwiseInitializationSettings.TerminateSoundEngine();
|
||||
AkRoomManager.Terminate();
|
||||
}
|
||||
|
||||
// In the Editor, the sound needs to keep playing when switching windows (remote debugging in Wwise, for example).
|
||||
// On iOS, application interruptions are handled in the sound engine already.
|
||||
#if UNITY_EDITOR || UNITY_IOS
|
||||
public void OnApplicationPause(bool pauseStatus)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnApplicationFocus(bool focus)
|
||||
{
|
||||
}
|
||||
#else
|
||||
public void OnApplicationPause(bool pauseStatus)
|
||||
{
|
||||
ActivateAudio(!pauseStatus);
|
||||
}
|
||||
|
||||
public void OnApplicationFocus(bool focus)
|
||||
{
|
||||
#if !UNITY_ANDROID
|
||||
ActivateAudio(focus, AkWwiseInitializationSettings.ActivePlatformSettings.RenderDuringFocusLoss);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public bool IsSoundEngineLoaded { get; set; }
|
||||
|
||||
// Enable/Disable the audio when pressing play/pause in the editor.
|
||||
private void OnPauseStateChanged(UnityEditor.PauseState pauseState)
|
||||
{
|
||||
if (UnityEngine.Application.isPlaying)
|
||||
{
|
||||
ActivateAudio(pauseState != UnityEditor.PauseState.Paused);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR || !UNITY_IOS
|
||||
private void ActivateAudio(bool activate, bool renderAnyway = false)
|
||||
{
|
||||
if (AkSoundEngine.IsInitialized())
|
||||
{
|
||||
if (activate)
|
||||
AkSoundEngine.WakeupFromSuspend();
|
||||
else
|
||||
AkSoundEngine.Suspend(renderAnyway);
|
||||
|
||||
AkSoundEngine.RenderAudio();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#region Editor Listener
|
||||
private UnityEngine.GameObject editorListenerGameObject;
|
||||
|
||||
private bool IsPlayingOrIsNotInitialized
|
||||
{
|
||||
get { return UnityEngine.Application.isPlaying || !AkSoundEngine.IsInitialized(); }
|
||||
}
|
||||
|
||||
private void OnEnableEditorListener(UnityEngine.GameObject gameObject)
|
||||
{
|
||||
if (IsPlayingOrIsNotInitialized || editorListenerGameObject != null)
|
||||
return;
|
||||
|
||||
editorListenerGameObject = gameObject;
|
||||
AkSoundEngine.RegisterGameObj(editorListenerGameObject, editorListenerGameObject.name);
|
||||
|
||||
// Do not create AkGameObj component when adding this listener
|
||||
var id = AkSoundEngine.GetAkGameObjectID(editorListenerGameObject);
|
||||
AkSoundEnginePINVOKE.CSharp_AddDefaultListener(id);
|
||||
|
||||
UnityEditor.EditorApplication.update += UpdateEditorListenerPosition;
|
||||
}
|
||||
|
||||
private void OnDisableEditorListener()
|
||||
{
|
||||
if (IsPlayingOrIsNotInitialized || editorListenerGameObject == null)
|
||||
return;
|
||||
|
||||
UnityEditor.EditorApplication.update -= UpdateEditorListenerPosition;
|
||||
|
||||
var id = AkSoundEngine.GetAkGameObjectID(editorListenerGameObject);
|
||||
AkSoundEnginePINVOKE.CSharp_RemoveDefaultListener(id);
|
||||
|
||||
AkSoundEngine.UnregisterGameObj(editorListenerGameObject);
|
||||
editorListenerGameObject = null;
|
||||
}
|
||||
|
||||
private UnityEngine.Vector3 editorListenerPosition = UnityEngine.Vector3.zero;
|
||||
private UnityEngine.Vector3 editorListenerForward = UnityEngine.Vector3.zero;
|
||||
private UnityEngine.Vector3 editorListenerUp = UnityEngine.Vector3.zero;
|
||||
|
||||
private void UpdateEditorListenerPosition()
|
||||
{
|
||||
if (IsPlayingOrIsNotInitialized || editorListenerGameObject == null)
|
||||
return;
|
||||
|
||||
if (UnityEditor.SceneView.lastActiveSceneView == null)
|
||||
return;
|
||||
|
||||
var sceneViewCamera = UnityEditor.SceneView.lastActiveSceneView.camera;
|
||||
if (sceneViewCamera == null)
|
||||
return;
|
||||
|
||||
var sceneViewTransform = sceneViewCamera.transform;
|
||||
if (sceneViewTransform == null)
|
||||
return;
|
||||
|
||||
if (editorListenerPosition == sceneViewTransform.position &&
|
||||
editorListenerForward == sceneViewTransform.forward &&
|
||||
editorListenerUp == sceneViewTransform.up)
|
||||
return;
|
||||
|
||||
AkSoundEngine.SetObjectPosition(editorListenerGameObject, sceneViewTransform);
|
||||
|
||||
editorListenerPosition = sceneViewTransform.position;
|
||||
editorListenerForward = sceneViewTransform.forward;
|
||||
editorListenerUp = sceneViewTransform.up;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Initialize only once
|
||||
private AkInitializer TheAkInitializer = null;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether this AkInitializer is the single one responsible for initializing the sound engine.
|
||||
/// </summary>
|
||||
/// <param name="akInitializer"></param>
|
||||
/// <returns>Returns true when called on the first AkInitializer and false otherwise.</returns>
|
||||
private bool IsTheSingleOwningInitializer(AkInitializer akInitializer)
|
||||
{
|
||||
if (TheAkInitializer == null && akInitializer != null)
|
||||
{
|
||||
TheAkInitializer = akInitializer;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void ClearInitializeState()
|
||||
{
|
||||
TheAkInitializer = null;
|
||||
}
|
||||
#endregion
|
||||
#endif // UNITY_EDITOR
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e0bddedd415524746b63c64ff8d9b2ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
176
Assets/Wwise/Deployment/Components/AkSpatialAudioDebugDraw.cs
Normal file
176
Assets/Wwise/Deployment/Components/AkSpatialAudioDebugDraw.cs
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkSpatialAudioDebugDraw")]
|
||||
[UnityEngine.RequireComponent(typeof(AkGameObj))]
|
||||
///@brief Add this script on a GameObject to print Spatial Audio paths.
|
||||
public class AkSpatialAudioDebugDraw : UnityEngine.MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// This allows you to visualize first order reflection sound paths.
|
||||
public bool drawFirstOrderReflections = false;
|
||||
|
||||
/// This allows you to visualize second order reflection sound paths.
|
||||
public bool drawSecondOrderReflections = false;
|
||||
|
||||
/// This allows you to visualize third or higher order reflection sound paths.
|
||||
public bool drawHigherOrderReflections = false;
|
||||
|
||||
/// This allows you to visualize geometric diffraction sound paths between an obstructed emitter and the listener.
|
||||
public bool drawDiffractionPaths = false;
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (!UnityEngine.Application.isPlaying || !AkSoundEngine.IsInitialized())
|
||||
return;
|
||||
|
||||
if (debugDrawData == null)
|
||||
debugDrawData = new DebugDrawData();
|
||||
|
||||
if (drawFirstOrderReflections || drawSecondOrderReflections || drawHigherOrderReflections)
|
||||
debugDrawData.DebugDrawEarlyReflections(gameObject, drawFirstOrderReflections, drawSecondOrderReflections, drawHigherOrderReflections);
|
||||
|
||||
if (drawDiffractionPaths)
|
||||
debugDrawData.DebugDrawDiffraction(gameObject);
|
||||
}
|
||||
|
||||
private class DebugDrawData
|
||||
{
|
||||
// Constants
|
||||
private const uint kMaxIndirectPaths = 64;
|
||||
private const uint kMaxDiffractionPaths = 16;
|
||||
private readonly UnityEngine.Color32 colorLightYellow = new UnityEngine.Color32(255, 255, 121, 255);
|
||||
private readonly UnityEngine.Color32 colorDarkYellow = new UnityEngine.Color32(164, 164, 0, 255);
|
||||
private readonly UnityEngine.Color32 colorLightOrange = new UnityEngine.Color32(255, 202, 79, 255);
|
||||
private readonly UnityEngine.Color32 colorDarkOrange = new UnityEngine.Color32(164, 115, 0, 255);
|
||||
private readonly UnityEngine.Color32 colorLightRed = new UnityEngine.Color32(252, 177, 162, 255);
|
||||
private readonly UnityEngine.Color32 colorDarkRed = new UnityEngine.Color32(169, 62, 39, 255);
|
||||
private readonly UnityEngine.Color32 colorLightGrey = new UnityEngine.Color32(75, 75, 75, 255);
|
||||
private readonly UnityEngine.Color32 colorGreen = new UnityEngine.Color32(38, 113, 88, 255);
|
||||
private const float radiusSphere = 0.25f;
|
||||
|
||||
// Calculated path info
|
||||
private readonly AkReflectionPathInfoArray indirectPathInfoArray = new AkReflectionPathInfoArray((int)kMaxIndirectPaths);
|
||||
private readonly AkDiffractionPathInfoArray diffractionPathInfoArray = new AkDiffractionPathInfoArray((int)kMaxDiffractionPaths);
|
||||
|
||||
public void DebugDrawEarlyReflections(UnityEngine.GameObject gameObject, bool firstOrder, bool secondOrder, bool higherOrder)
|
||||
{
|
||||
var listenerPosition = UnityEngine.Vector3.zero;
|
||||
var emitterPosition = UnityEngine.Vector3.zero;
|
||||
uint numValidPaths = (uint)indirectPathInfoArray.Count();
|
||||
if (AkSoundEngine.QueryReflectionPaths(gameObject, ref listenerPosition, ref emitterPosition, indirectPathInfoArray, out numValidPaths) != AKRESULT.AK_Success)
|
||||
return;
|
||||
|
||||
for (var idxPath = (int)numValidPaths - 1; idxPath >= 0; --idxPath)
|
||||
{
|
||||
var path = indirectPathInfoArray[idxPath];
|
||||
var order = path.numReflections;
|
||||
|
||||
var colorLight = colorLightRed;
|
||||
var colorDark = colorDarkRed;
|
||||
|
||||
if (order == 1)
|
||||
{
|
||||
if (!firstOrder)
|
||||
continue;
|
||||
|
||||
colorLight = colorLightYellow;
|
||||
colorDark = colorDarkYellow;
|
||||
}
|
||||
else if (order == 2)
|
||||
{
|
||||
if (!secondOrder)
|
||||
continue;
|
||||
|
||||
colorLight = colorLightOrange;
|
||||
colorDark = colorDarkOrange;
|
||||
}
|
||||
else if (order > 2 && !higherOrder)
|
||||
continue;
|
||||
|
||||
var listenerPt = listenerPosition;
|
||||
|
||||
for (var idxSeg = (int)path.numPathPoints - 1; idxSeg >= 0; --idxSeg)
|
||||
{
|
||||
var pt = path.GetPathPoint((uint)idxSeg);
|
||||
|
||||
UnityEngine.Debug.DrawLine(listenerPt, pt, path.isOccluded ? colorLightGrey : colorLight);
|
||||
|
||||
UnityEngine.Gizmos.color = path.isOccluded ? colorLightGrey : colorLight;
|
||||
UnityEngine.Gizmos.DrawWireSphere(pt, radiusSphere / 2 / order);
|
||||
|
||||
if (!path.isOccluded)
|
||||
{
|
||||
var surface = path.GetAcousticSurface((uint)idxSeg);
|
||||
DrawLabelInFrontOfCam(pt, surface.strName, 100000, colorDark);
|
||||
}
|
||||
|
||||
float dfrnAmount = path.GetDiffraction((uint)idxSeg);
|
||||
if (dfrnAmount > 0)
|
||||
{
|
||||
string dfrnAmountStr = dfrnAmount.ToString("0.#%");
|
||||
DrawLabelInFrontOfCam(pt, dfrnAmountStr, 100000, colorDark);
|
||||
}
|
||||
|
||||
listenerPt = pt;
|
||||
}
|
||||
|
||||
if (!path.isOccluded)
|
||||
{
|
||||
// Finally the last path segment towards the emitter.
|
||||
UnityEngine.Debug.DrawLine(listenerPt, emitterPosition, path.isOccluded ? colorLightGrey : colorLight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DebugDrawDiffraction(UnityEngine.GameObject gameObject)
|
||||
{
|
||||
var listenerPosition = UnityEngine.Vector3.zero;
|
||||
var emitterPosition = UnityEngine.Vector3.zero;
|
||||
uint numValidPaths = (uint)diffractionPathInfoArray.Count();
|
||||
if (AkSoundEngine.QueryDiffractionPaths(gameObject, ref listenerPosition, ref emitterPosition, diffractionPathInfoArray, out numValidPaths) != AKRESULT.AK_Success)
|
||||
return;
|
||||
|
||||
for (var idxPath = (int)numValidPaths - 1; idxPath >= 0; --idxPath)
|
||||
{
|
||||
var path = diffractionPathInfoArray[idxPath];
|
||||
if (path.nodeCount <= 0)
|
||||
continue;
|
||||
|
||||
var prevPt = listenerPosition;
|
||||
|
||||
for (var idxSeg = 0; idxSeg < (int)path.nodeCount; ++idxSeg)
|
||||
{
|
||||
var pt = path.GetNodes((uint)idxSeg);
|
||||
UnityEngine.Debug.DrawLine(prevPt, pt, colorGreen);
|
||||
|
||||
float angle = path.GetAngles((uint)idxSeg) / UnityEngine.Mathf.PI;
|
||||
if (angle > 0)
|
||||
{
|
||||
string angleStr = angle.ToString("0.#%");
|
||||
DrawLabelInFrontOfCam(pt, angleStr, 100000, colorGreen);
|
||||
}
|
||||
|
||||
prevPt = pt;
|
||||
}
|
||||
|
||||
UnityEngine.Debug.DrawLine(prevPt, emitterPosition, colorGreen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static DebugDrawData debugDrawData = null;
|
||||
|
||||
private static void DrawLabelInFrontOfCam(UnityEngine.Vector3 position, string name, float distance, UnityEngine.Color c)
|
||||
{
|
||||
var style = new UnityEngine.GUIStyle();
|
||||
var oncam = UnityEngine.Camera.current.WorldToScreenPoint(position);
|
||||
|
||||
if (oncam.x >= 0 && oncam.x <= UnityEngine.Camera.current.pixelWidth && oncam.y >= 0 &&
|
||||
oncam.y <= UnityEngine.Camera.current.pixelHeight && oncam.z > 0 && oncam.z < distance)
|
||||
{
|
||||
style.normal.textColor = c;
|
||||
UnityEditor.Handles.Label(position, name, style);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 114c31abbe4bbf947afdba0ae901ecb0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
210
Assets/Wwise/Deployment/Components/AkSpatialAudioEmitter.cs
Normal file
210
Assets/Wwise/Deployment/Components/AkSpatialAudioEmitter.cs
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
///@brief (DEPRECATED) This script is deprecated as of 2019.2. Early reflections, Diffraction and Room Reverb can all be enabled per sound in the Sound Property Editor of the Authoring.
|
||||
/// @details Some functionalities were moved to different components. See the AkEarlyReflections and AkSpatialAudioDebugDraw components for more details.
|
||||
public class AkSpatialAudioEmitter : UnityEngine.MonoBehaviour
|
||||
#if UNITY_EDITOR
|
||||
, AK.Wwise.IMigratable
|
||||
#endif
|
||||
{
|
||||
[UnityEngine.Header("Early Reflections")]
|
||||
[UnityEngine.Tooltip("(DEPRECATED) As of 2019.2, the early reflections auxiliary bus can be set per sound, in the Authoring tool, or per game object, with the AkEarlyReflections component.")]
|
||||
/// (DEPRECATED) As of 2019.2, the early reflections auxiliary bus can be set per sound, in the Authoring tool, or per game object, with the AkEarlyReflections component.
|
||||
public AK.Wwise.AuxBus reflectAuxBus = new AK.Wwise.AuxBus();
|
||||
[UnityEngine.Tooltip("(DEPRECATED) As of 2019.2, the Reflection Max Path Length is set by the sound's Attenuation Max Distance value in the Authoring tool.")]
|
||||
/// (DEPRECATED) As of 2019.2, the Reflection Max Path Length is set by the sound's Attenuation Max Distance value in the Authoring tool.
|
||||
public float reflectionMaxPathLength = 1000;
|
||||
[UnityEngine.Range(0, 1)]
|
||||
[UnityEngine.Tooltip("(DEPRECATED) As of 2019.2, the early reflections send volume can be set per sound, in the Authoring tool, or for all sunds playing on a game object, with the AkEarlyReflections component.")]
|
||||
/// (DEPRECATED) As of 2019.2, the early reflections send volume can be set per sound, in the Authoring tool, or for all sunds playing on a game object, with the AkEarlyReflections component.
|
||||
public float reflectionsAuxBusGain = 1;
|
||||
[UnityEngine.Tooltip("(DEPRECATED) As of 2019.2, the Reflection Order is set in the Spatial Audio Initialization Settings.")]
|
||||
/// (DEPRECATED) As of 2019.2, the Reflection Order is set in the Spatial Audio Initialization Settings.
|
||||
public uint reflectionsOrder = 1;
|
||||
|
||||
[UnityEngine.Header("Rooms")]
|
||||
[UnityEngine.Tooltip("(DEPRECATED) As of 2019.2, the Room Reverb Aux Bus Gain is set by the Game-Defined Auxiliary Sends Volume in the Sound Property Editor in the Authoring tool.")]
|
||||
/// (DEPRECATED) As of 2019.2, the Room Reverb Aux Bus Gain is set by the Game-Defined Auxiliary Sends Volume in the Sound Property Editor in the Authoring tool.
|
||||
public float roomReverbAuxBusGain = 1;
|
||||
|
||||
[UnityEngine.Header("Geometric Diffraction")]
|
||||
[UnityEngine.Tooltip("(DEPRECATED) As of 2019.2, diffraction is enabled in the Sound Property Editor in the Authoring tool.")]
|
||||
/// (DEPRECATED) As of 2019.2, diffraction is enabled in the Sound Property Editor in the Authoring tool.
|
||||
public uint diffractionMaxEdges = 0;
|
||||
[UnityEngine.Tooltip("(DEPRECATED) As of 2019.2, diffraction is enabled in the Sound Property Editor in the Authoring tool.")]
|
||||
/// (DEPRECATED) As of 2019.2, diffraction is enabled in the Sound Property Editor in the Authoring tool.
|
||||
public uint diffractionMaxPaths = 0;
|
||||
[UnityEngine.Tooltip("(DEPRECATED) As of 2019.2, diffraction is enabled in the Sound Property Editor in the Authoring tool.")]
|
||||
/// (DEPRECATED) As of 2019.2, diffraction is enabled in the Sound Property Editor in the Authoring tool.
|
||||
public uint diffractionMaxPathLength = 0;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEngine.Header("Debug Draw")]
|
||||
|
||||
[UnityEngine.Tooltip("(DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component.")]
|
||||
/// (DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component.
|
||||
public bool drawFirstOrderReflections = false;
|
||||
[UnityEngine.Tooltip("(DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component.")]
|
||||
/// (DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component.
|
||||
public bool drawSecondOrderReflections = false;
|
||||
[UnityEngine.Tooltip("(DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component.")]
|
||||
/// (DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component.
|
||||
public bool drawHigherOrderReflections = false;
|
||||
[UnityEngine.Tooltip("(DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component.")]
|
||||
/// (DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component.
|
||||
public bool drawDiffractionPaths = false;
|
||||
|
||||
[UnityEditor.CustomEditor(typeof(AkSpatialAudioEmitter))]
|
||||
[UnityEditor.CanEditMultipleObjects]
|
||||
private class Editor : UnityEditor.Editor
|
||||
{
|
||||
private UnityEditor.SerializedProperty reflectAuxBus;
|
||||
private UnityEditor.SerializedProperty reflectionMaxPathLength;
|
||||
private UnityEditor.SerializedProperty reflectionsAuxBusGain;
|
||||
private UnityEditor.SerializedProperty reflectionsOrder;
|
||||
|
||||
private UnityEditor.SerializedProperty roomReverbAuxBusGain;
|
||||
|
||||
private UnityEditor.SerializedProperty diffractionMaxEdges;
|
||||
private UnityEditor.SerializedProperty diffractionMaxPaths;
|
||||
private UnityEditor.SerializedProperty diffractionMaxPathLength;
|
||||
|
||||
private UnityEditor.SerializedProperty drawFirstOrderReflections;
|
||||
private UnityEditor.SerializedProperty drawSecondOrderReflections;
|
||||
private UnityEditor.SerializedProperty drawHigherOrderReflections;
|
||||
private UnityEditor.SerializedProperty drawDiffractionPaths;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
reflectAuxBus = serializedObject.FindProperty("reflectAuxBus");
|
||||
reflectionMaxPathLength = serializedObject.FindProperty("reflectionMaxPathLength");
|
||||
reflectionsAuxBusGain = serializedObject.FindProperty("reflectionsAuxBusGain");
|
||||
reflectionsOrder = serializedObject.FindProperty("reflectionsOrder");
|
||||
|
||||
roomReverbAuxBusGain = serializedObject.FindProperty("roomReverbAuxBusGain");
|
||||
|
||||
diffractionMaxEdges = serializedObject.FindProperty("diffractionMaxEdges");
|
||||
diffractionMaxPaths = serializedObject.FindProperty("diffractionMaxPaths");
|
||||
diffractionMaxPathLength = serializedObject.FindProperty("diffractionMaxPathLength");
|
||||
|
||||
drawFirstOrderReflections = serializedObject.FindProperty("drawFirstOrderReflections");
|
||||
drawSecondOrderReflections = serializedObject.FindProperty("drawSecondOrderReflections");
|
||||
drawHigherOrderReflections = serializedObject.FindProperty("drawHigherOrderReflections");
|
||||
drawDiffractionPaths = serializedObject.FindProperty("drawDiffractionPaths");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
var wasEnabled = UnityEngine.GUI.enabled;
|
||||
UnityEngine.GUI.enabled = false;
|
||||
|
||||
UnityEditor.EditorGUILayout.PropertyField(reflectAuxBus, new UnityEngine.GUIContent("Reflect Aux Bus", "(DEPRECATED) As of 2019.2, the early reflections auxiliary bus can be set per sound, in the Authoring tool, or per game object, with the AkEarlyReflections component."));
|
||||
UnityEditor.EditorGUILayout.PropertyField(reflectionMaxPathLength, new UnityEngine.GUIContent("Reflection Max Path Length", "(DEPRECATED) As of 2019.2, the Reflection Max Path Length is set by the sound's Attenuation Max Distance value in the Authoring tool."));
|
||||
UnityEditor.EditorGUILayout.PropertyField(reflectionsAuxBusGain, new UnityEngine.GUIContent("Reflections Aux Bus Gain", "(DEPRECATED) As of 2019.2, the early reflections send volume can be set per sound, in the Authoring tool, or for all sunds playing on a game object, with the AkEarlyReflections component."));
|
||||
UnityEditor.EditorGUILayout.PropertyField(reflectionsOrder, new UnityEngine.GUIContent("Reflections Order", "(DEPRECATED) As of 2019.2, the Reflection Order is set in the Spatial Audio Initialization Settings."));
|
||||
|
||||
UnityEditor.EditorGUILayout.PropertyField(roomReverbAuxBusGain, new UnityEngine.GUIContent("Room Reverb Aux Bus Gain", "(DEPRECATED) As of 2019.2, the Room Reverb Aux Bus Gain is set by the Game-Defined Auxiliary Sends Volume in the Sound Property Editor in the Authoring tool."));
|
||||
|
||||
UnityEditor.EditorGUILayout.PropertyField(diffractionMaxEdges, new UnityEngine.GUIContent("Diffraction Max Edges", "(DEPRECATED) As of 2019.2, diffraction is enabled in the Sound Property Editor in the Authoring tool."));
|
||||
UnityEditor.EditorGUILayout.PropertyField(diffractionMaxPaths, new UnityEngine.GUIContent("Diffraction Max Paths", "(DEPRECATED) As of 2019.2, diffraction is enabled in the Sound Property Editor in the Authoring tool."));
|
||||
UnityEditor.EditorGUILayout.PropertyField(diffractionMaxPathLength, new UnityEngine.GUIContent("Diffraction Max Path Length", "(DEPRECATED) As of 2019.2, diffraction is enabled in the Sound Property Editor in the Authoring tool."));
|
||||
|
||||
UnityEditor.EditorGUILayout.PropertyField(drawFirstOrderReflections, new UnityEngine.GUIContent("Draw First Order Reflections", "(DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component."));
|
||||
UnityEditor.EditorGUILayout.PropertyField(drawSecondOrderReflections, new UnityEngine.GUIContent("Draw Second Order Reflections", "(DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component."));
|
||||
UnityEditor.EditorGUILayout.PropertyField(drawHigherOrderReflections, new UnityEngine.GUIContent("Draw Higher Order Reflections", "(DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component."));
|
||||
UnityEditor.EditorGUILayout.PropertyField(drawDiffractionPaths, new UnityEngine.GUIContent("Draw Diffraction Paths", "(DEPRECATED) Spatial Audio Debug Drawing were moved to the new AkSpatialAudioDebugDraw component."));
|
||||
|
||||
UnityEngine.GUI.enabled = wasEnabled;
|
||||
|
||||
// button to add AkEarlyReflections
|
||||
bool bShowButton = false;
|
||||
foreach (var obj in targets)
|
||||
{
|
||||
AkSpatialAudioEmitter spatialAudioEmitter = obj as AkSpatialAudioEmitter;
|
||||
if (spatialAudioEmitter.gameObject.GetComponent<AkEarlyReflections>() == null)
|
||||
bShowButton = true;
|
||||
}
|
||||
|
||||
if (bShowButton)
|
||||
{
|
||||
UnityEngine.GUILayout.Space(UnityEditor.EditorGUIUtility.standardVerticalSpacing);
|
||||
|
||||
using (new UnityEditor.EditorGUILayout.VerticalScope("box"))
|
||||
{
|
||||
UnityEditor.EditorGUILayout.HelpBox(
|
||||
"If you want to keep setting Early Reflections per game object, consider adding an AkEarlyReflections component.",
|
||||
UnityEditor.MessageType.Warning);
|
||||
|
||||
if (UnityEngine.GUILayout.Button("Add AkEarlyReflections"))
|
||||
{
|
||||
foreach (var obj in targets)
|
||||
{
|
||||
AkSpatialAudioEmitter spatialAudioEmitter = obj as AkSpatialAudioEmitter;
|
||||
if (spatialAudioEmitter.gameObject.GetComponent<AkEarlyReflections>() == null)
|
||||
{
|
||||
var er = UnityEditor.Undo.AddComponent<AkEarlyReflections>(spatialAudioEmitter.gameObject);
|
||||
er.reflectionsAuxBus.ObjectReference = spatialAudioEmitter.reflectAuxBus.ObjectReference;
|
||||
er.reflectionsVolume = spatialAudioEmitter.reflectionsAuxBusGain;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// button to add AkSpatialAudioDebugDraw
|
||||
bShowButton = false;
|
||||
foreach (var obj in targets)
|
||||
{
|
||||
AkSpatialAudioEmitter spatialAudioEmitter = obj as AkSpatialAudioEmitter;
|
||||
if (spatialAudioEmitter.gameObject.GetComponent<AkSpatialAudioDebugDraw>() == null)
|
||||
bShowButton = true;
|
||||
}
|
||||
|
||||
if (bShowButton)
|
||||
{
|
||||
UnityEngine.GUILayout.Space(UnityEditor.EditorGUIUtility.standardVerticalSpacing);
|
||||
|
||||
using (new UnityEditor.EditorGUILayout.VerticalScope("box"))
|
||||
{
|
||||
UnityEditor.EditorGUILayout.HelpBox(
|
||||
"For debugging purposes, early reflection and diffraction paths can be shown in the scene with the AkSpatialAudioDebugDraw component.",
|
||||
UnityEditor.MessageType.Warning);
|
||||
|
||||
if (UnityEngine.GUILayout.Button("Add AkSpatialAudioDebugDraw"))
|
||||
{
|
||||
foreach (var obj in targets)
|
||||
{
|
||||
AkSpatialAudioEmitter spatialAudioEmitter = obj as AkSpatialAudioEmitter;
|
||||
if (spatialAudioEmitter.gameObject.GetComponent<AkSpatialAudioDebugDraw>() == null)
|
||||
{
|
||||
var dd = UnityEditor.Undo.AddComponent<AkSpatialAudioDebugDraw>(spatialAudioEmitter.gameObject);
|
||||
dd.drawFirstOrderReflections = spatialAudioEmitter.drawFirstOrderReflections;
|
||||
dd.drawSecondOrderReflections = spatialAudioEmitter.drawSecondOrderReflections;
|
||||
dd.drawHigherOrderReflections = spatialAudioEmitter.drawHigherOrderReflections;
|
||||
dd.drawDiffractionPaths = spatialAudioEmitter.drawDiffractionPaths;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
|
||||
#region WwiseMigration
|
||||
bool AK.Wwise.IMigratable.Migrate(UnityEditor.SerializedObject obj)
|
||||
{
|
||||
if (!AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.NewScriptableObjectFolder_v2019_2_0))
|
||||
return false;
|
||||
|
||||
UnityEditor.Undo.AddComponent<AkRoomAwareObject>(gameObject);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4831e9b5c3b18c546b3d082a5519fb71
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
137
Assets/Wwise/Deployment/Components/AkSpatialAudioListener.cs
Normal file
137
Assets/Wwise/Deployment/Components/AkSpatialAudioListener.cs
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
#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
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkSpatialAudioListener")]
|
||||
[UnityEngine.RequireComponent(typeof(AkAudioListener))]
|
||||
[UnityEngine.RequireComponent(typeof(AkRoomAwareObject))]
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
///@brief Add this script on the game object that represent a listener. This is normally added to the Camera object or the Player object, but can be added to any game object when implementing 3D busses. \c isDefaultListener determines whether the game object will be considered a default listener - a listener that automatically listens to all game objects that do not have listeners attached to their AkGameObjListenerList's.
|
||||
/// \sa
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__listeners.html" target="_blank">Integrating Listeners</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
public class AkSpatialAudioListener : UnityEngine.MonoBehaviour
|
||||
#if UNITY_EDITOR
|
||||
, AK.Wwise.IMigratable
|
||||
#endif
|
||||
{
|
||||
private static AkSpatialAudioListener s_SpatialAudioListener;
|
||||
private static readonly SpatialAudioListenerList spatialAudioListeners = new SpatialAudioListenerList();
|
||||
private AkAudioListener AkAudioListener;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the "single" spatial audio listener.
|
||||
/// </summary>
|
||||
public static AkAudioListener TheSpatialAudioListener
|
||||
{
|
||||
get { return s_SpatialAudioListener != null ? s_SpatialAudioListener.AkAudioListener : null; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the list of active Unity Game Objects that are designated to be spatial audio listeners.
|
||||
/// </summary>
|
||||
public static SpatialAudioListenerList SpatialAudioListeners
|
||||
{
|
||||
get { return spatialAudioListeners; }
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
AkAudioListener = GetComponent<AkAudioListener>();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
spatialAudioListeners.Add(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
spatialAudioListeners.Remove(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This class represents the list of active Unity Game Objects that are designated to be spatial audio listeners.
|
||||
/// Currently, only one spatial audio listener can be active at a time.
|
||||
/// </summary>
|
||||
public class SpatialAudioListenerList
|
||||
{
|
||||
private readonly System.Collections.Generic.List<AkSpatialAudioListener> listenerList =
|
||||
new System.Collections.Generic.List<AkSpatialAudioListener>();
|
||||
|
||||
public System.Collections.Generic.List<AkSpatialAudioListener> ListenerList
|
||||
{
|
||||
get { return listenerList; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Uniquely adds listeners to the list
|
||||
/// </summary>
|
||||
/// <param name="listener"></param>
|
||||
/// <returns></returns>
|
||||
public bool Add(AkSpatialAudioListener listener)
|
||||
{
|
||||
if (listener == null)
|
||||
return false;
|
||||
|
||||
if (listenerList.Contains(listener))
|
||||
return false;
|
||||
|
||||
listenerList.Add(listener);
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes listeners from the list
|
||||
/// </summary>
|
||||
/// <param name="listener"></param>
|
||||
/// <returns></returns>
|
||||
public bool Remove(AkSpatialAudioListener listener)
|
||||
{
|
||||
if (listener == null)
|
||||
return false;
|
||||
|
||||
if (!listenerList.Remove(listener))
|
||||
return false;
|
||||
|
||||
Refresh();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
if (ListenerList.Count == 1)
|
||||
{
|
||||
if (s_SpatialAudioListener != null)
|
||||
AkSoundEngine.UnregisterSpatialAudioListener(s_SpatialAudioListener.gameObject);
|
||||
|
||||
s_SpatialAudioListener = ListenerList[0];
|
||||
|
||||
AkSoundEngine.RegisterSpatialAudioListener(s_SpatialAudioListener.gameObject);
|
||||
}
|
||||
else if (ListenerList.Count == 0 && s_SpatialAudioListener != null)
|
||||
{
|
||||
AkSoundEngine.UnregisterSpatialAudioListener(s_SpatialAudioListener.gameObject);
|
||||
s_SpatialAudioListener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
#region WwiseMigration
|
||||
bool AK.Wwise.IMigratable.Migrate(UnityEditor.SerializedObject obj)
|
||||
{
|
||||
if (!AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.NewScriptableObjectFolder_v2019_2_0))
|
||||
return false;
|
||||
|
||||
UnityEditor.Undo.AddComponent<AkRoomAwareObject>(gameObject);
|
||||
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
#endif
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 257865e72e0784f478546aede851ca3e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
94
Assets/Wwise/Deployment/Components/AkState.cs
Normal file
94
Assets/Wwise/Deployment/Components/AkState.cs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkState")]
|
||||
[UnityEngine.DefaultExecutionOrder(-20)]
|
||||
/// @brief This will call \c AkSoundEngine.SetState() whenever the selected Unity event is triggered. For example this component could be set on a Unity collider to trigger when an object enters it.
|
||||
/// \sa
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__states.html" target="_blank">Integration Details - States</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
public class AkState : AkDragDropTriggerHandler
|
||||
#if UNITY_EDITOR
|
||||
, AK.Wwise.IMigratable
|
||||
#endif
|
||||
{
|
||||
public AK.Wwise.State data = new AK.Wwise.State();
|
||||
protected override AK.Wwise.BaseType WwiseType { get { return data; } }
|
||||
|
||||
public override void HandleEvent(UnityEngine.GameObject in_gameObject)
|
||||
{
|
||||
data.SetValue();
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public int valueID { get { return (int)(data == null ? AkSoundEngine.AK_INVALID_UNIQUE_ID : data.Id); } }
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public int groupID { get { return (int)(data == null ? AkSoundEngine.AK_INVALID_UNIQUE_ID : data.GroupId); } }
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public byte[] valueGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var objRef = data.ObjectReference;
|
||||
return !objRef ? null : objRef.Guid.ToByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public byte[] groupGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var objRef = data.GroupWwiseObjectReference;
|
||||
return !objRef ? null : objRef.Guid.ToByteArray();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WwiseMigration
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("valueID")]
|
||||
private int valueIdInternal;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("groupID")]
|
||||
private int groupIdInternal;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("valueGuid")]
|
||||
private byte[] valueGuidInternal;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("groupGuid")]
|
||||
private byte[] groupGuidInternal;
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
bool AK.Wwise.IMigratable.Migrate(UnityEditor.SerializedObject obj)
|
||||
{
|
||||
if (!AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.WwiseTypes_v2018_1_6))
|
||||
return false;
|
||||
|
||||
return AK.Wwise.TypeMigration.ProcessDoubleGuidType(obj.FindProperty("data.WwiseObjectReference"), WwiseObjectType.State,
|
||||
obj.FindProperty("valueGuidInternal"), obj.FindProperty("valueIdInternal"),
|
||||
obj.FindProperty("groupGuidInternal"), obj.FindProperty("groupIdInternal"));
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkState.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkState.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 99b3ab61e0f25f44ba5be56f14dd716e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
454
Assets/Wwise/Deployment/Components/AkSurfaceReflector.cs
Normal file
454
Assets/Wwise/Deployment/Components/AkSurfaceReflector.cs
Normal file
|
|
@ -0,0 +1,454 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkSurfaceReflector")]
|
||||
[UnityEngine.ExecuteInEditMode]
|
||||
///@brief This component converts the provided mesh into Spatial Audio Geometry.
|
||||
///@details This component takes a mesh as a parameter. The triangles of the mesh are sent to Spatial Audio by calling SpatialAudio::AddGeometrySet(). The triangles reflect sounds that have an associated early reflections bus. If diffraction is enabled on this component, spatial audio also finds edges on the provided mesh, which diffract sounds that are diffraction enabled.
|
||||
public class AkSurfaceReflector : UnityEngine.MonoBehaviour
|
||||
#if UNITY_EDITOR
|
||||
, AK.Wwise.IMigratable
|
||||
#endif
|
||||
{
|
||||
[UnityEngine.Tooltip("The mesh to send to Spatial Audio as a Geometry Set. If this GameObject has a MeshFilter component, you can leave this parameter to None to use the same mesh for Spatial Audio. Otherwise, this parameter lets you import a different mesh for Spatial Audio purposes. We recommend using a simplified mesh.")]
|
||||
/// The mesh to send to Spatial Audio as a Geometry Set. We recommend using a simplified mesh.
|
||||
public UnityEngine.Mesh Mesh;
|
||||
|
||||
[UnityEngine.Tooltip("The acoustic texture per submesh. The acoustic texture represents the surface of the geometry. An acoustic texture is a set of absorption levels that will filter the sound reflected from the geometry.")]
|
||||
/// The acoustic texture per submesh. The acoustic texture represents the surface of the geometry. An acoustic texture is a set of absorption levels that will filter the sound reflected from the geometry.
|
||||
public AK.Wwise.AcousticTexture[] AcousticTextures = new AK.Wwise.AcousticTexture[1];
|
||||
|
||||
[UnityEngine.Tooltip("The occlusion value per submesh. The occlusion value is a control value used to adjust sound parameters. Typically, a value of 1.0 represents fully occluded, and a value of 0.0 indicates that sound can be transmitted through the geometry. Default value : 1.0.")]
|
||||
[UnityEngine.Range(0, 1)]
|
||||
/// The occlusion value per submesh. The occlusion value is a control value used to adjust sound parameters. Typically, a value of 1.0 represents fully occluded, and a value of 0.0 indicates that sound can be transmitted through the geometry. Default value : 1.0.
|
||||
public float[] OcclusionValues = new[] { 1.0f };
|
||||
|
||||
[UnityEngine.Tooltip("Enable or disable geometric diffraction for this mesh.")]
|
||||
/// Switch to enable or disable geometric diffraction for this mesh.
|
||||
public bool EnableDiffraction = false;
|
||||
|
||||
[UnityEngine.Tooltip("Enable or disable geometric diffraction on boundary edges for this mesh. Boundary edges are edges that are connected to only one triangle.")]
|
||||
/// Switch to enable or disable geometric diffraction on boundary edges for this mesh. Boundary edges are edges that are connected to only one triangle.
|
||||
public bool EnableDiffractionOnBoundaryEdges = false;
|
||||
|
||||
[UnityEngine.Tooltip("Optional room with which this surface reflector is associated. It is recommended to associate geometry with a particular room if the geometry is fully contained within the room and the room does not share any geometry with any other rooms. Doing so reduces the search space for ray casting performed by reflection and diffraction calculations.")]
|
||||
/// Optional room with which this surface reflector is associated. It is recommended to associate geometry with a particular room if the geometry is fully contained within the room and the room does not share any geometry with any other rooms. Doing so reduces the search space for ray casting performed by reflection and diffraction calculations.
|
||||
public AkRoom AssociatedRoom = null;
|
||||
|
||||
private ulong GetID()
|
||||
{
|
||||
return (ulong)GetInstanceID();
|
||||
}
|
||||
|
||||
private static void SetGeometryFromMesh(
|
||||
UnityEngine.Mesh mesh,
|
||||
AK.Wwise.AcousticTexture[] acousticTextures,
|
||||
float[] occlusionValues,
|
||||
UnityEngine.Transform transform,
|
||||
ulong geometryID,
|
||||
ulong associatedRoomID,
|
||||
bool enableDiffraction,
|
||||
bool enableDiffractionOnBoundaryEdges,
|
||||
string name = "")
|
||||
{
|
||||
var vertices = mesh.vertices;
|
||||
|
||||
// Remove duplicate vertices
|
||||
var vertRemap = new int[vertices.Length];
|
||||
var uniqueVerts = new System.Collections.Generic.List<UnityEngine.Vector3>();
|
||||
var vertDict = new System.Collections.Generic.Dictionary<UnityEngine.Vector3, int>();
|
||||
|
||||
for (var v = 0; v < vertices.Length; ++v)
|
||||
{
|
||||
int vertIdx = 0;
|
||||
if (!vertDict.TryGetValue(vertices[v], out vertIdx))
|
||||
{
|
||||
vertIdx = uniqueVerts.Count;
|
||||
uniqueVerts.Add(vertices[v]);
|
||||
vertDict.Add(vertices[v], vertIdx);
|
||||
}
|
||||
vertRemap[v] = vertIdx;
|
||||
}
|
||||
|
||||
int vertexCount = uniqueVerts.Count;
|
||||
var vertexArray = new UnityEngine.Vector3[vertexCount];
|
||||
|
||||
for (var v = 0; v < vertexCount; ++v)
|
||||
{
|
||||
var point = transform.TransformPoint(uniqueVerts[v]);
|
||||
vertexArray[v].x = point.x;
|
||||
vertexArray[v].y = point.y;
|
||||
vertexArray[v].z = point.z;
|
||||
}
|
||||
|
||||
int surfaceCount = mesh.subMeshCount;
|
||||
|
||||
var numTriangles = mesh.triangles.Length / 3;
|
||||
if ((mesh.triangles.Length % 3) != 0)
|
||||
{
|
||||
UnityEngine.Debug.LogFormat("SetGeometryFromMesh({0}): Wrong number of triangles", mesh.name);
|
||||
}
|
||||
|
||||
using (var surfaceArray = new AkAcousticSurfaceArray(surfaceCount))
|
||||
using (var triangleArray = new AkTriangleArray(numTriangles))
|
||||
{
|
||||
int triangleArrayIdx = 0;
|
||||
|
||||
for (var s = 0; s < surfaceCount; ++s)
|
||||
{
|
||||
var surface = surfaceArray[s];
|
||||
var triangles = mesh.GetTriangles(s);
|
||||
var triangleCount = triangles.Length / 3;
|
||||
if ((triangles.Length % 3) != 0)
|
||||
{
|
||||
UnityEngine.Debug.LogFormat("SetGeometryFromMesh({0}): Wrong number of triangles in submesh {1}", mesh.name, s);
|
||||
}
|
||||
|
||||
AK.Wwise.AcousticTexture acousticTexture = null;
|
||||
float occlusionValue = 1.0f;
|
||||
|
||||
if (s < acousticTextures.Length)
|
||||
acousticTexture = acousticTextures[s];
|
||||
|
||||
if (s < occlusionValues.Length)
|
||||
occlusionValue = occlusionValues[s];
|
||||
|
||||
surface.textureID = acousticTexture == null ? AK.Wwise.AcousticTexture.InvalidId : acousticTexture.Id;
|
||||
surface.occlusion = occlusionValue;
|
||||
surface.strName = name + "_" + mesh.name + "_" + s;
|
||||
|
||||
for (var i = 0; i < triangleCount; ++i)
|
||||
{
|
||||
var triangle = triangleArray[triangleArrayIdx];
|
||||
|
||||
triangle.point0 = (ushort)vertRemap[triangles[3 * i + 0]];
|
||||
triangle.point1 = (ushort)vertRemap[triangles[3 * i + 1]];
|
||||
triangle.point2 = (ushort)vertRemap[triangles[3 * i + 2]];
|
||||
triangle.surface = (ushort)s;
|
||||
|
||||
if (triangle.point0 != triangle.point1 && triangle.point0 != triangle.point2 && triangle.point1 != triangle.point2)
|
||||
{
|
||||
++triangleArrayIdx;
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.LogFormat("SetGeometryFromMesh({0}): Skipped degenerate triangle({1}, {2}, {3}) in submesh {4}", mesh.name, 3 * i + 0, 3 * i + 1, 3 * i + 2, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (triangleArrayIdx > 0)
|
||||
{
|
||||
AkSoundEngine.SetGeometry(
|
||||
geometryID,
|
||||
triangleArray,
|
||||
(uint)triangleArrayIdx,
|
||||
vertexArray,
|
||||
(uint)vertexArray.Length,
|
||||
surfaceArray,
|
||||
(uint)surfaceArray.Count(),
|
||||
associatedRoomID,
|
||||
enableDiffraction,
|
||||
enableDiffractionOnBoundaryEdges);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.LogFormat("SetGeometry({0}): No valid triangle was found. Geometry was not set", mesh.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAssociatedRoom(AkRoom room)
|
||||
{
|
||||
if (AssociatedRoom != room)
|
||||
{
|
||||
AssociatedRoom = room;
|
||||
UpdateGeometry();
|
||||
if (AssociatedRoom != null)
|
||||
AkRoomManager.RegisterReflector(this);
|
||||
else
|
||||
AkRoomManager.UnregisterReflector(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sends the mesh's triangles and their acoustic texture to Spatial Audio
|
||||
/// </summary>
|
||||
public void SetGeometry()
|
||||
{
|
||||
if (!AkSoundEngine.IsInitialized())
|
||||
return;
|
||||
|
||||
if (Mesh == null)
|
||||
{
|
||||
UnityEngine.Debug.LogFormat("SetGeometry({0}): No mesh found!", gameObject.name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
SetGeometryFromMesh(
|
||||
Mesh,
|
||||
AcousticTextures,
|
||||
OcclusionValues,
|
||||
transform,
|
||||
GetID(),
|
||||
AkRoom.GetAkRoomID(AssociatedRoom && AssociatedRoom.enabled ? AssociatedRoom : null),
|
||||
EnableDiffraction,
|
||||
EnableDiffractionOnBoundaryEdges,
|
||||
name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the surface reflector's geometry in Spatial Audio.
|
||||
/// </summary>
|
||||
public void UpdateGeometry()
|
||||
{
|
||||
RemoveGeometry();
|
||||
SetGeometry();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the surface reflector's geometry from Spatial Audio.
|
||||
/// </summary>
|
||||
public void RemoveGeometry()
|
||||
{
|
||||
AkSoundEngine.RemoveGeometry(GetID());
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public static void RemoveGeometrySet(UnityEngine.MeshFilter meshFilter)
|
||||
{
|
||||
if (meshFilter != null)
|
||||
AkSoundEngine.RemoveGeometry(GetAkGeometrySetID(meshFilter));
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating)
|
||||
return;
|
||||
|
||||
var reference = AkUtilities.DragAndDropObjectReference;
|
||||
if (reference)
|
||||
{
|
||||
UnityEngine.GUIUtility.hotControl = 0;
|
||||
|
||||
if (AcousticTextures == null || AcousticTextures.Length < 1)
|
||||
AcousticTextures = new AK.Wwise.AcousticTexture[1];
|
||||
|
||||
if (AcousticTextures[0] == null)
|
||||
AcousticTextures[0] = new AK.Wwise.AcousticTexture();
|
||||
|
||||
AcousticTextures[0].ObjectReference = reference;
|
||||
}
|
||||
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (Mesh == null)
|
||||
{
|
||||
var meshFilter = GetComponent<UnityEngine.MeshFilter>();
|
||||
if (meshFilter != null)
|
||||
Mesh = meshFilter.sharedMesh;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating || !UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
SetGeometry();
|
||||
if (AssociatedRoom != null)
|
||||
AkRoomManager.RegisterReflector(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating || !UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
RemoveGeometry();
|
||||
AkRoomManager.UnregisterReflector(this);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEditor.CustomEditor(typeof(AkSurfaceReflector))]
|
||||
[UnityEditor.CanEditMultipleObjects]
|
||||
private class Editor : UnityEditor.Editor
|
||||
{
|
||||
private AkSurfaceReflector m_AkSurfaceReflector;
|
||||
|
||||
private UnityEditor.SerializedProperty Mesh;
|
||||
private UnityEditor.SerializedProperty AcousticTextures;
|
||||
private UnityEditor.SerializedProperty OcclusionValues;
|
||||
private UnityEditor.SerializedProperty EnableDiffraction;
|
||||
private UnityEditor.SerializedProperty EnableDiffractionOnBoundaryEdges;
|
||||
private UnityEditor.SerializedProperty AssociatedRoom;
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
m_AkSurfaceReflector = target as AkSurfaceReflector;
|
||||
|
||||
Mesh = serializedObject.FindProperty("Mesh");
|
||||
AcousticTextures = serializedObject.FindProperty("AcousticTextures");
|
||||
OcclusionValues = serializedObject.FindProperty("OcclusionValues");
|
||||
EnableDiffraction = serializedObject.FindProperty("EnableDiffraction");
|
||||
EnableDiffractionOnBoundaryEdges = serializedObject.FindProperty("EnableDiffractionOnBoundaryEdges");
|
||||
AssociatedRoom = serializedObject.FindProperty("AssociatedRoom");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
UnityEditor.EditorGUILayout.PropertyField(Mesh);
|
||||
|
||||
UnityEditor.EditorGUILayout.PropertyField(AcousticTextures, true);
|
||||
CheckArraySize(m_AkSurfaceReflector, m_AkSurfaceReflector.AcousticTextures.Length, "acoustic textures");
|
||||
|
||||
UnityEditor.EditorGUILayout.PropertyField(OcclusionValues, true);
|
||||
CheckArraySize(m_AkSurfaceReflector, m_AkSurfaceReflector.OcclusionValues.Length, "occlusion values");
|
||||
|
||||
UnityEditor.EditorGUILayout.PropertyField(EnableDiffraction);
|
||||
if (EnableDiffraction.boolValue)
|
||||
UnityEditor.EditorGUILayout.PropertyField(EnableDiffractionOnBoundaryEdges);
|
||||
|
||||
UnityEditor.EditorGUILayout.PropertyField(AssociatedRoom);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
public static void CheckArraySize(AkSurfaceReflector surfaceReflector, int length, string name)
|
||||
{
|
||||
if (surfaceReflector != null && surfaceReflector.Mesh != null)
|
||||
{
|
||||
int maxSize = surfaceReflector.Mesh.subMeshCount;
|
||||
|
||||
if (length > maxSize)
|
||||
{
|
||||
UnityEngine.GUILayout.Space(UnityEditor.EditorGUIUtility.standardVerticalSpacing);
|
||||
|
||||
using (new UnityEditor.EditorGUILayout.VerticalScope("box"))
|
||||
{
|
||||
UnityEditor.EditorGUILayout.HelpBox(
|
||||
"There are more " + name + " than the Mesh has submeshes. Additional ones will be ignored.",
|
||||
UnityEditor.MessageType.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#region Obsolete
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public static ulong GetAkGeometrySetID(UnityEngine.MeshFilter meshFilter)
|
||||
{
|
||||
return (ulong)meshFilter.GetInstanceID();
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public static void AddGeometrySet(AK.Wwise.AcousticTexture acousticTexture, UnityEngine.MeshFilter meshFilter, ulong roomID, bool enableDiffraction, bool enableDiffractionOnBoundaryEdges)
|
||||
{
|
||||
if (!AkSoundEngine.IsInitialized())
|
||||
return;
|
||||
|
||||
if (meshFilter == null)
|
||||
{
|
||||
UnityEngine.Debug.LogFormat("AddGeometrySet: No mesh found!");
|
||||
return;
|
||||
}
|
||||
|
||||
var AcousticTextures = new[] { acousticTexture };
|
||||
|
||||
var OcclusionValues = new[] { 1.0f };
|
||||
|
||||
SetGeometryFromMesh(
|
||||
meshFilter.sharedMesh,
|
||||
AcousticTextures,
|
||||
OcclusionValues,
|
||||
meshFilter.transform,
|
||||
GetAkGeometrySetID(meshFilter),
|
||||
roomID,
|
||||
enableDiffraction,
|
||||
enableDiffractionOnBoundaryEdges,
|
||||
meshFilter.name);
|
||||
}
|
||||
|
||||
// for migration purpose, have a single acoustic texture parameter as a setter
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_0)]
|
||||
public AK.Wwise.AcousticTexture AcousticTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
return (AcousticTextures == null || AcousticTextures.Length < 1) ? null : AcousticTextures[0];
|
||||
}
|
||||
set
|
||||
{
|
||||
var numAcousticTextures = (Mesh == null) ? 1 : Mesh.subMeshCount;
|
||||
if (AcousticTextures == null || AcousticTextures.Length < numAcousticTextures)
|
||||
AcousticTextures = new AK.Wwise.AcousticTexture[numAcousticTextures];
|
||||
|
||||
for (int i = 0; i < numAcousticTextures; ++i)
|
||||
AcousticTextures[i] = new AK.Wwise.AcousticTexture { WwiseObjectReference = value != null ? value.WwiseObjectReference : null };
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WwiseMigration
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("AcousticTexture")]
|
||||
private AK.Wwise.AcousticTexture AcousticTextureInternal = new AK.Wwise.AcousticTexture();
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
bool AK.Wwise.IMigratable.Migrate(UnityEditor.SerializedObject obj)
|
||||
{
|
||||
if (!AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.NewScriptableObjectFolder_v2019_2_0))
|
||||
return false;
|
||||
|
||||
var hasChanged = false;
|
||||
|
||||
var numAcousticTextures = 1;
|
||||
var meshProperty = obj.FindProperty("Mesh");
|
||||
if (meshProperty != null)
|
||||
{
|
||||
var meshFilter = GetComponent<UnityEngine.MeshFilter>();
|
||||
if (meshFilter)
|
||||
{
|
||||
var sharedMesh = meshFilter.sharedMesh;
|
||||
if (sharedMesh)
|
||||
{
|
||||
hasChanged = true;
|
||||
meshProperty.objectReferenceValue = sharedMesh;
|
||||
numAcousticTextures = sharedMesh.subMeshCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var oldwwiseObjRefProperty = obj.FindProperty("AcousticTextureInternal.WwiseObjectReference");
|
||||
if (oldwwiseObjRefProperty != null)
|
||||
{
|
||||
var objectReferenceValue = oldwwiseObjRefProperty.objectReferenceValue;
|
||||
if (objectReferenceValue != null)
|
||||
{
|
||||
hasChanged = true;
|
||||
var acousticTextures = obj.FindProperty("AcousticTextures");
|
||||
acousticTextures.arraySize = numAcousticTextures;
|
||||
for (int i = 0; i < numAcousticTextures; ++i)
|
||||
acousticTextures.GetArrayElementAtIndex(i).FindPropertyRelative("WwiseObjectReference").objectReferenceValue = objectReferenceValue;
|
||||
}
|
||||
}
|
||||
|
||||
return hasChanged;
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a3745e74c894cf44ab1f5e3fc85eea54
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
94
Assets/Wwise/Deployment/Components/AkSwitch.cs
Normal file
94
Assets/Wwise/Deployment/Components/AkSwitch.cs
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.AddComponentMenu("Wwise/AkSwitch")]
|
||||
[UnityEngine.DefaultExecutionOrder(-10)]
|
||||
/// @brief This will call <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=namespace_a_k_1_1_sound_engine_a9364c865ed62f4666f357822ae409855.html" target="_blank">AkSoundEngine.SetSwitch()</a> whenever the selected Unity event is triggered. For example, this component could be set on a Unity collider to trigger when an object enters it.
|
||||
/// \sa
|
||||
/// - <a href="https://www.audiokinetic.com/library/edge/?source=SDK&id=soundengine__switch.html" target="_blank">Integration Details - Switches</a> (Note: This is described in the Wwise SDK documentation.)
|
||||
public class AkSwitch : AkDragDropTriggerHandler
|
||||
#if UNITY_EDITOR
|
||||
, AK.Wwise.IMigratable
|
||||
#endif
|
||||
{
|
||||
public AK.Wwise.Switch data = new AK.Wwise.Switch();
|
||||
protected override AK.Wwise.BaseType WwiseType { get { return data; } }
|
||||
|
||||
public override void HandleEvent(UnityEngine.GameObject in_gameObject)
|
||||
{
|
||||
data.SetValue(useOtherObject && in_gameObject != null ? in_gameObject : gameObject);
|
||||
}
|
||||
|
||||
#region Obsolete
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public int valueID { get { return (int)(data == null ? AkSoundEngine.AK_INVALID_UNIQUE_ID : data.Id); } }
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public int groupID { get { return (int)(data == null ? AkSoundEngine.AK_INVALID_UNIQUE_ID : data.GroupId); } }
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public byte[] valueGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var objRef = data.ObjectReference;
|
||||
return !objRef ? null : objRef.Guid.ToByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2018_1_6)]
|
||||
public byte[] groupGuid
|
||||
{
|
||||
get
|
||||
{
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var objRef = data.GroupWwiseObjectReference;
|
||||
return !objRef ? null : objRef.Guid.ToByteArray();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region WwiseMigration
|
||||
#pragma warning disable 0414 // private field assigned but not used.
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("valueID")]
|
||||
private int valueIdInternal = (int)AkSoundEngine.AK_INVALID_UNIQUE_ID;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("groupID")]
|
||||
private int groupIdInternal = (int)AkSoundEngine.AK_INVALID_UNIQUE_ID;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("valueGuid")]
|
||||
private byte[] valueGuidInternal;
|
||||
[UnityEngine.HideInInspector]
|
||||
[UnityEngine.SerializeField]
|
||||
[UnityEngine.Serialization.FormerlySerializedAs("groupGuid")]
|
||||
private byte[] groupGuidInternal;
|
||||
#pragma warning restore 0414 // private field assigned but not used.
|
||||
|
||||
#if UNITY_EDITOR
|
||||
bool AK.Wwise.IMigratable.Migrate(UnityEditor.SerializedObject obj)
|
||||
{
|
||||
if (!AkUtilities.IsMigrationRequired(AkUtilities.MigrationStep.WwiseTypes_v2018_1_6))
|
||||
return false;
|
||||
|
||||
return AK.Wwise.TypeMigration.ProcessDoubleGuidType(obj.FindProperty("data.WwiseObjectReference"), WwiseObjectType.Switch,
|
||||
obj.FindProperty("valueGuidInternal"), obj.FindProperty("valueIdInternal"),
|
||||
obj.FindProperty("groupGuidInternal"), obj.FindProperty("groupIdInternal"));
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkSwitch.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkSwitch.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 94aa552a2efec3b43b78b28416c7a91c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
12
Assets/Wwise/Deployment/Components/AkTerminator.cs
Normal file
12
Assets/Wwise/Deployment/Components/AkTerminator.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2012 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[UnityEngine.DisallowMultipleComponent]
|
||||
public class AkTerminator : UnityEngine.MonoBehaviour
|
||||
{
|
||||
}
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkTerminator.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkTerminator.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7f59ececaab17294eb4b3fa30426bc72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
62
Assets/Wwise/Deployment/Components/AkTriggerBase.cs
Normal file
62
Assets/Wwise/Deployment/Components/AkTriggerBase.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/// @brief Base class for the generic triggering mechanism for Wwise Integration.
|
||||
/// All Wwise components will use this mechanism to drive their behavior.
|
||||
/// Derive from this class to add your own triggering condition, as described in \ref unity_add_triggers
|
||||
public abstract class AkTriggerBase : UnityEngine.MonoBehaviour
|
||||
{
|
||||
/// Delegate declaration for all Wwise Triggers.
|
||||
public delegate void Trigger(
|
||||
UnityEngine.GameObject in_gameObject ///< in_gameObject is used to pass "Collidee" objects when Colliders are used. Some components have the option "Use other object", this is the object they'll use.
|
||||
);
|
||||
|
||||
/// All components reacting to the trigger will be registered in this delegate.
|
||||
public Trigger triggerDelegate = null;
|
||||
|
||||
public static System.Collections.Generic.Dictionary<uint, string> GetAllDerivedTypes()
|
||||
{
|
||||
var derivedTypes = new System.Collections.Generic.Dictionary<uint, string>();
|
||||
|
||||
var baseType = typeof(AkTriggerBase);
|
||||
|
||||
#if UNITY_WSA && !UNITY_EDITOR
|
||||
var baseTypeInfo = System.Reflection.IntrospectionExtensions.GetTypeInfo(baseType);
|
||||
var typeInfos = baseTypeInfo.Assembly.DefinedTypes;
|
||||
|
||||
foreach (var typeInfo in typeInfos)
|
||||
{
|
||||
if (typeInfo.IsClass && (typeInfo.IsSubclassOf(baseType) || baseTypeInfo.IsAssignableFrom(typeInfo) && baseType != typeInfo.AsType()))
|
||||
{
|
||||
var typeName = typeInfo.Name;
|
||||
derivedTypes.Add(AkUtilities.ShortIDGenerator.Compute(typeName), typeName);
|
||||
}
|
||||
}
|
||||
#else
|
||||
var types = baseType.Assembly.GetTypes();
|
||||
|
||||
for (var i = 0; i < types.Length; i++)
|
||||
{
|
||||
if (types[i].IsClass &&
|
||||
(types[i].IsSubclassOf(baseType) || baseType.IsAssignableFrom(types[i]) && baseType != types[i]))
|
||||
{
|
||||
var typeName = types[i].Name;
|
||||
derivedTypes.Add(AkUtilities.ShortIDGenerator.Compute(typeName), typeName);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//Add the Awake, Start and Destroy triggers and build the displayed list.
|
||||
derivedTypes.Add(AkUtilities.ShortIDGenerator.Compute("Awake"), "Awake");
|
||||
derivedTypes.Add(AkUtilities.ShortIDGenerator.Compute("Start"), "Start");
|
||||
derivedTypes.Add(AkUtilities.ShortIDGenerator.Compute("Destroy"), "Destroy");
|
||||
|
||||
return derivedTypes;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkTriggerBase.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkTriggerBase.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 419c445312767f04da6b3c5212a07418
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public class AkTriggerCollisionEnter : AkTriggerBase
|
||||
{
|
||||
public UnityEngine.GameObject triggerObject = null;
|
||||
|
||||
private void OnCollisionEnter(UnityEngine.Collision in_other)
|
||||
{
|
||||
if (triggerDelegate != null && (triggerObject == null || triggerObject == in_other.gameObject))
|
||||
triggerDelegate(in_other.gameObject);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(UnityEngine.Collider in_other)
|
||||
{
|
||||
if (triggerDelegate != null && (triggerObject == null || triggerObject == in_other.gameObject))
|
||||
triggerDelegate(in_other.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7019647fb669bac48a729fd8c3342149
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Wwise/Deployment/Components/AkTriggerCollisionExit.cs
Normal file
18
Assets/Wwise/Deployment/Components/AkTriggerCollisionExit.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public class AkTriggerCollisionExit : AkTriggerBase
|
||||
{
|
||||
public UnityEngine.GameObject triggerObject = null;
|
||||
|
||||
private void OnCollisionExit(UnityEngine.Collision in_other)
|
||||
{
|
||||
if (triggerDelegate != null && (triggerObject == null || triggerObject == in_other.gameObject))
|
||||
triggerDelegate(in_other.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7855505801e40e64491a687fe5a90939
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Wwise/Deployment/Components/AkTriggerDisable.cs
Normal file
17
Assets/Wwise/Deployment/Components/AkTriggerDisable.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public class AkTriggerDisable : AkTriggerBase
|
||||
{
|
||||
private void OnDisable()
|
||||
{
|
||||
if (triggerDelegate != null)
|
||||
triggerDelegate(null);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkTriggerDisable.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkTriggerDisable.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 207e43f79e918e047b626dda69d96646
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/Wwise/Deployment/Components/AkTriggerEnable.cs
Normal file
13
Assets/Wwise/Deployment/Components/AkTriggerEnable.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
[System.Obsolete(AkSoundEngine.Deprecation_2019_2_2)]
|
||||
public class AkTriggerEnable : AkTriggerBase
|
||||
{
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkTriggerEnable.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkTriggerEnable.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ec1821531aa54b54b8d70bb45100ecca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Wwise/Deployment/Components/AkTriggerEnter.cs
Normal file
18
Assets/Wwise/Deployment/Components/AkTriggerEnter.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public class AkTriggerEnter : AkTriggerBase
|
||||
{
|
||||
public UnityEngine.GameObject triggerObject = null;
|
||||
|
||||
private void OnTriggerEnter(UnityEngine.Collider in_other)
|
||||
{
|
||||
if (triggerDelegate != null && (triggerObject == null || triggerObject == in_other.gameObject))
|
||||
triggerDelegate(in_other.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkTriggerEnter.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkTriggerEnter.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 996ff7da7303c51408d093f0adc26418
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/Wwise/Deployment/Components/AkTriggerExit.cs
Normal file
18
Assets/Wwise/Deployment/Components/AkTriggerExit.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public class AkTriggerExit : AkTriggerBase
|
||||
{
|
||||
public UnityEngine.GameObject triggerObject = null;
|
||||
|
||||
private void OnTriggerExit(UnityEngine.Collider in_other)
|
||||
{
|
||||
if (triggerDelegate != null && (triggerObject == null || triggerObject == in_other.gameObject))
|
||||
triggerDelegate(in_other.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkTriggerExit.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkTriggerExit.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b20ad1e45ce31a6449e1ed7c57631d8c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
176
Assets/Wwise/Deployment/Components/AkTriggerHandler.cs
Normal file
176
Assets/Wwise/Deployment/Components/AkTriggerHandler.cs
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public abstract class AkTriggerHandler : UnityEngine.MonoBehaviour
|
||||
{
|
||||
public const int AWAKE_TRIGGER_ID = 1151176110;
|
||||
public const int START_TRIGGER_ID = 1281810935;
|
||||
public const int DESTROY_TRIGGER_ID = unchecked((int)3936390293);
|
||||
public const int ON_ENABLE_TRIGGER_ID = -320808462;
|
||||
|
||||
///Since our mask is a 32 bits integer, we can't have more than 32 triggers
|
||||
public const int MAX_NB_TRIGGERS = 32;
|
||||
|
||||
///Will contain the types of all the triggers derived from AkTriggerBase at runtime
|
||||
public static System.Collections.Generic.Dictionary<uint, string> triggerTypes = AkTriggerBase.GetAllDerivedTypes();
|
||||
|
||||
private bool didDestroy;
|
||||
|
||||
///List containing the enabled triggers.
|
||||
public System.Collections.Generic.List<int> triggerList = new System.Collections.Generic.List<int> { START_TRIGGER_ID };
|
||||
|
||||
///This property is usefull only when used with colliders. When enabled, the target of the action will be the other colliding object. When disabled, it will be the current object.
|
||||
public bool useOtherObject = false;
|
||||
|
||||
public abstract void HandleEvent(UnityEngine.GameObject in_gameObject);
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
RegisterTriggers(triggerList, HandleEvent);
|
||||
}
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating)
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (triggerList.Contains(START_TRIGGER_ID))
|
||||
HandleEvent(null);
|
||||
}
|
||||
|
||||
protected virtual void OnDestroy()
|
||||
{
|
||||
if (!didDestroy)
|
||||
DoDestroy();
|
||||
}
|
||||
|
||||
public void DoDestroy()
|
||||
{
|
||||
UnregisterTriggers(triggerList, HandleEvent);
|
||||
didDestroy = true;
|
||||
}
|
||||
|
||||
protected void RegisterTriggers(System.Collections.Generic.List<int> in_triggerList, AkTriggerBase.Trigger in_delegate)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating)
|
||||
return;
|
||||
#endif
|
||||
|
||||
foreach (uint triggerID in in_triggerList)
|
||||
{
|
||||
switch (triggerID)
|
||||
{
|
||||
case AWAKE_TRIGGER_ID:
|
||||
case START_TRIGGER_ID:
|
||||
case unchecked((uint)DESTROY_TRIGGER_ID):
|
||||
case unchecked((uint)ON_ENABLE_TRIGGER_ID):
|
||||
continue;
|
||||
}
|
||||
|
||||
var triggerName = string.Empty;
|
||||
if (triggerTypes.TryGetValue(triggerID, out triggerName))
|
||||
{
|
||||
var trigger = (AkTriggerBase)GetComponent(System.Type.GetType(triggerName));
|
||||
if (trigger == null)
|
||||
trigger = (AkTriggerBase)gameObject.AddComponent(System.Type.GetType(triggerName));
|
||||
trigger.triggerDelegate += in_delegate;
|
||||
}
|
||||
}
|
||||
|
||||
if (in_triggerList.Contains(AWAKE_TRIGGER_ID))
|
||||
in_delegate(null);
|
||||
|
||||
if (in_triggerList.Contains(ON_ENABLE_TRIGGER_ID))
|
||||
in_delegate(null);
|
||||
}
|
||||
|
||||
protected void UnregisterTriggers(System.Collections.Generic.List<int> in_triggerList, AkTriggerBase.Trigger in_delegate)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating)
|
||||
return;
|
||||
#endif
|
||||
|
||||
foreach (uint triggerID in in_triggerList)
|
||||
{
|
||||
switch (triggerID)
|
||||
{
|
||||
case AWAKE_TRIGGER_ID:
|
||||
case START_TRIGGER_ID:
|
||||
case unchecked((uint)DESTROY_TRIGGER_ID):
|
||||
case unchecked((uint)ON_ENABLE_TRIGGER_ID):
|
||||
continue;
|
||||
}
|
||||
|
||||
var triggerName = string.Empty;
|
||||
if (triggerTypes.TryGetValue(triggerID, out triggerName))
|
||||
{
|
||||
var trigger = (AkTriggerBase)GetComponent(System.Type.GetType(triggerName));
|
||||
if (trigger != null)
|
||||
{
|
||||
trigger.triggerDelegate -= in_delegate;
|
||||
if (trigger.triggerDelegate == null)
|
||||
Destroy(trigger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (in_triggerList.Contains(DESTROY_TRIGGER_ID))
|
||||
in_delegate(null);
|
||||
}
|
||||
}
|
||||
|
||||
[UnityEngine.ExecuteInEditMode]
|
||||
public abstract class AkDragDropTriggerHandler : AkTriggerHandler
|
||||
{
|
||||
protected abstract AK.Wwise.BaseType WwiseType { get; }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating)
|
||||
return;
|
||||
|
||||
var reference = AkUtilities.DragAndDropObjectReference;
|
||||
if (reference)
|
||||
{
|
||||
UnityEngine.GUIUtility.hotControl = 0;
|
||||
WwiseType.ObjectReference = reference;
|
||||
}
|
||||
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
base.Awake();
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
base.Start();
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (UnityEditor.BuildPipeline.isBuildingPlayer || AkUtilities.IsMigrating || !UnityEditor.EditorApplication.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
|
||||
base.OnDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkTriggerHandler.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkTriggerHandler.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a0ca8fb3dc0eca6489e84aa65e5fabb2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Wwise/Deployment/Components/AkTriggerMouseDown.cs
Normal file
17
Assets/Wwise/Deployment/Components/AkTriggerMouseDown.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public class AkTriggerMouseDown : AkTriggerBase
|
||||
{
|
||||
private void OnMouseDown()
|
||||
{
|
||||
if (triggerDelegate != null)
|
||||
triggerDelegate(null);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 88a4aa679b763ec49b26fad846d6ef86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Wwise/Deployment/Components/AkTriggerMouseEnter.cs
Normal file
17
Assets/Wwise/Deployment/Components/AkTriggerMouseEnter.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public class AkTriggerMouseEnter : AkTriggerBase
|
||||
{
|
||||
private void OnMouseEnter()
|
||||
{
|
||||
if (triggerDelegate != null)
|
||||
triggerDelegate(null);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f5b351be85453d9429c156c5febd4d13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Wwise/Deployment/Components/AkTriggerMouseExit.cs
Normal file
17
Assets/Wwise/Deployment/Components/AkTriggerMouseExit.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public class AkTriggerMouseExit : AkTriggerBase
|
||||
{
|
||||
private void OnMouseExit()
|
||||
{
|
||||
if (triggerDelegate != null)
|
||||
triggerDelegate(null);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d7d7e329b504e114cbeeaf7564eaade2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Wwise/Deployment/Components/AkTriggerMouseUp.cs
Normal file
17
Assets/Wwise/Deployment/Components/AkTriggerMouseUp.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (c) 2014 Audiokinetic Inc. / All Rights Reserved
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
public class AkTriggerMouseUp : AkTriggerBase
|
||||
{
|
||||
private void OnMouseUp()
|
||||
{
|
||||
if (triggerDelegate != null)
|
||||
triggerDelegate(null);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if ! (UNITY_DASHBOARD_WIDGET || UNITY_WEBPLAYER || UNITY_WII || UNITY_WIIU || UNITY_NACL || UNITY_FLASH || UNITY_BLACKBERRY) // Disable under unsupported platforms.
|
||||
11
Assets/Wwise/Deployment/Components/AkTriggerMouseUp.cs.meta
Normal file
11
Assets/Wwise/Deployment/Components/AkTriggerMouseUp.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f71dc4e8f953d0c4395d8c1854c174e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Reference in a new issue