diff --git a/Source/Editor/CustomEditors/Dedicated/AudioSourceEditor.cs b/Source/Editor/CustomEditors/Dedicated/AudioSourceEditor.cs new file mode 100644 index 000000000..adbdb90c6 --- /dev/null +++ b/Source/Editor/CustomEditors/Dedicated/AudioSourceEditor.cs @@ -0,0 +1,69 @@ +// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. + +using System; +using FlaxEngine; +using FlaxEngine.GUI; + +namespace FlaxEditor.CustomEditors.Dedicated +{ + /// + /// Custom editor for . + /// + [CustomEditor(typeof(AudioSource)), DefaultEditor] + public class AudioSourceEditor : ActorEditor + { + private Label _infoLabel; + + /// + public override void Initialize(LayoutElementsContainer layout) + { + base.Initialize(layout); + + // Show playback options during simulation + if (Editor.IsPlayMode) + { + var playbackGroup = layout.Group("Playback"); + playbackGroup.Panel.Open(); + + _infoLabel = playbackGroup.Label(string.Empty).Label; + _infoLabel.AutoHeight = true; + + var grid = playbackGroup.CustomContainer(); + var gridControl = grid.CustomControl; + gridControl.ClipChildren = false; + gridControl.Height = Button.DefaultHeight; + gridControl.SlotsHorizontally = 3; + gridControl.SlotsVertically = 1; + grid.Button("Play").Button.Clicked += () => Foreach(x => x.Play()); + grid.Button("Pause").Button.Clicked += () => Foreach(x => x.Pause()); + grid.Button("Stop").Button.Clicked += () => Foreach(x => x.Stop()); + } + } + + /// + public override void Refresh() + { + base.Refresh(); + + if (_infoLabel != null) + { + var text = string.Empty; + foreach (var value in Values) + { + if (value is AudioSource audioSource && audioSource.Clip) + text += $"Time: {audioSource.Time:##0.0}s / {audioSource.Clip.Length:##0.0}s\n"; + } + _infoLabel.Text = text; + } + } + + private void Foreach(Action func) + { + foreach (var value in Values) + { + if (value is AudioSource audioSource) + func(audioSource); + } + } + } +} diff --git a/Source/Editor/CustomEditors/Dedicated/SceneAnimationPlayerEditor.cs b/Source/Editor/CustomEditors/Dedicated/SceneAnimationPlayerEditor.cs new file mode 100644 index 000000000..96da5662e --- /dev/null +++ b/Source/Editor/CustomEditors/Dedicated/SceneAnimationPlayerEditor.cs @@ -0,0 +1,69 @@ +// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. + +using System; +using FlaxEngine; +using FlaxEngine.GUI; + +namespace FlaxEditor.CustomEditors.Dedicated +{ + /// + /// Custom editor for . + /// + [CustomEditor(typeof(SceneAnimationPlayer)), DefaultEditor] + public class SceneAnimationPlayerEditor : ActorEditor + { + private Label _infoLabel; + + /// + public override void Initialize(LayoutElementsContainer layout) + { + base.Initialize(layout); + + // Show playback options during simulation + if (Editor.IsPlayMode) + { + var playbackGroup = layout.Group("Playback"); + playbackGroup.Panel.Open(); + + _infoLabel = playbackGroup.Label(string.Empty).Label; + _infoLabel.AutoHeight = true; + + var grid = playbackGroup.CustomContainer(); + var gridControl = grid.CustomControl; + gridControl.ClipChildren = false; + gridControl.Height = Button.DefaultHeight; + gridControl.SlotsHorizontally = 3; + gridControl.SlotsVertically = 1; + grid.Button("Play").Button.Clicked += () => Foreach(x => x.Play()); + grid.Button("Pause").Button.Clicked += () => Foreach(x => x.Pause()); + grid.Button("Stop").Button.Clicked += () => Foreach(x => x.Stop()); + } + } + + /// + public override void Refresh() + { + base.Refresh(); + + if (_infoLabel != null) + { + var text = string.Empty; + foreach (var value in Values) + { + if (value is SceneAnimationPlayer player && player.Animation) + text += $"Time: {player.Time:##0.0}s / {player.Animation.Duration:##0.0}s\n"; + } + _infoLabel.Text = text; + } + } + + private void Foreach(Action func) + { + foreach (var value in Values) + { + if (value is SceneAnimationPlayer player) + func(player); + } + } + } +}