From a50c21cf367d87526851b812ae919da630c594a6 Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Wed, 9 Oct 2024 17:19:00 +0200 Subject: [PATCH] add audio volume and muted in game panel tab rmb menu --- Source/Editor/Windows/GameWindow.cs | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/Source/Editor/Windows/GameWindow.cs b/Source/Editor/Windows/GameWindow.cs index 56e4c4380..bf79d5281 100644 --- a/Source/Editor/Windows/GameWindow.cs +++ b/Source/Editor/Windows/GameWindow.cs @@ -23,6 +23,8 @@ namespace FlaxEditor.Windows private readonly GameRoot _guiRoot; private bool _showGUI = true; private bool _showDebugDraw = false; + private bool _audioMuted = false; + private float _audioVolume = 1; private bool _isMaximized = false, _isUnlockingMouse = false; private bool _isFloating = false, _isBorderless = false; private bool _cursorVisible = true; @@ -69,6 +71,35 @@ namespace FlaxEditor.Windows set => _showDebugDraw = value; } + + /// + /// Gets or set a value indicating whether Audio is muted. + /// + public bool AudioMuted + { + get => _audioMuted; + set + { + Audio.MasterVolume = value ? 0 : AudioVolume; + _audioMuted = value; + } + } + + /// + /// Gets or sets a value that set the audio volume. + /// + public float AudioVolume + { + get => _audioVolume; + set + { + if (!AudioMuted) + Audio.MasterVolume = value; + + _audioVolume = value; + } + } + /// /// Gets or sets a value indicating whether the game window is maximized (only in play mode). /// @@ -596,6 +627,24 @@ namespace FlaxEditor.Windows checkbox.StateChanged += x => ShowDebugDraw = x.Checked; } + menu.AddSeparator(); + + // Mute Audio + { + var button = menu.AddButton("Mute Audio"); + button.CloseMenuOnClick = false; + var checkbox = new CheckBox(140, 2, AudioMuted) { Parent = button }; + checkbox.StateChanged += x => AudioMuted = x.Checked; + } + + // Audio Volume + { + var button = menu.AddButton("Audio Volume"); + button.CloseMenuOnClick = false; + var slider = new FloatValueBox(1, 140, 2, 50, 0, 1) { Parent = button }; + slider.ValueChanged += () => AudioVolume = slider.Value; + } + menu.MinimumWidth = 200; menu.AddSeparator(); }