Skip to content

Commit

Permalink
fix sound players ignoring volume
Browse files Browse the repository at this point in the history
slow down tutel random walk
  • Loading branch information
Govorunb committed Nov 1, 2023
1 parent 5e115cb commit daf6e52
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 26 deletions.
6 changes: 1 addition & 5 deletions SCHIZO/Resources/AssetBundles/Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@ namespace SCHIZO.Resources;

public static class Assets
{
private const int _rnd = -130073006;
private const int _rnd = -1185798419;

private static readonly UnityEngine.AssetBundle _a = ResourceManager.GetAssetBundle("assets");

public static T[] All<T>() where T : UnityEngine.Object => _a.LoadAllAssets<T>();
public static UnityEngine.Object[] All() => _a.LoadAllAssets();

// [System.Obsolete] public static SCHIZO._old.CustomCreatureData Old_Anneel_AnneelData = _a.LoadAsset<SCHIZO._old.CustomCreatureData>("Assets/_old/Anneel/Anneel data.asset");
public static SCHIZO.Sounds.Collections.SoundCollection Old_Credits_SNEasterEgg = _a.LoadAsset<SCHIZO.Sounds.Collections.SoundCollection>("Assets/_old/Credits/SN Easter Egg.asset");
public static SCHIZO.Items.Data.CloneItemData Gymbag_GymbagBZ = _a.LoadAsset<SCHIZO.Items.Data.CloneItemData>("Assets/Gymbag/Gymbag BZ.asset");
public static SCHIZO.Items.Data.CloneItemData Gymbag_GymbagSN = _a.LoadAsset<SCHIZO.Items.Data.CloneItemData>("Assets/Gymbag/Gymbag SN.asset");
public static UnityEngine.Texture2D Loading_Icon_LoadingIcon = _a.LoadAsset<UnityEngine.Texture2D>("Assets/Loading/Icon/loading icon.png");
public static SCHIZO.Options.Bool.ToggleModOption Options_DisableAllSounds = _a.LoadAsset<SCHIZO.Options.Bool.ToggleModOption>("Assets/Options/Disable all sounds.asset");
public static SCHIZO.Options.Bool.ToggleModOption Options_EnableAutomaticEvents = _a.LoadAsset<SCHIZO.Options.Bool.ToggleModOption>("Assets/Options/Enable automatic events.asset");
public static SCHIZO.Registering.ModRegistry Registry = _a.LoadAsset<SCHIZO.Registering.ModRegistry>("Assets/Registry.asset");
public static SCHIZO.Sounds.Collections.SoundCollection Tutel_Sounds_Ambient_TutelAmbient = _a.LoadAsset<SCHIZO.Sounds.Collections.SoundCollection>("Assets/Tutel/Sounds/Ambient/Tutel Ambient.asset");
public static SCHIZO.Sounds.Collections.CombinedSoundCollection Tutel_Sounds_GetCarried_CarryByErmshark = _a.LoadAsset<SCHIZO.Sounds.Collections.CombinedSoundCollection>("Assets/Tutel/Sounds/Get Carried/Carry by ermshark.asset");
public static SCHIZO.Sounds.Collections.CombinedSoundCollection Tutel_Sounds_GetCarried_PickupByErmshark = _a.LoadAsset<SCHIZO.Sounds.Collections.CombinedSoundCollection>("Assets/Tutel/Sounds/Get Carried/Pickup by ermshark.asset");
}
Binary file modified SCHIZO/Resources/AssetBundles/assets
Binary file not shown.
28 changes: 27 additions & 1 deletion SCHIZO/Sounds/FMODSoundCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ namespace SCHIZO.Sounds;

public sealed class FMODSoundCollection
{
private enum VCA
{
Master,
Music,
Voice,
Ambient
}
private static readonly Dictionary<string, FMODSoundCollection> _cache = new();

private readonly string _busName;
Expand Down Expand Up @@ -129,9 +136,28 @@ private void PlaySound(FMOD_CustomEmitter emitter = null)
}
else
{
// TODO: Play this sound using an Emitter or something (so that it changes based on volume)
CustomSoundHandler.TryPlayCustomSound(sound, out Channel channel);
channel.setVolume(GetVolumeFor(GetVCAForBus(_busName)));
channel.set3DLevel(0);
}
}

private static VCA GetVCAForBus(string bus)
{
if (bus.Contains("bus:/master/Music")) return VCA.Music;
if (bus.Contains("/all voice/")) return VCA.Voice;
if (bus.StartsWith("/SFX/")) return VCA.Ambient;
return VCA.Master;
}

private static float GetVolumeFor(VCA vca)
{
return vca switch
{
VCA.Music => SoundSystem.masterVolume * SoundSystem.musicVolume,
VCA.Voice => SoundSystem.masterVolume * SoundSystem.voiceVolume,
VCA.Ambient => SoundSystem.masterVolume * SoundSystem.ambientVolume,
_ => SoundSystem.masterVolume,
};
}
}
3 changes: 1 addition & 2 deletions SCHIZO/Sounds/Players/SoundPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ protected virtual void Awake()

public void Play(float delay = 0)
{
if (Is3D) soundCollection.Play(emitter, delay);
else soundCollection.Play2D(delay);
soundCollection.Play(emitter, delay);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
using SCHIZO.Utilities;
using UnityEngine;

namespace SCHIZO.Interop.Subnautica;

partial class _CaveCrawlerGravity : MonoBehaviour
namespace SCHIZO.Interop.Subnautica
{
[Foldout(STRINGS.COMPONENT_REFERENCES), Required] public _CaveCrawler caveCrawler;
[Foldout(STRINGS.COMPONENT_REFERENCES), Required, ExposedType("LiveMixin")] public MonoBehaviour liveMixin;
[Foldout(STRINGS.COMPONENT_REFERENCES), Required] public Rigidbody crawlerRigidbody;
partial class _CaveCrawlerGravity : MonoBehaviour
{
[Foldout(STRINGS.COMPONENT_REFERENCES), Required] public _CaveCrawler caveCrawler;
[Foldout(STRINGS.COMPONENT_REFERENCES), Required, ExposedType("LiveMixin")] public MonoBehaviour liveMixin;
[Foldout(STRINGS.COMPONENT_REFERENCES), Required] public Rigidbody crawlerRigidbody;
}
}
1 change: 0 additions & 1 deletion Unity/Assets/Scripts/SCHIZO/Loading/LoadingSoundPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ namespace SCHIZO.Loading
public sealed partial class LoadingSoundPlayer : SoundPlayer
{
protected override string DefaultBus => buses[PDA_VOICE];
protected override bool Is3D => false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ namespace SCHIZO.Sounds.Players
public sealed partial class HurtSoundPlayer : SoundPlayer
{
protected override string DefaultBus => buses[UNDERWATER_CREATURES];
protected override bool Is3D => true;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using JetBrains.Annotations;
using NaughtyAttributes;
using SCHIZO.Options.Float;
Expand All @@ -23,7 +23,6 @@ public partial class InventoryAmbientSoundPlayer : SoundPlayer
private MonoBehaviour pickupable;

protected override string DefaultBus => buses[PDA_VOICE];
protected override bool Is3D => false;

private bool Validate_pickupable() => !pickupable || pickupable.GetComponentsInChildren<InventoryAmbientSoundPlayer>().Contains(this);
}
Expand Down
4 changes: 1 addition & 3 deletions Unity/Assets/Scripts/SCHIZO/Sounds/Players/SoundPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ public abstract partial class SoundPlayer : MonoBehaviour
[SerializeField, Dropdown(nameof(buses)), ShowIf(nameof(NeedsBus)), UsedImplicitly]
protected string bus;

[SerializeField, Required, ShowIf(nameof(NeedsEmitter)), UsedImplicitly]
[SerializeField, Required("If unset, sounds will play in 2D on the player."), UsedImplicitly]
private _FMOD_CustomEmitter emitter;

protected abstract string DefaultBus { get; }
protected abstract bool Is3D { get; }

private bool NeedsBus => string.IsNullOrEmpty(DefaultBus);
private bool NeedsEmitter => Is3D;

[StaticHelpers.Cache]
private protected static readonly BetterDropdownList<string> buses = new BetterDropdownList<string>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ public sealed partial class WorldAmbientSoundPlayer : SoundPlayer
private MonoBehaviour constructable;

protected override string DefaultBus => null;
protected override bool Is3D => true;
}
}
2 changes: 1 addition & 1 deletion Unity/Assets/Tutel/Sounds/Ambient/Tutel Ambient.asset.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Unity/Assets/Tutel/Tutel.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ MonoBehaviour:
onSurfaceMovement: {fileID: 2945450220734416713}
updateTargetInterval: 5
updateTargetRandomInterval: 6
moveVelocity: 13
moveVelocity: 6
moveRadius: 7
moveOnWalls: 0
--- !u!114 &205571466966154798
Expand Down

0 comments on commit daf6e52

Please sign in to comment.