From 1cf5930d51f1ab7af5387793e03df12b8a1e02ce Mon Sep 17 00:00:00 2001 From: James Frowen Date: Thu, 24 Dec 2020 07:29:36 +0000 Subject: [PATCH] feat: Adding default folder as argument for ScriptableObjectUtility (#2513) This allows ScriptableObjectUtility to be used for other folders not just Asset/Mirror --- Assets/Mirror/Editor/Logging/LogLevelsGUI.cs | 3 ++- .../Mirror/Editor/ScriptableObjectUtility.cs | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Assets/Mirror/Editor/Logging/LogLevelsGUI.cs b/Assets/Mirror/Editor/Logging/LogLevelsGUI.cs index 2aaa855fe..47cffaa83 100644 --- a/Assets/Mirror/Editor/Logging/LogLevelsGUI.cs +++ b/Assets/Mirror/Editor/Logging/LogLevelsGUI.cs @@ -7,11 +7,12 @@ namespace Mirror.EditorScripts.Logging { public static class LogLevelsGUI { + const string DefaultFolder = "Assets/Mirror/"; public static LogSettings DrawCreateNewButton() { if (GUILayout.Button("Create New")) { - return ScriptableObjectUtility.CreateAsset(nameof(LogSettings)); + return ScriptableObjectUtility.CreateAsset(nameof(LogSettings), DefaultFolder); } return null; diff --git a/Assets/Mirror/Editor/ScriptableObjectUtility.cs b/Assets/Mirror/Editor/ScriptableObjectUtility.cs index e6a36bd2f..d98cc935d 100644 --- a/Assets/Mirror/Editor/ScriptableObjectUtility.cs +++ b/Assets/Mirror/Editor/ScriptableObjectUtility.cs @@ -5,12 +5,18 @@ namespace Mirror.EditorScripts { public static class ScriptableObjectUtility { - /// - // This makes it easy to create, name and place unique new ScriptableObject asset files. - /// + const string DefaultMirrorFolder = "Assets/Mirror/"; + + [System.Obsolete("Use CreateAsset(string defaultName, string defaultFolder) instead")] public static T CreateAsset(string defaultName) where T : ScriptableObject + => CreateAsset(defaultName, DefaultMirrorFolder); + + /// + /// This makes it easy to create, name and place unique new ScriptableObject asset files. + /// + public static T CreateAsset(string defaultName, string defaultFolder) where T : ScriptableObject { - string path = SavePanel(defaultName); + string path = SavePanel(defaultName, defaultFolder); // user click cancel if (string.IsNullOrEmpty(path)) { return null; } @@ -21,11 +27,11 @@ public static T CreateAsset(string defaultName) where T : ScriptableObject return asset; } - static string SavePanel(string name) + static string SavePanel(string name, string defaultFolder) { string path = EditorUtility.SaveFilePanel( "Save ScriptableObject", - "Assets/Mirror/", + defaultFolder, name + ".asset", "asset");