Audio Integration
Associated equippable items with audio triggers and individual game objects Added event triggers for stopping sounds when entities are destroyed
This commit is contained in:
parent
d8127c2240
commit
d3a03bec6c
24 changed files with 591 additions and 283 deletions
|
|
@ -257,11 +257,12 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
if (length(wormhole.Position - CurrentEntity.Position.xz) < Settings.GameplaySettings.WormholeExitRadius)
|
||||
{
|
||||
var oldZone = Zone;
|
||||
ship.EnterWormhole(wormhole.Position);
|
||||
ship.OnEnteredWormhole += () =>
|
||||
{
|
||||
GenerateLevel(wormhole.Target);
|
||||
ship.ExitWormhole(ZoneRenderer.WormholeInstances.Keys.First().Position,
|
||||
ship.ExitWormhole(ZoneRenderer.WormholeInstances.Keys.First(w=>w.Target==Zone.SectorZone).Position,
|
||||
Settings.GameplaySettings.WormholeExitVelocity * ItemManager.Random.NextFloat2Direction());
|
||||
CurrentEntity.Zone = Zone;
|
||||
};
|
||||
|
|
@ -477,10 +478,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
if (CurrentEntity != null)
|
||||
{
|
||||
CurrentEntity.Deactivate();
|
||||
if (CurrentEntity.Zone != null)
|
||||
{
|
||||
CurrentEntity.Zone.Entities.Remove(CurrentEntity);
|
||||
}
|
||||
CurrentEntity.Zone?.Entities.Remove(CurrentEntity);
|
||||
CurrentEntity.Zone = Zone;
|
||||
Zone.Entities.Add(CurrentEntity);
|
||||
CurrentEntity.Activate();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public class EntityInstance : MonoBehaviour
|
|||
public ShieldManager Shield;
|
||||
public HullCollider[] HullColliders;
|
||||
|
||||
public Transform[] EquipmentHardpoints;
|
||||
public RadiatorHardpoint[] RadiatorHardpoints;
|
||||
public ThrusterHardpoint[] ThrusterHardpoints;
|
||||
public WeaponHardpoint[] WeaponHardpoints;
|
||||
|
|
@ -36,6 +37,9 @@ public class EntityInstance : MonoBehaviour
|
|||
private bool _unfadedElementsVisible = false;
|
||||
private float _fadeTime;
|
||||
|
||||
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>();
|
||||
|
||||
|
|
@ -195,6 +199,39 @@ public class EntityInstance : MonoBehaviour
|
|||
_constantWeaponManagers[data].StopFiring(item);
|
||||
}
|
||||
}
|
||||
|
||||
var hp = Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
if (hp != null && !string.IsNullOrEmpty(item.Data.SoundEffectTrigger))
|
||||
{
|
||||
if(hp.Type == HardpointType.Radiator)
|
||||
{
|
||||
var radiatorHardpoint = RadiatorHardpoints.FirstOrDefault(x => x.name == hp.Transform);
|
||||
if (radiatorHardpoint)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
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>();
|
||||
Barrels = new Dictionary<HardpointData, Transform[]>();
|
||||
|
|
@ -423,6 +460,23 @@ 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.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.ItemManager.CompoundQuality(r.Key.Item.EquippableItem), r.Value);
|
||||
}
|
||||
|
||||
if (_reactor.reactor != null)
|
||||
{
|
||||
_reactor.sfxSource.SetActive(_reactor.reactor.Item.Online.Value);
|
||||
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.ItemManager.CompoundQuality(_reactor.reactor.Item.EquippableItem), _reactor.sfxSource);
|
||||
}
|
||||
|
||||
foreach (var x in RadiatorMeshes)
|
||||
{
|
||||
|
|
@ -439,8 +493,19 @@ public class EntityInstance : MonoBehaviour
|
|||
transform.position = Entity.Position;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
foreach (var r in _radiatorSfx)
|
||||
{
|
||||
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);
|
||||
}
|
||||
foreach(var x in _subscriptions)
|
||||
x.Dispose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,16 @@ using UnityEngine;
|
|||
|
||||
public class ShipInstance : EntityInstance
|
||||
{
|
||||
public (Thruster effect, ParticleSystem system, float baseEmission)[] Particles;
|
||||
private class ThrusterInstance
|
||||
{
|
||||
public Thruster Thruster;
|
||||
public GameObject SfxSource;
|
||||
public ParticleSystem System;
|
||||
public float BaseEmission;
|
||||
public int MaxParticleCount;
|
||||
}
|
||||
|
||||
private ThrusterInstance[] _thrusters;
|
||||
|
||||
public Ship Ship { get; private set; }
|
||||
|
||||
|
|
@ -18,40 +27,52 @@ public class ShipInstance : EntityInstance
|
|||
return;
|
||||
}
|
||||
Ship = ship;
|
||||
Particles = ship.GetBehaviors<Thruster>()
|
||||
.Select<Thruster, (Thruster effect, ParticleSystem system, float baseEmission)>(x =>
|
||||
_thrusters = ship.GetBehaviors<Thruster>().Select(thruster =>
|
||||
{
|
||||
var effectData = (ThrusterData) x.Data;
|
||||
var effectData = (ThrusterData) thruster.Data;
|
||||
var particles = Instantiate(UnityHelpers.LoadAsset<ParticleSystem>(effectData.ParticlesPrefab), transform, false);
|
||||
var particlesShape = particles.shape;
|
||||
particlesShape.meshRenderer = ThrusterHardpoints
|
||||
.FirstOrDefault(t => t.name == x.Entity.Hardpoints[x.Item.Position.x, x.Item.Position.y].Transform)
|
||||
?.Emitter;
|
||||
return (x, particles, particles.emission.rateOverTimeMultiplier);
|
||||
var thrusterHardpoint = ThrusterHardpoints
|
||||
.FirstOrDefault(t => t.name == thruster.Entity.Hardpoints[thruster.Item.Position.x, thruster.Item.Position.y].Transform);
|
||||
particlesShape.meshRenderer = thrusterHardpoint?.Emitter;
|
||||
if (!string.IsNullOrEmpty(thruster.Item.Data.SoundEffectTrigger) && thrusterHardpoint != null)
|
||||
{
|
||||
AkSoundEngine.RegisterGameObj(thrusterHardpoint.gameObject);
|
||||
AkSoundEngine.PostEvent(thruster.Item.Data.SoundEffectTrigger, thrusterHardpoint.gameObject);
|
||||
}
|
||||
|
||||
return new ThrusterInstance
|
||||
{
|
||||
Thruster = thruster,
|
||||
SfxSource = thrusterHardpoint?.gameObject,
|
||||
System = particles,
|
||||
BaseEmission = particles.emission.rateOverTimeMultiplier,
|
||||
MaxParticleCount = 0
|
||||
};
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
foreach (var particle in Particles)
|
||||
foreach (var particle in _thrusters)
|
||||
{
|
||||
particle.system.gameObject.SetActive(false);
|
||||
particle.System.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ShowUnfadedElements()
|
||||
{
|
||||
base.ShowUnfadedElements();
|
||||
foreach (var particle in Particles)
|
||||
foreach (var particle in _thrusters)
|
||||
{
|
||||
particle.system.gameObject.SetActive(true);
|
||||
particle.System.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void HideUnfadedElements()
|
||||
{
|
||||
base.HideUnfadedElements();
|
||||
foreach (var particle in Particles)
|
||||
foreach (var particle in _thrusters)
|
||||
{
|
||||
particle.system.gameObject.SetActive(false);
|
||||
particle.System.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,14 +80,38 @@ public class ShipInstance : EntityInstance
|
|||
{
|
||||
base.Update();
|
||||
|
||||
foreach (var (effect, system, baseEmission) in Particles)
|
||||
foreach (var thrusterInstance in _thrusters)
|
||||
{
|
||||
var emissionModule = system.emission;
|
||||
var item = effect.Item.EquippableItem;
|
||||
var emissionModule = thrusterInstance.System.emission;
|
||||
var item = thrusterInstance.Thruster.Item.EquippableItem;
|
||||
var data = Entity.ItemManager.GetData(item);
|
||||
emissionModule.rateOverTimeMultiplier = baseEmission * effect.Axis * (item.Durability / data.Durability);
|
||||
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.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.ItemManager.CompoundQuality(thrusterInstance.Thruster.Item.EquippableItem), 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue