Wwise Audio Integration

This commit is contained in:
Reinier Vens 2021-04-30 06:39:57 +01:00
commit 7d67d7ec2c
72 changed files with 4551 additions and 11819 deletions

View file

@ -11,6 +11,7 @@ using Cinemachine;
using Ink;
using Ink.Runtime;
using MessagePack;
using Newtonsoft.Json;
using TMPro;
using UniRx;
using UnityEngine;
@ -36,6 +37,21 @@ public class ActionGameManager : MonoBehaviour
get => _gameDataDirectory ??= new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
}
private static WwiseMetaSoundBanksInfo _soundBanksInfo;
public static WwiseMetaSoundBanksInfo SoundBanksInfo => _soundBanksInfo ??=
JsonConvert.DeserializeObject<WwiseMetadataFile>(File.ReadAllText(Path.Combine(GameDataDirectory.FullName, "SoundbanksInfo.json")))
.SoundBanksInfo;
private static HashSet<uint> _loadedSoundBanks = new HashSet<uint>();
public static void LoadSoundbank(uint soundBank)
{
if (!_loadedSoundBanks.Contains(soundBank))
{
AkSoundEngine.LoadBank(SoundBanksInfo.GetSoundBank(soundBank).ShortName, out _);
_loadedSoundBanks.Add(soundBank);
}
}
private static CultCache _cultCache;
public static CultCache CultCache

View file

@ -42,9 +42,10 @@ public class EntityInstance : MonoBehaviour
private (Transform transform, MeshRenderer meshRenderer) _currentPing;
private float _pingBrightness;
private Sensor _sensor;
private (Reactor reactor, GameObject sfxSource) _reactor;
private Dictionary<Radiator, GameObject> _radiatorSfx = new Dictionary<Radiator, GameObject>();
private List<(GameObject source, EquippedItem item)> _audioSources = new List<(GameObject source, EquippedItem item)>();
// private (Reactor reactor, GameObject sfxSource) _reactor;
// private Dictionary<Radiator, GameObject> _radiatorSfx = new Dictionary<Radiator, GameObject>();
private static Dictionary<InstantWeaponData, InstantWeaponEffectManager> _instantWeaponManagers = new Dictionary<InstantWeaponData, InstantWeaponEffectManager>();
private static Dictionary<ConstantWeaponData, ConstantWeaponEffectManager> _constantWeaponManagers = new Dictionary<ConstantWeaponData, ConstantWeaponEffectManager>();
@ -231,36 +232,24 @@ public class EntityInstance : MonoBehaviour
}
var hp = Entity.Hardpoints[item.Position.x, item.Position.y];
if (hp != null && !string.IsNullOrEmpty(item.Data.SoundEffectTrigger))
if (hp != null && item.Data.SoundBank != 0)
{
if(hp.Type == HardpointType.Radiator)
var hardpointTransform = EquipmentHardpoints.FirstOrDefault(x => x.name == hp.Transform);
if (hardpointTransform != null)
{
var radiatorHardpoint = RadiatorHardpoints.FirstOrDefault(x => x.name == hp.Transform);
if (radiatorHardpoint)
var hardpointGameObject = hardpointTransform.gameObject;
_audioSources.Add((hardpointGameObject, item));
AkSoundEngine.RegisterGameObj(hardpointGameObject);
ActionGameManager.LoadSoundbank(item.Data.SoundBank);
_subscriptions.Add(item.AudioEvents.Subscribe(e=>AkSoundEngine.PostEvent(e, hardpointGameObject)));
_subscriptions.Add(item.AudioParameters.Subscribe(p=>AkSoundEngine.SetRTPCValue(p.id, p.v, hardpointGameObject)));
var soundBank = ActionGameManager.SoundBanksInfo.GetSoundBank(item.Data.SoundBank);
item.SoundBank = soundBank;
if (soundBank.GetEvent(LoopingAudioEvent.Play) != null && soundBank.GetEvent(ChargedWeaponAudioEvent.Start) == null)
{
var rad = item.GetBehavior<Radiator>();
if(rad != null && !string.IsNullOrEmpty(item.Data.SoundEffectTrigger))
{
AkSoundEngine.RegisterGameObj(radiatorHardpoint.gameObject);
AkSoundEngine.PostEvent(item.Data.SoundEffectTrigger, radiatorHardpoint.gameObject);
_radiatorSfx[rad] = radiatorHardpoint.gameObject;
}
AkSoundEngine.PostEvent(soundBank.GetEvent(LoopingAudioEvent.Play).Id, hardpointGameObject);
}
}
// if(hp.Type == HardpointType.Reactor)
// {
// var reactorHardpoint = EquipmentHardpoints.FirstOrDefault(x => x.name == hp.Transform);
// if (reactorHardpoint)
// {
// var reactor = item.GetBehavior<Reactor>();
// if( reactor != null && !string.IsNullOrEmpty(item.Data.SoundEffectTrigger) )
// {
// AkSoundEngine.RegisterGameObj(reactorHardpoint.gameObject);
// AkSoundEngine.PostEvent(item.Data.SoundEffectTrigger, reactorHardpoint.gameObject);
// _reactor = (reactor, reactorHardpoint.gameObject);
// }
// }
// }
}
}
RadiatorMeshes = new Dictionary<Radiator, MeshRenderer>();
@ -522,25 +511,6 @@ public class EntityInstance : MonoBehaviour
foreach(var material in _fadeMaterials) material.SetFloat("_Fade", _fade);
}
}
foreach (var r in _radiatorSfx)
{
r.Value.SetActive(r.Key.Item.Online.Value);
AkSoundEngine.SetObjectPosition(r.Value, r.Value.transform);
AkSoundEngine.SetRTPCValue("performance_durability", r.Key.Item.DurabilityPerformance, r.Value);
AkSoundEngine.SetRTPCValue("performance_thermal", r.Key.Item.ThermalPerformance, r.Value);
AkSoundEngine.SetRTPCValue("performance_quality", r.Key.Item.EquippableItem.Quality, r.Value);
}
// if (_reactor.reactor != null)
// {
// _reactor.sfxSource.SetActive(_reactor.reactor.Item.Online.Value);
// AkSoundEngine.SetObjectPosition(_reactor.sfxSource, _reactor.sfxSource.transform);
// AkSoundEngine.SetRTPCValue("reactor_load", _reactor.reactor.CurrentLoadRatio, _reactor.sfxSource);
// AkSoundEngine.SetRTPCValue("performance_durability", _reactor.reactor.Item.DurabilityPerformance, _reactor.sfxSource);
// AkSoundEngine.SetRTPCValue("performance_thermal", _reactor.reactor.Item.ThermalPerformance, _reactor.sfxSource);
// AkSoundEngine.SetRTPCValue("performance_quality", _reactor.reactor.Item.EquippableItem.Quality, _reactor.sfxSource);
// }
foreach (var x in RadiatorMeshes)
{
@ -560,16 +530,14 @@ public class EntityInstance : MonoBehaviour
public virtual void OnDestroy()
{
Destroy(LocalSpace.gameObject);
foreach (var r in _radiatorSfx)
foreach (var (source, item) in _audioSources)
{
AkSoundEngine.PostEvent($"{r.Key.Item.Data.SoundEffectTrigger}_stop", r.Value);
AkSoundEngine.UnregisterGameObj(r.Value);
}
if (_reactor.reactor != null)
{
AkSoundEngine.PostEvent($"{_reactor.reactor.Item.Data.SoundEffectTrigger}_stop", _reactor.sfxSource);
AkSoundEngine.UnregisterGameObj(_reactor.sfxSource);
var soundBank = ActionGameManager.SoundBanksInfo.GetSoundBank(item.Data.SoundBank);
if (soundBank.GetEvent(LoopingAudioEvent.Stop) != null)
{
AkSoundEngine.PostEvent(soundBank.GetEvent(LoopingAudioEvent.Stop).Id, source);
}
AkSoundEngine.UnregisterGameObj(source);
}
foreach(var x in _subscriptions)
x.Dispose();

View file

@ -10,7 +10,6 @@ public class ShipInstance : EntityInstance
private class ThrusterInstance
{
public Thruster Thruster;
public GameObject SfxSource;
public ParticleSystem System;
public float BaseEmission;
public int MaxParticleCount;
@ -53,7 +52,6 @@ public class ShipInstance : EntityInstance
return new ThrusterInstance
{
Thruster = thruster,
SfxSource = thrusterHardpoint?.gameObject,
System = particles,
BaseEmission = particles.emission.rateOverTimeMultiplier,
MaxParticleCount = 0
@ -99,31 +97,8 @@ public class ShipInstance : EntityInstance
var data = Entity.ItemManager.GetData(item);
thrusterInstance.MaxParticleCount = thrusterInstance.System.particleCount;
emissionModule.rateOverTimeMultiplier = thrusterInstance.BaseEmission * thrusterInstance.Thruster.Axis * (item.Durability / data.Durability);
// if (thrusterInstance.SfxSource)
// {
// var throttle = 0f;
// if (thrusterInstance.System.particleCount > 0)
// throttle = (float) thrusterInstance.System.particleCount / thrusterInstance.MaxParticleCount;
// AkSoundEngine.SetObjectPosition(thrusterInstance.SfxSource, thrusterInstance.SfxSource.transform);
// AkSoundEngine.SetRTPCValue("thruster_throttle", throttle, thrusterInstance.SfxSource);
// AkSoundEngine.SetRTPCValue("performance_durability", thrusterInstance.Thruster.Item.DurabilityPerformance, thrusterInstance.SfxSource);
// AkSoundEngine.SetRTPCValue("performance_thermal", thrusterInstance.Thruster.Item.ThermalPerformance, thrusterInstance.SfxSource);
// AkSoundEngine.SetRTPCValue("performance_quality", thrusterInstance.Thruster.Item.EquippableItem.Quality, thrusterInstance.SfxSource);
// }
}
transform.rotation = Ship.Rotation;
}
public override void OnDestroy()
{
foreach (var thrusterInstance in _thrusters)
{
if (thrusterInstance.SfxSource)
{
AkSoundEngine.PostEvent(thrusterInstance.Thruster.Item.Data.SoundEffectTrigger + "_stop", thrusterInstance.SfxSource);
AkSoundEngine.UnregisterGameObj(thrusterInstance.SfxSource);
}
}
}
}