From be7d5a63edb82014c1ad0c31fd997b4df4db4f92 Mon Sep 17 00:00:00 2001 From: NaoyaKohda Date: Wed, 20 Nov 2024 00:06:01 +0900 Subject: [PATCH 1/6] =?UTF-8?q?TargetedPropertyDrawer=20=E3=82=92=20DmxRec?= =?UTF-8?q?order=20=E5=81=B4=E3=81=AB=E7=A7=BB=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Input => DmxRecorder}/TargetedPropertyDrawer.cs | 2 +- .../Input => DmxRecorder}/TargetedPropertyDrawer.cs.meta | 0 .../UnityRecorder/Input/ArtNetInputSettingsPropertyDrawer.cs | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) rename Assets/ArtNet/Editor/{UnityRecorder/Input => DmxRecorder}/TargetedPropertyDrawer.cs (95%) rename Assets/ArtNet/Editor/{UnityRecorder/Input => DmxRecorder}/TargetedPropertyDrawer.cs.meta (100%) diff --git a/Assets/ArtNet/Editor/UnityRecorder/Input/TargetedPropertyDrawer.cs b/Assets/ArtNet/Editor/DmxRecorder/TargetedPropertyDrawer.cs similarity index 95% rename from Assets/ArtNet/Editor/UnityRecorder/Input/TargetedPropertyDrawer.cs rename to Assets/ArtNet/Editor/DmxRecorder/TargetedPropertyDrawer.cs index 9f514db..af88025 100644 --- a/Assets/ArtNet/Editor/UnityRecorder/Input/TargetedPropertyDrawer.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/TargetedPropertyDrawer.cs @@ -2,7 +2,7 @@ using UnityEditor; using UnityEngine; -namespace ArtNet.Editor.UnityRecorder.Input +namespace ArtNet.Editor.DmxRecorder { public class TargetedPropertyDrawer : PropertyDrawer where T : class { diff --git a/Assets/ArtNet/Editor/UnityRecorder/Input/TargetedPropertyDrawer.cs.meta b/Assets/ArtNet/Editor/DmxRecorder/TargetedPropertyDrawer.cs.meta similarity index 100% rename from Assets/ArtNet/Editor/UnityRecorder/Input/TargetedPropertyDrawer.cs.meta rename to Assets/ArtNet/Editor/DmxRecorder/TargetedPropertyDrawer.cs.meta diff --git a/Assets/ArtNet/Editor/UnityRecorder/Input/ArtNetInputSettingsPropertyDrawer.cs b/Assets/ArtNet/Editor/UnityRecorder/Input/ArtNetInputSettingsPropertyDrawer.cs index 3e99a25..18c6507 100644 --- a/Assets/ArtNet/Editor/UnityRecorder/Input/ArtNetInputSettingsPropertyDrawer.cs +++ b/Assets/ArtNet/Editor/UnityRecorder/Input/ArtNetInputSettingsPropertyDrawer.cs @@ -1,3 +1,4 @@ +using ArtNet.Editor.DmxRecorder; using UnityEditor; using UnityEngine; From f415dae417bc9ea6888ec65c789a8dcca8fdb80b Mon Sep 17 00:00:00 2001 From: NaoyaKohda Date: Wed, 20 Nov 2024 05:55:03 +0900 Subject: [PATCH 2/6] =?UTF-8?q?FileGenerator=20=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Editor/DmxRecorder/FileGenerator.cs | 187 ++++++++++++++++++ .../Editor/DmxRecorder/FileGenerator.cs.meta | 3 + .../Editor/DmxRecorder/FileGeneratorDrawer.cs | 148 ++++++++++++++ .../DmxRecorder/FileGeneratorDrawer.cs.meta | 3 + .../ArtNet/Editor/DmxRecorder/IconHelper.cs | 1 + .../Editor/DmxRecorder/RecorderSettings.cs | 27 ++- .../DmxRecorder/RecorderSettingsEditor.cs | 15 +- 7 files changed, 380 insertions(+), 4 deletions(-) create mode 100644 Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs create mode 100644 Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs.meta create mode 100644 Assets/ArtNet/Editor/DmxRecorder/FileGeneratorDrawer.cs create mode 100644 Assets/ArtNet/Editor/DmxRecorder/FileGeneratorDrawer.cs.meta diff --git a/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs b/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs new file mode 100644 index 0000000..3fd5f74 --- /dev/null +++ b/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs @@ -0,0 +1,187 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; +using UnityEngine; + +namespace ArtNet.Editor.DmxRecorder +{ + internal class Wildcard + { + private readonly Func _resolver; + + public string Pattern { get; } + public string Label { get; } + + internal Wildcard(string pattern, Func resolver) + { + Pattern = pattern; + Label = Pattern; + _resolver = resolver; + } + + internal string Resolve() + { + return _resolver == null ? string.Empty : _resolver(); + } + } + + public static class DefaultWildcard + { + /// + /// The Recorder name. + /// + public static readonly string Recorder = GeneratePattern("Recorder"); + + /// + /// The date when the recording session started (in the yyyy-MM-dd format). + /// + public static readonly string Date = GeneratePattern("Date"); + + /// + /// The time the recording session started (in the 00h00m format). + /// + public static readonly string Time = GeneratePattern("Time"); + + /// + /// The take number (which is incremented every time a new session is started). + /// + public static readonly string Take = GeneratePattern("Take"); + + /// + /// The file extension of the output format. + /// + public static readonly string Extension = GeneratePattern("Extension"); + + private static string GeneratePattern(string tag) + { + return "<" + tag + ">"; + } + } + + /// + /// A class that provides a way to generate names of output files, with support for wildcards. + /// + [Serializable] + public class FileGenerator + { + [SerializeField] private string _directory = "Recordings"; + [SerializeField] private string _fileName = DefaultWildcard.Recorder; + + private readonly List _wildcards; + internal IEnumerable Wildcards => _wildcards; + + + public string Directory + { + get => _directory; + set => _directory = value; + } + + public string FileName + { + get => _fileName; + set => _fileName = value; + } + + internal RecorderSettings RecorderSettings { get; private set; } + + internal FileGenerator(RecorderSettings recorderSettings) + { + RecorderSettings = recorderSettings; + _wildcards = new List + { + new(DefaultWildcard.Recorder, RecorderResolver), + new(DefaultWildcard.Date, DateResolver), + new(DefaultWildcard.Time, TimeResolver), + new(DefaultWildcard.Take, TakeResolver), + new(DefaultWildcard.Extension, ExtensionResolver) + }; + } + + private string RecorderResolver() + { + return SanitizeInvalidName(RecorderSettings.name); + } + + private static string DateResolver() + { + var date = DateTime.Now; + return date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture); + } + + private static string TimeResolver() + { + var date = DateTime.Now; + return $"{date:HH}h{date:mm}m"; + } + + private string TakeResolver() + { + return RecorderSettings.Take.ToString("000"); + } + + private string ExtensionResolver() + { + return RecorderSettings.Extension; + } + + public string AbsolutePath() + { + return OutputDirectory() + OutputFileName(); + } + + public string OutputDirectory() + { + var path = ApplyWildcards(Directory); + if (!string.IsNullOrEmpty(path) && !path.EndsWith("/")) + path += "/"; + + return Application.dataPath + Path.DirectorySeparatorChar + path; + } + + public string OutputFileName() + { + return ApplyWildcards(SanitizeFileName(FileName)) + "." + ExtensionResolver(); + } + + public void CreateDirectory() + { + var path = ApplyWildcards(Directory); + if (!string.IsNullOrEmpty(path) && !System.IO.Directory.Exists(path)) + System.IO.Directory.CreateDirectory(path); + } + + /// + /// Replaces any invalid path character by "_". + /// + internal static string SanitizeInvalidName(string fileName) + { + var invalidChars = Path.GetInvalidFileNameChars(); + return invalidChars.Aggregate(fileName, (current, c) => current.Replace(c, '_')); + } + + /// + /// Replaces any occurrence of "/" or "\" in file name with "_". + /// + internal static string SanitizeFileName(string fileName) + { + return Regex.Replace(fileName, @"[\\|/]", "_"); + } + + private string ApplyWildcards(string str) + { + if (string.IsNullOrEmpty(str)) + return string.Empty; + + foreach (var w in Wildcards) + { + str = str.Replace(w.Pattern, w.Resolve()); + } + + return str; + } + } +} diff --git a/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs.meta b/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs.meta new file mode 100644 index 0000000..c3bb13b --- /dev/null +++ b/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5cbd4d4ce9594c4581e9948a9f25d9ce +timeCreated: 1731867607 \ No newline at end of file diff --git a/Assets/ArtNet/Editor/DmxRecorder/FileGeneratorDrawer.cs b/Assets/ArtNet/Editor/DmxRecorder/FileGeneratorDrawer.cs new file mode 100644 index 0000000..424910b --- /dev/null +++ b/Assets/ArtNet/Editor/DmxRecorder/FileGeneratorDrawer.cs @@ -0,0 +1,148 @@ +using System.IO; +using UnityEditor; +using UnityEngine; + +namespace ArtNet.Editor.DmxRecorder +{ + [CustomPropertyDrawer(typeof(FileGenerator))] + internal class FileGeneratorDrawer : TargetedPropertyDrawer + { + private static class Styles + { + internal static readonly GUIContent FileNameLabel = new("File Name", "The name of the file to record to."); + internal static readonly GUIContent AddWildcardButton = new("+ Wildcards", + "Add a wildcard to the file name. Wildcards are replaced with values."); + internal static readonly GUIContent PathSelectButton = new("...", "Select the output location"); + } + + private SerializedProperty _fileName; + private SerializedProperty _directory; + + private static readonly GUIStyle PathPreviewStyle = new(GUI.skin.label) + { + wordWrap = true, + stretchHeight = true, + stretchWidth = true, + padding = new RectOffset(20, 0, 0, 0), + clipping = TextClipping.Overflow + }; + + private static Texture2D _openPathIcon; + + protected override void Initialize(SerializedProperty property) + { + if (_openPathIcon == null) _openPathIcon = IconHelper.FolderOpen as Texture2D; + + base.Initialize(property); + + _fileName = property.FindPropertyRelative("_fileName"); + _directory = property.FindPropertyRelative("_directory"); + } + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + Initialize(property); + + EditorGUI.BeginProperty(position, label, property); + + using (new EditorGUILayout.HorizontalScope()) + { + EditorGUILayout.PropertyField(_fileName, Styles.FileNameLabel); + + if (GUILayout.Button(Styles.AddWildcardButton, EditorStyles.popup, GUILayout.Width(90))) + { + GUI.FocusControl(null); + var menu = new GenericMenu(); + + foreach (var w in Target.Wildcards) + { + var pattern = w.Pattern; + menu.AddItem(new GUIContent(w.Label), + false, + () => + { + _fileName.stringValue += pattern; + _fileName.serializedObject.ApplyModifiedProperties(); + }); + } + + menu.ShowAsContext(); + } + } + + + using (new EditorGUILayout.HorizontalScope()) + { + EditorGUILayout.LabelField("Assets Path", GUILayout.Width(EditorGUIUtility.labelWidth)); + + var restRect = GUILayoutUtility.GetRect(GUIContent.none, GUI.skin.textField); + var labelRect = new Rect(restRect.x, restRect.y, 50, restRect.height); + GUI.Label(labelRect, "Assets" + Path.DirectorySeparatorChar, EditorStyles.label); + var directoryInputRect = new Rect( + restRect.x + 55, + restRect.y, + restRect.width - 55, + restRect.height + ); + _directory.stringValue = EditorGUI.TextField(directoryInputRect, _directory.stringValue); + + if (GUILayout.Button(Styles.PathSelectButton, EditorStyles.miniButton, GUILayout.Width(30))) + { + var outputDirectory = Target.OutputDirectory(); + var newDirectory = EditorUtility.OpenFolderPanel("Select Folder", outputDirectory, ""); + GUI.FocusControl(null); + + if (!string.IsNullOrEmpty(newDirectory)) + { + if (!newDirectory.StartsWith(Application.dataPath)) + { + EditorUtility.DisplayDialog("Invalid Path", + "Selected path " + newDirectory + " is not within the project's Assets folder.", + "Ok"); + } + else + { + newDirectory = newDirectory[Application.dataPath.Length..]; + if (newDirectory.StartsWith("/") || newDirectory.StartsWith("\\")) + { + newDirectory = newDirectory[1..]; + } + + _directory.stringValue = newDirectory; + _directory.serializedObject.ApplyModifiedProperties(); + } + } + + GUIUtility.ExitGUI(); + } + } + + + using (new EditorGUILayout.HorizontalScope()) + { + EditorGUILayout.PrefixLabel(" "); + + var layoutOptions = new[] + { + GUILayout.ExpandWidth(true), + GUILayout.ExpandHeight(true) + }; + + var outputPath = Target.AbsolutePath(); + var rect = GUILayoutUtility.GetRect(new GUIContent(outputPath), PathPreviewStyle, layoutOptions); + EditorGUI.SelectableLabel(rect, outputPath, PathPreviewStyle); + + if (GUILayout.Button(_openPathIcon, EditorStyles.miniButton, GUILayout.Width(30))) + { + var outputDir = Target.OutputDirectory(); + var dir = new DirectoryInfo(outputDir); + if (!dir.Exists) dir.Create(); + + EditorUtility.RevealInFinder(outputDir); + } + } + + EditorGUI.EndProperty(); + } + } +} diff --git a/Assets/ArtNet/Editor/DmxRecorder/FileGeneratorDrawer.cs.meta b/Assets/ArtNet/Editor/DmxRecorder/FileGeneratorDrawer.cs.meta new file mode 100644 index 0000000..5f846b1 --- /dev/null +++ b/Assets/ArtNet/Editor/DmxRecorder/FileGeneratorDrawer.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b9b62befaed343eaa8af03d259e81baf +timeCreated: 1731870431 \ No newline at end of file diff --git a/Assets/ArtNet/Editor/DmxRecorder/IconHelper.cs b/Assets/ArtNet/Editor/DmxRecorder/IconHelper.cs index 321389a..4e0768a 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/IconHelper.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/IconHelper.cs @@ -14,6 +14,7 @@ public static class IconHelper public static Texture PlayButton => Icon("PlayButton@2x", true); public static Texture PreMatQuad => Icon("PreMatQuad@2x", true); public static Texture PauseButton => Icon("PauseButton@2x", true); + public static Texture FolderOpen => Icon("FolderOpened Icon"); internal static Texture Icon(string iconPath, bool provideDarkModel = false) { diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs index 9b5f6f0..f548a4c 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using UnityEngine; @@ -7,8 +8,10 @@ public abstract class RecorderSettings : ScriptableObject, ISerializationCallbac { private const int MaxPathLength = 259; - [SerializeField] private string _outputPath; [SerializeField] private bool _enabled = true; + [SerializeField] private string _outputPath; // TODO: FileGenerator を使うようにする + [SerializeField] protected FileGenerator _fileGenerator; + [SerializeField] private int _take = 1; protected internal abstract string Extension { get; } protected internal abstract Texture Icon { get; } @@ -22,6 +25,23 @@ public bool Enabled set => _enabled = value; } + public FileGenerator FileGenerator => _fileGenerator; + + public int Take + { + get => _take; + set + { + if (value < 0) throw new ArgumentOutOfRangeException($"The take number must be positive"); + _take = value; + } + } + + protected RecorderSettings() + { + _fileGenerator = new FileGenerator(this); + } + protected internal virtual void GetErrors(List errors) { if (string.IsNullOrEmpty(_outputPath)) @@ -52,7 +72,10 @@ protected internal virtual bool HasWarnings() return warnings.Count > 0; } - internal virtual void OnValidate() { } + internal virtual void OnValidate() + { + _take = Mathf.Max(0, _take); + } void ISerializationCallbackReceiver.OnBeforeSerialize() { OnBeforeSerialize(); } void ISerializationCallbackReceiver.OnAfterDeserialize() { OnAfterDeserialize(); } diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettingsEditor.cs b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettingsEditor.cs index 9da8b3f..25427a8 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettingsEditor.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettingsEditor.cs @@ -8,6 +8,11 @@ namespace ArtNet.Editor.DmxRecorder [CustomEditor(typeof(RecorderSettings), true)] public class RecorderSettingsEditor : UnityEditor.Editor { + private static class Styles + { + internal static readonly GUIContent TakeNumberLabel = new("Take Number", "Value that the Recorder uses to number the recordings. It increases by one after each recording."); + } + internal event Action OnRecorderValidated; public override void OnInspectorGUI() @@ -21,8 +26,14 @@ public override void OnInspectorGUI() DrawHeader("Output File"); EditorGUILayout.Separator(); - var outputName = serializedObject.FindProperty("_outputPath"); - EditorGUILayout.PropertyField(outputName); + var fileNameGenerator = serializedObject.FindProperty("_fileGenerator"); + EditorGUILayout.PropertyField(fileNameGenerator, GUIContent.none); + + EditorGUILayout.Space(); + EditorGUI.BeginChangeCheck(); + + var take = serializedObject.FindProperty("_take"); + EditorGUILayout.PropertyField(take, Styles.TakeNumberLabel); EditorGUILayout.Separator(); From 2e6faa7458563862ce246e6cc005dd9aa66b371f Mon Sep 17 00:00:00 2001 From: NaoyaKohda Date: Wed, 20 Nov 2024 05:57:54 +0900 Subject: [PATCH 3/6] =?UTF-8?q?FileGenerator=20=E3=82=92=E4=BD=BF=E3=81=86?= =?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 --- Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs index f548a4c..b412e99 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs @@ -9,7 +9,6 @@ public abstract class RecorderSettings : ScriptableObject, ISerializationCallbac private const int MaxPathLength = 259; [SerializeField] private bool _enabled = true; - [SerializeField] private string _outputPath; // TODO: FileGenerator を使うようにする [SerializeField] protected FileGenerator _fileGenerator; [SerializeField] private int _take = 1; @@ -17,7 +16,7 @@ public abstract class RecorderSettings : ScriptableObject, ISerializationCallbac protected internal abstract Texture Icon { get; } internal abstract string DefaultName { get; } - public string OutputPath => _outputPath; + public string OutputPath => FileGenerator.AbsolutePath(); public bool Enabled { @@ -44,11 +43,11 @@ protected RecorderSettings() protected internal virtual void GetErrors(List errors) { - if (string.IsNullOrEmpty(_outputPath)) + if (string.IsNullOrEmpty(FileGenerator.FileName)) { errors.Add("Save path is empty"); } - else if (_outputPath.Length > MaxPathLength) + else if (FileGenerator.FileName.Length > MaxPathLength) { errors.Add($"Save path is too long. Max length is {MaxPathLength}"); } From 5dcab96222ff7154b200652014da633155de81f2 Mon Sep 17 00:00:00 2001 From: NaoyaKohda Date: Thu, 21 Nov 2024 02:18:36 +0900 Subject: [PATCH 4/6] =?UTF-8?q?ScrollView=20=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uss | 1 + Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uxml | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uss b/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uss index 90d8b10..4b7f372 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uss +++ b/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uss @@ -74,6 +74,7 @@ EditableLabel > Label { #recorderSettingsPanel { padding: 6px 18px; + border-bottom-width: 0; } /* footer */ diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uxml b/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uxml index dfae547..1051fba 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uxml +++ b/Assets/ArtNet/Editor/DmxRecorder/RecorderWindow.uxml @@ -13,7 +13,9 @@ - + + + From 730ad0a1b3f9f60ef5dabab5842ed7e9491668b4 Mon Sep 17 00:00:00 2001 From: NaoyaKohda Date: Thu, 21 Nov 2024 02:56:39 +0900 Subject: [PATCH 5/6] =?UTF-8?q?FileGenerator=20=E3=81=8B=E3=82=89=E5=87=BA?= =?UTF-8?q?=E5=8A=9B=E5=85=88=E3=83=91=E3=82=B9=E3=82=92=E5=8F=96=E5=BE=97?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DmxRecorder/ConvertAnimInspector.cs | 2 +- .../Editor/DmxRecorder/FileGenerator.cs | 17 +++++++++--- .../Editor/DmxRecorder/RecordController.cs | 26 ++++--------------- .../Editor/DmxRecorder/RecorderSettings.cs | 3 ++- .../Editor/DmxRecorder/TimelineConverter.cs | 8 +----- 5 files changed, 23 insertions(+), 33 deletions(-) diff --git a/Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs b/Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs index 322199f..f28780a 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs @@ -56,7 +56,7 @@ private static void ConvertAnim(ConvertAnim convertAnim) .packet.Dmx)); TimelineConverter timelineConverter = new(universeData); - timelineConverter.SaveDmxTimelineClips(convertAnim.OutputDirectory); + timelineConverter.SaveDmxTimelineClips(convertAnim.OutputDirectory + "/ArtNetDmx.anim"); Debug.Log("Conversion complete"); } diff --git a/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs b/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs index 3fd5f74..ae67aaa 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/FileGenerator.cs @@ -133,13 +133,24 @@ public string AbsolutePath() return OutputDirectory() + OutputFileName(); } + public string AssetsRelativePath() + { + var path = OutputDirectoryPath(); + return "Assets/" + path + OutputFileName(); + } + public string OutputDirectory() + { + var path = OutputDirectoryPath(); + return Application.dataPath + Path.DirectorySeparatorChar + path; + } + + private string OutputDirectoryPath() { var path = ApplyWildcards(Directory); if (!string.IsNullOrEmpty(path) && !path.EndsWith("/")) path += "/"; - - return Application.dataPath + Path.DirectorySeparatorChar + path; + return path; } public string OutputFileName() @@ -149,7 +160,7 @@ public string OutputFileName() public void CreateDirectory() { - var path = ApplyWildcards(Directory); + var path = OutputDirectory(); if (!string.IsNullOrEmpty(path) && !System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path); } diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecordController.cs b/Assets/ArtNet/Editor/DmxRecorder/RecordController.cs index 0161932..b93e7fc 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecordController.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/RecordController.cs @@ -152,38 +152,22 @@ private void StoreDmxPacket() private void StoreBinary(BinaryRecorderSettings settings) { - var directory = settings.OutputPath; - - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } + settings.FileGenerator.CreateDirectory(); var binary = RecordData.Serialize(_recordedDmx); - var path = Path.Combine(directory, $"{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.bytes"); - var exists = File.Exists(path); + var path = settings.OutputAbsolutePath; File.WriteAllBytes(path, binary); - var message = exists ? "Data updated" : "Data stored"; - Debug.Log($"ArtNet Recorder: {message} at {path}"); } private void Store(AnimationRecorderSettings settings) { - var directory = settings.OutputPath; - if (!directory.StartsWith("Assets")) - { - Debug.LogError("Output directory must be in the Assets folder"); - return; - } + settings.FileGenerator.CreateDirectory(); + var path = settings.OutputAssetPath; - if (!Directory.Exists(directory)) - { - Directory.CreateDirectory(directory); - } var universeData = _recordedDmx.Select(packet => new UniverseData(packet.Item1 / 1000f, packet.Item2 .Universe, packet.Item2.Dmx)); var timelineConverter = new TimelineConverter(universeData); - timelineConverter.SaveDmxTimelineClips(directory); + timelineConverter.SaveDmxTimelineClips(path); } } } diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs index b412e99..2128d00 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/RecorderSettings.cs @@ -16,7 +16,8 @@ public abstract class RecorderSettings : ScriptableObject, ISerializationCallbac protected internal abstract Texture Icon { get; } internal abstract string DefaultName { get; } - public string OutputPath => FileGenerator.AbsolutePath(); + public string OutputAbsolutePath => FileGenerator.AbsolutePath(); + public string OutputAssetPath => FileGenerator.AssetsRelativePath(); public bool Enabled { diff --git a/Assets/ArtNet/Editor/DmxRecorder/TimelineConverter.cs b/Assets/ArtNet/Editor/DmxRecorder/TimelineConverter.cs index fd5568c..d5ebedb 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/TimelineConverter.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/TimelineConverter.cs @@ -52,17 +52,11 @@ public void SaveToClip(AnimationClip clip) } } - public void SaveDmxTimelineClips(string directory) + public void SaveDmxTimelineClips(string path) { - if (System.IO.Directory.Exists(directory) == false) - { - System.IO.Directory.CreateDirectory(directory); - } - var clip = new AnimationClip { name = "ArtNetDmx" }; SaveToClip(clip); - var path = $"{directory}/ArtNetDmx.anim"; AssetDatabase.CreateAsset(clip, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); From 7155a60bffb693e623d244b01e7a9ac328674da6 Mon Sep 17 00:00:00 2001 From: NaoyaKohda Date: Thu, 21 Nov 2024 03:13:49 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=BE=8C=E3=81=AB=20take=20=E3=82=92?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=AF=E3=83=AA=E3=83=A1=E3=83=B3=E3=83=88?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/ArtNet/Editor/DmxRecorder/RecordController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Assets/ArtNet/Editor/DmxRecorder/RecordController.cs b/Assets/ArtNet/Editor/DmxRecorder/RecordController.cs index b93e7fc..5287112 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/RecordController.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/RecordController.cs @@ -147,6 +147,7 @@ private void StoreDmxPacket() default: throw new ArgumentOutOfRangeException(); } + setting.Take++; } }