From bc0f61a78101a61c304fb9612e2ab138cba56ae2 Mon Sep 17 00:00:00 2001 From: Metious <71298690+Metious@users.noreply.github.com> Date: Sun, 10 Nov 2024 10:27:07 +0330 Subject: [PATCH] Slight refactoring --- Nautilus/Utility/AudioUtils.cs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Nautilus/Utility/AudioUtils.cs b/Nautilus/Utility/AudioUtils.cs index af1ef081f..8e4666aab 100644 --- a/Nautilus/Utility/AudioUtils.cs +++ b/Nautilus/Utility/AudioUtils.cs @@ -26,7 +26,7 @@ public static partial class AudioUtils /// For music, PDA voices and any 2D sounds that can have more than one instance at a time. /// public const MODE StandardSoundModes_Stream = StandardSoundModes_2D | MODE.CREATESTREAM; - + private static FMOD.System FMOD_System => RuntimeManager.CoreSystem; /// @@ -84,14 +84,8 @@ public static IEnumerable CreateSounds(IEnumerable soundPaths, MO public static bool TryPlaySound(Sound sound, string busPath, out Channel channel) { channel = default; - Bus bus = RuntimeManager.GetBus(busPath); - if (bus.getChannelGroup(out ChannelGroup channelGroup) != RESULT.OK || !channelGroup.hasHandle()) - { - bus.lockChannelGroup(); - } - return bus.getChannelGroup(out channelGroup) == RESULT.OK && - channelGroup.getPaused(out bool paused) == RESULT.OK && - FMOD_System.playSound(sound, channelGroup, paused, out channel) == RESULT.OK; + var bus = RuntimeManager.GetBus(busPath); + return TryPlaySound(sound, bus, out channel); } /// @@ -108,9 +102,17 @@ public static bool TryPlaySound(Sound sound, Bus bus, out Channel channel) { bus.lockChannelGroup(); } - return bus.getChannelGroup(out channelGroup) == RESULT.OK && + + var success = bus.getChannelGroup(out channelGroup) == RESULT.OK && channelGroup.getPaused(out bool paused) == RESULT.OK && FMOD_System.playSound(sound, channelGroup, paused, out channel) == RESULT.OK; + + if (!success) + { + return false; + } + + return true; } ///