Skip to content

Commit

Permalink
DmxRecorder を preset として保存できるようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
nasshu2916 committed Jan 2, 2025
1 parent a914b03 commit 3c2bf30
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions Assets/ArtNet/Editor/DmxRecorder/IconHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
48 changes: 48 additions & 0 deletions Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
3 changes: 3 additions & 0 deletions Assets/ArtNet/Editor/DmxRecorder/PresetRecorder.cs.meta

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

1 change: 1 addition & 0 deletions Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,6 @@ internal virtual void OnValidate()

protected virtual void OnBeforeSerialize() { }
protected virtual void OnAfterDeserialize() { }
public virtual void OnAfterDuplicate() { }
}
}
14 changes: 14 additions & 0 deletions Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.Presets;
using UnityEngine;
using UnityEngine.UIElements;

Expand Down Expand Up @@ -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<PresetRecorder>();
presetReceiver.Init(settings, Repaint);

PresetSelector.ShowSelector(settings, null, true, presetReceiver);
}
}

EditorGUILayout.EndHorizontal();
EditorGUILayout.Separator();

Expand Down

0 comments on commit 3c2bf30

Please sign in to comment.