Music & SFX

This commit is contained in:
Reinier Vens 2021-04-30 11:19:25 +01:00
commit d955c9da2f
50 changed files with 3099 additions and 2646 deletions

View file

@ -1234,7 +1234,7 @@ public class @AetheriaInput : IInputActionCollection, IDisposable
}
}
}
public PlayerActions Player => new PlayerActions(this);
public PlayerActions @Player => new PlayerActions(this);
// UI
private readonly InputActionMap m_UI;

View file

@ -240,9 +240,30 @@ public class WwiseSoundBankInspector : BaseInspector<uint, InspectableSoundBankA
using (new HorizontalScope())
{
GUILayout.Label(label, GUILayout.Width(width));
IEnumerable<WwiseMetaSoundBank> soundBanks = ActionGameManager.SoundBanksInfo.SoundBanks;
var item = parent as EquippableItemData;
if (item == null)
if (parent is EquippableItemData item)
{
if (item.Behaviors.Any(b => b is WeaponData))
soundBanks = soundBanks.Where(s => s.GetEvent(WeaponAudioEvent.Fire) != null);
if (item.Behaviors.Any(b => b is ChargedWeaponData))
soundBanks = soundBanks.Where(s => s.GetEvent(ChargedWeaponAudioEvent.Start) != null);
if (item.Behaviors.Any(b => b is ReactorData || b is ThrusterData || b is AetherDriveData))
soundBanks = soundBanks.Where(s =>
s.GetEvent(LoopingAudioEvent.Play) != null &&
s.GetEvent(LoopingAudioEvent.Stop) != null &&
s.GetParameter(SpecialAudioParameter.Intensity) != null);
}
else if (parent is Faction)
{
soundBanks = soundBanks.Where(s => s.ObjectPath.Contains("Music") &&
s.GetEvent(LoopingAudioEvent.Play) != null &&
s.GetEvent(LoopingAudioEvent.Stop) != null);
}
else
{
using (new HorizontalScope(GUI.skin.box))
{
@ -250,21 +271,7 @@ public class WwiseSoundBankInspector : BaseInspector<uint, InspectableSoundBankA
return value;
}
}
IEnumerable<WwiseMetaSoundBank> soundBanks = ActionGameManager.SoundBanksInfo.SoundBanks;
if (item.Behaviors.Any(b => b is WeaponData))
soundBanks = soundBanks.Where(s => s.GetEvent(WeaponAudioEvent.Fire) != null);
if (item.Behaviors.Any(b => b is ChargedWeaponData))
soundBanks = soundBanks.Where(s => s.GetEvent(ChargedWeaponAudioEvent.Start) != null);
if (item.Behaviors.Any(b => b is ReactorData || b is ThrusterData || b is AetherDriveData))
soundBanks = soundBanks.Where(s =>
s.GetEvent(LoopingAudioEvent.Play) != null &&
s.GetEvent(LoopingAudioEvent.Stop) != null &&
s.GetParameter(SpecialAudioParameter.Intensity) != null);
var soundBanksArray = soundBanks.ToArray();
if (soundBanksArray.Length==0)
@ -278,8 +285,10 @@ public class WwiseSoundBankInspector : BaseInspector<uint, InspectableSoundBankA
var selected = Array.FindIndex(soundBanksArray, o=>o.Id==value);
if (selected == -1) selected = 0;
else selected++;
value = soundBanksArray[Popup(selected, soundBanksArray.Select(p => p.ShortName).ToArray())].Id;
var selection = Popup(selected, soundBanksArray.Select(p => p.ShortName).Prepend("None").ToArray());
value = selection != 0 ? soundBanksArray[selection - 1].Id : 0;
return value;
}
}

View file

@ -52,6 +52,30 @@ public class ActionGameManager : MonoBehaviour
}
}
private static GameObject CurrentMusicGameObject;
private static uint CurrentMusicSoundbank;
public static void PlayMusic(uint soundBank, GameObject obj)
{
if (soundBank == CurrentMusicSoundbank) return;
if (CurrentMusicSoundbank != 0)
AkSoundEngine.PostEvent(SoundBanksInfo.GetSoundBank(CurrentMusicSoundbank)
.GetEvent(LoopingAudioEvent.Stop).Id, CurrentMusicGameObject);
LoadSoundbank(soundBank);
CurrentMusicGameObject = obj;
CurrentMusicSoundbank = soundBank;
AkSoundEngine.PostEvent(SoundBanksInfo.GetSoundBank(CurrentMusicSoundbank)
.GetEvent(LoopingAudioEvent.Play).Id, CurrentMusicGameObject);
}
public static void StopMusic()
{
if (CurrentMusicSoundbank != 0)
AkSoundEngine.PostEvent(SoundBanksInfo.GetSoundBank(CurrentMusicSoundbank)
.GetEvent(LoopingAudioEvent.Stop).Id, CurrentMusicGameObject);
CurrentMusicGameObject = null;
CurrentMusicSoundbank = 0;
}
private static CultCache _cultCache;
public static CultCache CultCache
@ -233,6 +257,13 @@ public class ActionGameManager : MonoBehaviour
private void OnDisable()
{
Input.Dispose();
var ambience = SoundBanksInfo.GetSoundBank(Settings.AmbienceSoundBank);
foreach (var stopEvent in ambience.IncludedEvents.Where(e => e.Name.EndsWith("_stop")))
{
AkSoundEngine.PostEvent(stopEvent.Id, gameObject);
}
StopMusic();
AkSoundEngine.UnregisterGameObj(gameObject);
ConsoleController.ClearCommands();
EntityInstance.ClearWeaponManagers();
}
@ -243,6 +274,13 @@ public class ActionGameManager : MonoBehaviour
EntityInstance.EffectManagerParent = EffectManagerParent;
AkSoundEngine.RegisterGameObj(gameObject);
ConsoleController.MessageReceiver = this;
var ambience = SoundBanksInfo.GetSoundBank(Settings.AmbienceSoundBank);
LoadSoundbank(ambience.Id);
foreach (var playEvent in ambience.IncludedEvents.Where(e => e.Name.EndsWith("_play")))
{
AkSoundEngine.PostEvent(playEvent.Id, gameObject);
}
ItemManager = new ItemManager(CultCache, Settings.GameplaySettings, Debug.Log);
ZoneRenderer.ItemManager = ItemManager;
@ -630,6 +668,7 @@ public class ActionGameManager : MonoBehaviour
sectorZone.Contents = new Zone(ItemManager, Settings.PlanetSettings, sectorZone.PackedContents, sectorZone);
}
Zone = sectorZone.Contents;
PlayMusic(MusicType.Overworld);
Zone.Log = s => Debug.Log($"Zone: {s}");
@ -939,6 +978,11 @@ public class ActionGameManager : MonoBehaviour
foreach (var group in _articulationGroups)
group.crosshair.gameObject.SetActive(true);
_shipSubscriptions.Add(CurrentEntity.TargetedByCount.Subscribe(count =>
{
PlayMusic(count > 0 ? MusicType.Combat : MusicType.Overworld);
}));
_shipSubscriptions.Add(CurrentEntity.Target.Subscribe(target =>
{
// Clear previous subscriptions related to currently targeted enemy
@ -1071,6 +1115,26 @@ public class ActionGameManager : MonoBehaviour
yield return CurrentEntity;
}
public void PlayMusic(MusicType type)
{
var soundbank = type switch
{
MusicType.Overworld => Zone.SectorZone.Owner?.OverworldMusic ?? 0,
MusicType.Combat => Zone.SectorZone.Owner?.CombatMusic ?? 0,
MusicType.Boss => Zone.SectorZone.Owner?.BossMusic ?? 0,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
if (soundbank == 0)
soundbank = type switch
{
MusicType.Overworld => SoundBanksInfo.GetSoundBank(Settings.DefaultOverworldSoundbank).Id,
MusicType.Combat => SoundBanksInfo.GetSoundBank(Settings.DefaultCombatSoundbank).Id,
MusicType.Boss => SoundBanksInfo.GetSoundBank(Settings.DefaultBossSoundbank).Id,
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
};
PlayMusic(soundbank, gameObject);
}
void Update()
{
if(!_paused)

View file

@ -469,6 +469,10 @@ public class EntityInstance : MonoBehaviour
public virtual void Update()
{
foreach (var (source, item) in _audioSources)
{
AkSoundEngine.SetObjectPosition(source, source.transform);
}
LocalSpace.localPosition = transform.localPosition;
if (_currentPing.transform)
{

View file

@ -10,6 +10,10 @@ using UnityEngine;
[CreateAssetMenu(fileName = "Sector Display Properties", menuName = "Aetheria/Sector Display Properties")]
public class GameSettings : ScriptableObject
{
public string DefaultOverworldSoundbank = "Overworld_Generic";
public string DefaultCombatSoundbank = "Combat_Generic";
public string DefaultBossSoundbank = "Boss_Metal";
public string AmbienceSoundBank = "Ambience";
public string StartingHullName = "Longinus";
public float PickupLifetime = 30;
public float LootDropProbability = .25f;

View file

@ -47,6 +47,15 @@ public class Faction : DatabaseEntry, INamedEntry
[InspectableDatabaseLink(typeof(Faction)), RangedFloat(0, 1), JsonProperty("allegiance"), Key(12)]
public Dictionary<Guid, float> Allegiance = new Dictionary<Guid, float>();
[InspectableSoundBank, JsonProperty("overworldMusic"), Key(13)]
public uint OverworldMusic;
[InspectableSoundBank, JsonProperty("combatMusic"), Key(14)]
public uint CombatMusic;
[InspectableSoundBank, JsonProperty("bossMusic"), Key(15)]
public uint BossMusic;
[IgnoreMember] public string EntryName
{

View file

@ -125,6 +125,8 @@ public abstract class Entity
public Subject<Unit> HeatstrokeDeath = new Subject<Unit>();
public Subject<Unit> HypothermiaRisk = new Subject<Unit>();
public Subject<Unit> HypothermiaDeath = new Subject<Unit>();
public Subject<Entity> TargetedBy = new Subject<Entity>();
public ReactiveProperty<int> TargetedByCount = new ReactiveProperty<int>(0);
public UniRx.IObservable<EquippedItem> ItemDestroyed;
public UniRx.IObservable<int2> HullArmorDepleted;
@ -193,6 +195,13 @@ public abstract class Entity
.Merge(HypothermiaDeath.Select(_ => CauseOfDeath.Hypothermia))
.Merge(ItemDestroyed.Where(i=>i.GetBehavior<Cockpit>()!=null).Select(_ => CauseOfDeath.CockpitDestroyed));
Target.Subscribe(entity => entity?.TargetedBy.OnNext(this));
TargetedBy.Subscribe(enemy =>
{
TargetedByCount.Value++;
enemy.Target.Where(t => t != this).Take(1).Subscribe(_ => TargetedByCount.Value--);
});
EntityInfoGathered.ObserveReplace().Subscribe(replace =>
{
if (replace.OldValue < ItemManager.GameplaySettings.TargetDetectionInfoThreshold &&

View file

@ -198,4 +198,11 @@ public enum LoopingAudioEvent
{
Play,
Stop
}
public enum MusicType
{
Overworld,
Combat,
Boss
}

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Unity.Mathematics;
using static Unity.Mathematics.math;
@ -44,7 +45,10 @@ public class LoadoutGenerator
public EntityPack GenerateShipLoadout(Predicate<HullData> hullFilter = null)
{
var hull = ItemManager.CreateInstance(RandomHull(HullType.Ship, hullFilter)) as EquippableItem;
var hullData = RandomHull(HullType.Ship, hullFilter);
var hull = ItemManager.CreateInstance(hullData) as EquippableItem;
if(hull==null)
ItemManager.Log("WHAT???");
var entity = new Ship(ItemManager, null, hull, ItemManager.GameplaySettings.DefaultEntitySettings);
entity.Faction = Faction;
OutfitEntity(entity);

View file

@ -15,12 +15,18 @@ public class WwiseMetaSoundBanksInfo
public WwiseMetaSoundBank[] SoundBanks;
private Dictionary<uint, WwiseMetaSoundBank> _soundBanks;
public WwiseMetaSoundBank GetSoundBank(uint id)
{
if (_soundBanks == null) _soundBanks = SoundBanks.ToDictionary(sb => sb.Id);
return _soundBanks[id];
}
private Dictionary<string, WwiseMetaSoundBank> _soundBankNames;
public WwiseMetaSoundBank GetSoundBank(string name)
{
if (_soundBankNames == null) _soundBankNames = SoundBanks.ToDictionary(sb => sb.ShortName);
return _soundBankNames[name];
}
}
[JsonObject]
@ -28,6 +34,7 @@ public class WwiseMetaSoundBank
{
public uint Id;
public string ShortName;
public string ObjectPath;
public WwiseMetaObject[] IncludedEvents;
public WwiseMetaObject[] GameParameters;

View file

@ -97,6 +97,7 @@ public class MainMenu : MonoBehaviour
_nextMenu.panel.AddButton("Continue",
() =>
{
ActionGameManager.IsTutorial = ActionGameManager.PlayerSettings.SavedRun.IsTutorial;
ActionGameManager.CurrentSector = new Sector(
ActionGameManager.CultCache,
ActionGameManager.PlayerSettings.SavedRun);