From 3c2bf306502e9c4a2b96de0edd863d9f11895faf Mon Sep 17 00:00:00 2001 From: NaoyaKohda Date: Fri, 3 Jan 2025 04:24:04 +0900 Subject: [PATCH] =?UTF-8?q?DmxRecorder=20=E3=82=92=20preset=20=E3=81=A8?= =?UTF-8?q?=E3=81=97=E3=81=A6=E4=BF=9D=E5=AD=98=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ArtNet/Editor/DmxRecorder/IconHelper.cs | 1 + .../Editor/DmxRecorder/PresetRecorder.cs | 48 +++++++++++++++++++ .../Editor/DmxRecorder/PresetRecorder.cs.meta | 3 ++ .../Editor/DmxRecorder/RecorderSettings.cs | 1 + .../Editor/DmxRecorder/RecorderWindow.cs | 14 ++++++ 5 files changed, 67 insertions(+) create mode 100644 Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs create mode 100644 Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs.meta diff --git a/Assets/ArtNet/Editor/DmxRecorder/IconHelper.cs b/Assets/ArtNet/Editor/DmxRecorder/IconHelper.cs index 4e0768a..d00c138 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/IconHelper.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/IconHelper.cs @@ -15,6 +15,7 @@ public static class IconHelper public static Texture PreMatQuad => Icon("PreMatQuad@2x", true); public static Texture PauseButton => Icon("PauseButton@2x", true); public static Texture FolderOpen => Icon("FolderOpened Icon"); + public static Texture PresetIcon => Icon("Preset.Context", true); internal static Texture Icon(string iconPath, bool provideDarkModel = false) { diff --git a/Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs b/Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs new file mode 100644 index 0000000..3bb5d06 --- /dev/null +++ b/Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs @@ -0,0 +1,48 @@ +using System; +using UnityEditor; +using UnityEditor.Presets; + +namespace ArtNet.Editor.DmxRecorder +{ + public class PresetRecorder : PresetSelectorReceiver + { + private RecorderSettings _target; + private Preset _initialValue; + private Action _onSelectionChanged; + private Action _onSelectionClosed; + + internal void Init(RecorderSettings target, Action onSelectionChanged = null, Action onSelectionClosed = null) + { + _onSelectionChanged = onSelectionChanged; + _onSelectionClosed = onSelectionClosed; + _target = target; + _initialValue = new Preset(target); + } + + public override void OnSelectionChanged(Preset selection) + { + if (selection != null) + { + Undo.RecordObject(_target, "Apply Preset " + selection.name); + selection.ApplyTo(_target); + } + else + { + Undo.RecordObject(_target, "Cancel Preset"); + _initialValue.ApplyTo(_target); + } + + _onSelectionChanged?.Invoke(); + } + + public override void OnSelectionClosed(Preset selection) + { + OnSelectionChanged(selection); + + _target.OnAfterDuplicate(); + _onSelectionClosed?.Invoke(); + + DestroyImmediate(this); + } + } +} diff --git a/Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs.meta b/Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs.meta new file mode 100644 index 0000000..d623586 --- /dev/null +++ b/Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 823782597ad947cfb92de450c5cae424 +timeCreated: 1735584963 \ No newline at end of file diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs index e6a9f97..5a1df83 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs @@ -87,5 +87,6 @@ internal virtual void OnValidate() protected virtual void OnBeforeSerialize() { } protected virtual void OnAfterDeserialize() { } + public virtual void OnAfterDuplicate() { } } } diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.cs b/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.cs index 1901fd8..41b8b32 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using UnityEditor; +using UnityEditor.Presets; using UnityEngine; using UnityEngine.UIElements; @@ -202,6 +203,19 @@ private void RecorderSettingsGUI() var recorderName = editor.target.GetType().Name; EditorGUILayout.LabelField("Recorder Type", ObjectNames.NicifyVariableName(recorderName)); + if (GUILayout.Button(IconHelper.PresetIcon, new GUIStyle("iconButton") { fixedWidth = 20f })) + { + var settings = editor.target as RecorderSettings; + + if (settings != null) + { + var presetReceiver = CreateInstance(); + presetReceiver.Init(settings, Repaint); + + PresetSelector.ShowSelector(settings, null, true, presetReceiver); + } + } + EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator();