using System; using System.Collections.Generic; using UnityEngine; using AK.Wwise; using Wwise.Wooduan.Core; namespace Wwise.Wooduan.Components { public class AkSpotReflector : AkComponent { public AuxBus reflectAuxBus; public AcousticTexture acousticTexture; [Range(0, 1)] public float reflectionLevel = 1f; //[Range(0, 1)] //public float diffractionLevel = 1f; [Range(0, 4)] public float distanceScalingFactor = 1f; private ulong _roomID; private uint _imageSourceID; private AkImageSourceSettings _sourceSettings; private static readonly List _instances = new List(); private void OnEnable() { _instances.Add(this); var position = transform.position; var room = SpatialAudioManager.FindRoomAtPosition(position); _roomID = room ? room.GetID() : AkRoom.INVALID_ROOM_ID; _sourceSettings = new AkImageSourceSettings(); _sourceSettings.params_ = new AkImageSourceParams(position, distanceScalingFactor, reflectionLevel); // _sourceSettings.params_.sourcePosition = position; // _sourceSettings.params_.fLevel = reflectionLevel; // _sourceSettings.params_.fDiffraction = diffractionLevel; // _sourceSettings.params_.fDistanceScalingFactor = distanceScalingFactor; _sourceSettings.SetName(gameObject.name); if (acousticTexture != null) _sourceSettings.SetOneTexture(acousticTexture.Id); _imageSourceID = (uint) AkSoundEngine.GetAkGameObjectID(gameObject); } private void OnDisable() { _instances.Remove(this); } public static void SetSpotReflectors(AkGameObj emitter) { AkSoundEngine.ClearImageSources(AkSoundEngine.AK_INVALID_AUX_ID, emitter.gameObject); foreach (var reflector in _instances) { reflector.SetSpotReflector(emitter); } } private void SetSpotReflector(AkGameObj emitter) { if (reflectAuxBus == null) return; AkSoundEngine.SetImageSource(_imageSourceID, _sourceSettings, reflectAuxBus.Id, _roomID, emitter.gameObject); } private void OnDrawGizmos() { //throw new NotImplementedException(); } public override bool IsValid() { return reflectAuxBus.IsValid(); } } }