From 1f4151c962d7efadfa02ee023bbed79732346980 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 29 Sep 2024 12:51:32 +0100 Subject: [PATCH 1/3] :construction: 2.3.0 Release Prep - New editor only save so the build save is in the normal location. - New save defaults setup that lets users assign defaults outside of constructors when creating save values. - Save defaults now apply when making a build to all save objects so builds don't have persistent data from editor saves. - New setting to see save defaults in the editor tab like save keys - New editor GUI on save objects to see default values. --- .../Inspectors/SaveObjectEditor.cs | 40 ++++++ .../SaveValuePropertyDrawer.cs | 7 + .../Windows/Defaults Window.meta | 3 + .../Defaults Window/SaveDefaultsWindow.cs | 126 ++++++++++++++++++ .../SaveDefaultsWindow.cs.meta | 11 ++ .../Editor Window/Sub Windows/EditorTab.cs | 9 +- .../Code/Editor/Info/AssetVersionData.cs | 4 +- .../SaveManagerSettingsProvider.cs | 2 + .../Code/Editor/Systems/Build Handlers.meta | 3 + .../BuildHandlerResetSaveObjects.cs | 101 ++++++++++++++ .../BuildHandlerResetSaveObjects.cs.meta | 11 ++ .../Per User Settings/PerUserSettings.cs | 11 ++ .../Data/AssetGlobalRuntimeSettings.cs | 18 +-- .../Save Manager/Code/Runtime/SaveManager.cs | 40 ++++-- .../Demo/Data/Example Save Object.asset | 10 +- package.json | 2 +- 16 files changed, 364 insertions(+), 34 deletions(-) create mode 100644 Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window.meta create mode 100644 Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window/SaveDefaultsWindow.cs create mode 100644 Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window/SaveDefaultsWindow.cs.meta create mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Build Handlers.meta create mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Build Handlers/BuildHandlerResetSaveObjects.cs create mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Build Handlers/BuildHandlerResetSaveObjects.cs.meta diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Inspectors/SaveObjectEditor.cs b/Carter Games/Save Manager/Code/Editor/Custom Editors/Inspectors/SaveObjectEditor.cs index ea5234c..dba8692 100644 --- a/Carter Games/Save Manager/Code/Editor/Custom Editors/Inspectors/SaveObjectEditor.cs +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Inspectors/SaveObjectEditor.cs @@ -94,6 +94,8 @@ public override void OnInspectorGUI() InspectorDrawInfoSection(); EditorGUILayout.Space(3.5f); InspectorDrawValues(); + EditorGUILayout.Space(3.5f); + InspectorDrawDefaultValues(); serializedObject.Update(); } @@ -240,5 +242,43 @@ private void InspectorDrawValues() EditorGUILayout.Space(1.5f); EditorGUILayout.EndVertical(); } + + + /// + /// Draws the default values section for the save object. + /// + private void InspectorDrawDefaultValues() + { + if (!targetSaveObject.IsInitialized) return; + + EditorGUILayout.BeginVertical("HelpBox"); + EditorGUILayout.Space(.5f); + + EditorGUILayout.LabelField("Default Values", EditorStyles.boldLabel); + UtilEditor.DrawHorizontalGUILine(); + + var prop = serializedObject.GetIterator(); + + EditorGUI.BeginDisabledGroup(true); + + if (prop.NextVisible(true)) + { + while (prop.NextVisible(false)) + { + if (propertiesLookup.ContainsKey(prop.name)) continue; + + EditorGUI.indentLevel++; + + EditorGUILayout.PropertyField(serializedObject.Fp(prop.name).Fpr("defaultValue"), new GUIContent(prop.displayName), true); + + EditorGUI.indentLevel--; + } + } + + EditorGUI.EndDisabledGroup(); + + EditorGUILayout.Space(1.5f); + EditorGUILayout.EndVertical(); + } } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Property Drawers/SaveValuePropertyDrawer.cs b/Carter Games/Save Manager/Code/Editor/Custom Editors/Property Drawers/SaveValuePropertyDrawer.cs index f2d9b3c..9c77198 100644 --- a/Carter Games/Save Manager/Code/Editor/Custom Editors/Property Drawers/SaveValuePropertyDrawer.cs +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Property Drawers/SaveValuePropertyDrawer.cs @@ -72,6 +72,13 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten SaveManager.Save(); } + if (PerUserSettings.ShowDefaultValues) + { + EditorGUI.BeginDisabledGroup(true); + EditorGUILayout.PropertyField(property.Fpr("defaultValue"), new GUIContent("Default Value")); + EditorGUI.EndDisabledGroup(); + } + EditorGUILayout.EndVertical(); EditorGUI.indentLevel--; diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window.meta b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window.meta new file mode 100644 index 0000000..c6de67b --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 55d5136f42a64fd19bad08ec3161478a +timeCreated: 1727602184 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window/SaveDefaultsWindow.cs b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window/SaveDefaultsWindow.cs new file mode 100644 index 0000000..f1e95af --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window/SaveDefaultsWindow.cs @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2024 Carter Games + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +using UnityEditor; +using UnityEngine; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// An editor window to edit the save defaults of a save object. + /// + public sealed class SaveDefaultsWindow : EditorWindow + { + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Fields + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static SaveObject selected; + private static SerializedObject selectedObject; + private static Vector2 scrollRectPos; + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Open Window Method + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + public static void ShowDefaultsWindow(SaveObject saveObject, SerializedObject serializedObjectForSaveObject) + { + selected = saveObject; + selectedObject = serializedObjectForSaveObject; + + GetWindow(true, $"Default Values - {selected.name}").Show(); + } + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Draw Methods + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private void OnGUI() + { + if (selected == null) + { + Close(); + return; + } + + scrollRectPos = EditorGUILayout.BeginScrollView(scrollRectPos); + + DrawTab(); + + EditorGUILayout.EndScrollView(); + } + + + private void DrawTab() + { + if (Application.isPlaying) + { + EditorGUILayout.HelpBox( + "You cannot edit the save while in play mode, please exit play mode to edit the save data.", + MessageType.Info); + } + + EditorGUILayout.HelpBox( + $"Here you can edit all the default save values on the Save object. These are then set on a fresh save where defaults are used in the resetting.", + MessageType.Info); + + EditorGUILayout.BeginVertical("Box"); + + if (selected != null) + { + ShowPropertiesForObject(); + } + + EditorGUILayout.EndVertical(); + } + + + private static void ShowPropertiesForObject() + { + var propIterator = selectedObject.GetIterator(); + + if (!propIterator.NextVisible(true)) return; + + while (propIterator.NextVisible(true)) + { + var propElement = selectedObject.Fp(propIterator.name); + + if (propElement == null) continue; + + GUILayout.Space(3.5f); + + EditorGUILayout.BeginVertical("HelpBox"); + + EditorGUILayout.PropertyField(selectedObject.Fp(propIterator.name).Fpr("defaultValue"), + new GUIContent(propIterator.displayName)); + + EditorGUILayout.EndVertical(); + } + + GUILayout.Space(3.5f); + + selectedObject.ApplyModifiedProperties(); + selectedObject.Update(); + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window/SaveDefaultsWindow.cs.meta b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window/SaveDefaultsWindow.cs.meta new file mode 100644 index 0000000..a428e41 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window/SaveDefaultsWindow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2e7d735c79654935be379bf9c1f965ae +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 40ab1dfa65cdd6247bb1a3d4ea54901c, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/Sub Windows/EditorTab.cs b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/Sub Windows/EditorTab.cs index 8649df7..20f3b85 100644 --- a/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/Sub Windows/EditorTab.cs +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/Sub Windows/EditorTab.cs @@ -204,8 +204,15 @@ private void DrawSaveObjectEditor(SaveObject targetSaveObject) } EditorGUI.BeginDisabledGroup(Application.isPlaying); - GUI.backgroundColor = UtilEditor.Red; + GUI.backgroundColor = Color.cyan; + if (GUILayout.Button("Defaults", GUILayout.Width(75))) + { + SaveDefaultsWindow.ShowDefaultsWindow(targetSaveObject, editorsLookup[targetSaveObject].serializedObject); + } + + GUI.backgroundColor = UtilEditor.Red; + if (GUILayout.Button("-", GUILayout.Width(25))) { if (EditorUtility.DisplayDialog("Reset Save Object", diff --git a/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs b/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs index e58d0c7..bd69c56 100644 --- a/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs +++ b/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs @@ -31,7 +31,7 @@ public static class AssetVersionData /// /// The version number of the asset. /// - public static string VersionNumber => "2.2.0"; + public static string VersionNumber => "2.3.0"; /// @@ -40,6 +40,6 @@ public static class AssetVersionData /// /// Asset owner is in the UK, so its D/M/Y format. /// - public static string ReleaseDate => "2024/09/27"; + public static string ReleaseDate => "2024/09/29"; } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Settings Provider/SaveManagerSettingsProvider.cs b/Carter Games/Save Manager/Code/Editor/Settings Provider/SaveManagerSettingsProvider.cs index d51989f..e852bd5 100644 --- a/Carter Games/Save Manager/Code/Editor/Settings Provider/SaveManagerSettingsProvider.cs +++ b/Carter Games/Save Manager/Code/Editor/Settings Provider/SaveManagerSettingsProvider.cs @@ -48,6 +48,7 @@ public static class SaveManagerSettingsProvider private static readonly GUIContent PrettyFormat = new GUIContent("Pretty Save Formatting?","Formats the save file into a more readable format when saving."); private static readonly GUIContent AutoSave = new GUIContent("Auto Save?","Defines if the game saves when exiting the game."); private static readonly GUIContent SaveKeysToggle = new GUIContent("Show Save Keys?","Defines if the save editor shows the save key for each save value, Use this to condense the UI a tad if you need to."); + private static readonly GUIContent SaveDefaultsToggle = new GUIContent("Show Default Values?","Defines if the save editor shows the default value for each save value, Use this to condense the UI a tad if you need to."); private static readonly GUIContent Logs = new GUIContent("Show Log Messages?", "Shows log messages for any errors as well as some handy debugging information."); private const string ExplorerButtonLabel = "Open Save Path In Explorer"; @@ -238,6 +239,7 @@ private static void DrawGeneralOptions() // Editor Only Setting.... PerUserSettings.ShowSaveKeys = EditorGUILayout.Toggle(SaveKeysToggle, PerUserSettings.ShowSaveKeys); + PerUserSettings.ShowDefaultValues = EditorGUILayout.Toggle(SaveDefaultsToggle, PerUserSettings.ShowDefaultValues); // Use save categories... EditorGUI.BeginChangeCheck(); diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Build Handlers.meta b/Carter Games/Save Manager/Code/Editor/Systems/Build Handlers.meta new file mode 100644 index 0000000..5d9ae97 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Systems/Build Handlers.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 79a5d8e3a80d4fafb4cc267d036f70c2 +timeCreated: 1727550491 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Build Handlers/BuildHandlerResetSaveObjects.cs b/Carter Games/Save Manager/Code/Editor/Systems/Build Handlers/BuildHandlerResetSaveObjects.cs new file mode 100644 index 0000000..abd11db --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Systems/Build Handlers/BuildHandlerResetSaveObjects.cs @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2024 Carter Games + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +using System.Reflection; +using UnityEditor; +using UnityEditor.Build; +using UnityEditor.Build.Reporting; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// Handles resetting save objects to defaults on builds, then restoring them when the build is done. + /// + public sealed class BuildHandlerResetSaveObjects : IPreprocessBuildWithReport, IPostprocessBuildWithReport + { + public int callbackOrder { get; } + + + public void OnPreprocessBuild(BuildReport report) + { + var assets = AssetDatabase.FindAssets($"t:{typeof(SaveObject)}"); + + if (assets.Length <= 0) return; + + foreach (var asset in assets) + { + var fileInstancePath = AssetDatabase.GUIDToAssetPath(asset); + var fileInstance = AssetDatabase.LoadAssetAtPath(fileInstancePath); + + var assetObject = new SerializedObject(fileInstance); + + EditorPrefs.SetString(assetObject.targetObject.GetInstanceID().ToString(), EditorJsonUtility.ToJson(assetObject.targetObject)); + + var propIterator = assetObject.GetIterator(); + + if (propIterator.NextVisible(true)) + { + while (propIterator.NextVisible(true)) + { + var propElement = assetObject.Fp(propIterator.name); + + if (propElement == null) continue; + if (!propElement.type.Contains("SaveValue")) continue; + if (propElement.propertyType != propIterator.propertyType) continue; + + var field = assetObject.targetObject.GetType() + .GetField(propElement.propertyPath.Split('.')[0], + BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); + + field.GetValue(assetObject.targetObject).GetType() + .GetMethod("ResetValue", BindingFlags.Public | BindingFlags.Instance).Invoke(field.GetValue(assetObject.targetObject), new object[] { true }); + } + } + + assetObject.ApplyModifiedProperties(); + assetObject.Update(); + } + } + + + public void OnPostprocessBuild(BuildReport report) + { + var assets = AssetDatabase.FindAssets($"t:{typeof(SaveObject)}"); + + if (assets.Length <= 0) return; + + foreach (var asset in assets) + { + var fileInstancePath = AssetDatabase.GUIDToAssetPath(asset); + var fileInstance = AssetDatabase.LoadAssetAtPath(fileInstancePath); + + var assetObject = new SerializedObject(fileInstance); + + EditorJsonUtility.FromJsonOverwrite(EditorPrefs.GetString(assetObject.targetObject.GetInstanceID().ToString()), assetObject.targetObject); + EditorUtility.SetDirty(assetObject.targetObject); + } + + AssetDatabase.SaveAssets(); + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Build Handlers/BuildHandlerResetSaveObjects.cs.meta b/Carter Games/Save Manager/Code/Editor/Systems/Build Handlers/BuildHandlerResetSaveObjects.cs.meta new file mode 100644 index 0000000..6028de3 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Systems/Build Handlers/BuildHandlerResetSaveObjects.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: af8146194adf45dea55a4b83b49fe63f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 40ab1dfa65cdd6247bb1a3d4ea54901c, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Per User Settings/PerUserSettings.cs b/Carter Games/Save Manager/Code/Editor/Utility/Per User Settings/PerUserSettings.cs index 797dd28..cb036ee 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/Per User Settings/PerUserSettings.cs +++ b/Carter Games/Save Manager/Code/Editor/Utility/Per User Settings/PerUserSettings.cs @@ -48,6 +48,7 @@ public static class PerUserSettings private static readonly string SaveEditorProfileViewerId = $"{UniqueId}_CarterGames_SaveManager_EditorSettings_EditorProfileViewerShown"; private static readonly string SaveLastProfileNameId = $"{UniqueId}_CarterGames_SaveManager_EditorSettings_LastProfileName"; private static readonly string ShowSaveKeysId = $"{UniqueId}_CarterGames_SaveManager_EditorSettings_ShowSaveKeys"; + private static readonly string ShowDefaultValuesId = $"{UniqueId}_CarterGames_SaveManager_EditorSettings_ShowDefaultValues"; private static readonly string LastSaveObjectNameId = $"{UniqueId}_CarterGames_SaveManager_EditorSettings_LastSaveObjectName"; private static readonly string LastSaveObjectFileNameId = $"{UniqueId}_CarterGames_SaveManager_EditorSettings_LastSaveObjectFileName"; @@ -151,6 +152,16 @@ public static bool ShowSaveKeys } + /// + /// Should the editor show the default values for the save values in-line in the editor. + /// + public static bool ShowDefaultValues + { + get => (bool)GetOrCreateValue(ShowDefaultValuesId, SettingType.EditorPref, false); + set => SetValue(ShowDefaultValuesId, SettingType.EditorPref, value); + } + + /// /// The name of last save object made by the user. /// diff --git a/Carter Games/Save Manager/Code/Runtime/Data/AssetGlobalRuntimeSettings.cs b/Carter Games/Save Manager/Code/Runtime/Data/AssetGlobalRuntimeSettings.cs index 7ea8580..4fbcf16 100644 --- a/Carter Games/Save Manager/Code/Runtime/Data/AssetGlobalRuntimeSettings.cs +++ b/Carter Games/Save Manager/Code/Runtime/Data/AssetGlobalRuntimeSettings.cs @@ -52,22 +52,6 @@ public sealed class AssetGlobalRuntimeSettings : SaveManagerAsset | Properties ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - /// - /// Gets the default save path per platform, you cannot edit this. - /// - public string DefaultSavePath - { - get - { -#if UNITY_WEBGL && !UNITY_EDITOR - return defaultSavePathWeb.ParseSavePath(); -#else - return defaultSavePath.ParseSavePath(); -#endif - } - } - - /// /// Gets the save path for the game save data. /// @@ -77,6 +61,8 @@ public string SavePath { #if UNITY_WEBGL && !UNITY_EDITOR return defaultSavePathWeb.ParseSavePath(); +#elif UNITY_EDITOR + return ("%Application.persistentDataPath%/EditorSave/save.sf").ParseSavePath(); #else return defaultSavePath.ParseSavePath(); #endif diff --git a/Carter Games/Save Manager/Code/Runtime/SaveManager.cs b/Carter Games/Save Manager/Code/Runtime/SaveManager.cs index 1df4d3e..c5650af 100644 --- a/Carter Games/Save Manager/Code/Runtime/SaveManager.cs +++ b/Carter Games/Save Manager/Code/Runtime/SaveManager.cs @@ -237,17 +237,21 @@ private static void SaveToFile(SerializableDictionaryLoad Generic Data. diff --git a/Carter Games/Save Manager/Demo/Data/Example Save Object.asset b/Carter Games/Save Manager/Demo/Data/Example Save Object.asset index 8658e05..61810ac 100644 --- a/Carter Games/Save Manager/Demo/Data/Example Save Object.asset +++ b/Carter Games/Save Manager/Demo/Data/Example Save Object.asset @@ -12,19 +12,19 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 11010672a3811f84e8d31964f42df820, type: 3} m_Name: Example Save Object m_EditorClassIdentifier: - isExpanded: 0 + isExpanded: 1 saveKey: Example playerName: key: examplePlayerName - value: Emily - defaultValue: + value: Annie + defaultValue: Emily playerHealth: key: examplePlayerHealth - value: -102 + value: 100 defaultValue: 0 playerPosition: key: examplePlayerPosition - value: {x: 0, y: 0, z: 0} + value: {x: 1, y: 2, z: 3} defaultValue: {x: 0, y: 0, z: 0} playerShield: key: examplePlayerShield diff --git a/package.json b/package.json index 62f2b37..f2a6215 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "games.carter.savemanager", - "version": "2.2.0", + "version": "2.3.0", "displayName": "Save Manager", "description": "A free, scriptable object based, local save system for Unity. Works on all platforms using standard JSON Utility.", "unity": "2020.3", From 8730728fb39cf463a0e7d435f570d0ca716679da Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 1 Oct 2024 17:05:30 +0100 Subject: [PATCH 2/3] :construction: 2.3.0 Ready more or less. - Removed some old legacy fixes for issues that are now dated. - Removed some old API that isn't needed anymore. - Updated change log with changes. --- CHANGELOG.md | 12 +++ .../Code/Editor/Info/AssetVersionData.cs | 2 +- .../Code/Editor/Systems/Legacy.meta | 3 - .../Systems/Legacy/Asset Index Cleanup.meta | 3 - .../LegacyIndexRemovalTool.cs | 77 ------------------- .../LegacyIndexRemovalTool.cs.meta | 11 --- .../Legacy/Editor Settings Asset Cleanup.meta | 3 - .../LegacyEditorSettingsRemover.cs | 69 ----------------- .../LegacyEditorSettingsRemover.cs.meta | 11 --- .../Scriptable Assets/.idea/indexLayout.xml | 8 ++ .../.idea/projectSettingsUpdater.xml | 6 ++ .../Scriptable Assets/FileEditorUtil.cs | 68 +--------------- .../Scriptable Assets/ScriptableRef.cs | 5 -- .../Code/Editor/Utility/UtilEditor.cs | 10 +-- 14 files changed, 30 insertions(+), 258 deletions(-) delete mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Legacy.meta delete mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup.meta delete mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup/LegacyIndexRemovalTool.cs delete mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup/LegacyIndexRemovalTool.cs.meta delete mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup.meta delete mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup/LegacyEditorSettingsRemover.cs delete mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup/LegacyEditorSettingsRemover.cs.meta create mode 100644 Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/.idea/indexLayout.xml create mode 100644 Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/.idea/projectSettingsUpdater.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d286c1..e296eb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +# 2.3.0 +## Asset changes + +- New editor only save so the build save is in the normal location. +- New save defaults setup that lets users assign defaults outside of constructors when creating save values. +- Save defaults now apply when making a build to all save objects so builds don't have persistent data from editor saves. +- New setting to see save defaults in the editor tab like save keys +- New editor GUI on save objects to see default values. +- Removed some older 2.0.x legacy issue fixers. +- Removed some now redundant API bits. + + # 2.2.0 ## Asset changes diff --git a/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs b/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs index bd69c56..51bf309 100644 --- a/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs +++ b/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs @@ -40,6 +40,6 @@ public static class AssetVersionData /// /// Asset owner is in the UK, so its D/M/Y format. /// - public static string ReleaseDate => "2024/09/29"; + public static string ReleaseDate => "2024/10/01"; } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Legacy.meta b/Carter Games/Save Manager/Code/Editor/Systems/Legacy.meta deleted file mode 100644 index 4e292c7..0000000 --- a/Carter Games/Save Manager/Code/Editor/Systems/Legacy.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: dc650ea037fd3144f839e667ddc9ae87 -timeCreated: 1690704466 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup.meta b/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup.meta deleted file mode 100644 index 3fadffd..0000000 --- a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 148b5acb3e61b6545afdce007783abe9 -timeCreated: 1690704512 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup/LegacyIndexRemovalTool.cs b/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup/LegacyIndexRemovalTool.cs deleted file mode 100644 index 5e799f2..0000000 --- a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup/LegacyIndexRemovalTool.cs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2024 Carter Games - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -using System.IO; -using UnityEditor; - -namespace CarterGames.Assets.SaveManager.Editor -{ - /// - /// A helper class to remove the old asset index if it exists in the project still. - /// As of (2.0.9) it was moved into the asset folder structure, so the external one is not used anymore. - /// - public static class LegacyIndexRemovalTool - { - /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── - | Fields - ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - - /// - /// The path of the old index to clear. - /// - private const string LegacyIndexPath = "Assets/Resources/Carter Games/Save Manager/Asset Index.asset"; - - /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── - | Methods - ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - - /// - /// Returns if the old index is still in place. - /// - /// Bool - private static bool HasLegacyIndex() - { - return File.Exists(LegacyIndexPath); - } - - - /// - /// Tries to remove the old index and pathing where possible - /// - /// Doesn't delete Carter Games folder in-case other assets still use it. - public static void TryRemoveOldIndex() - { - if (!HasLegacyIndex()) return; - - Directory.Delete("Assets/Resources/Carter Games/Save Manager/", true); - AssetDatabase.Refresh(); - - if (Directory.GetFiles("Assets/Resources/Carter Games/").Length <= 1) - { - FileUtil.DeleteFileOrDirectory("Assets/Resources/Carter Games"); - } - - AssetDatabase.Refresh(); - } - } -} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup/LegacyIndexRemovalTool.cs.meta b/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup/LegacyIndexRemovalTool.cs.meta deleted file mode 100644 index e19033c..0000000 --- a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup/LegacyIndexRemovalTool.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: cc9560638917f48478b8f08bef34ddc5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {fileID: 2800000, guid: 40ab1dfa65cdd6247bb1a3d4ea54901c, type: 3} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup.meta b/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup.meta deleted file mode 100644 index c55ec8c..0000000 --- a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e640e0e069804f89b7e460fdd3bd2d64 -timeCreated: 1694156530 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup/LegacyEditorSettingsRemover.cs b/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup/LegacyEditorSettingsRemover.cs deleted file mode 100644 index 0f75824..0000000 --- a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup/LegacyEditorSettingsRemover.cs +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2024 Carter Games - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -using UnityEditor; -using UnityEngine.Windows; - -namespace CarterGames.Assets.SaveManager.Editor -{ - /// - /// Handles the removal of any legacy editor settings asset for this asset. - /// - /// - /// It was moved to editor prefs as of 2.0.13 to aid with version control on group projects with the asset. - /// - public sealed class LegacyEditorSettingsRemover : AssetPostprocessor - { - /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── - | Fields - ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - - private static readonly string OldEditorSettingsPath = - $"{FileEditorUtil.AssetBasePath}/Carter Games/{FileEditorUtil.AssetName}/Data/Editor Settings.asset"; - - /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── - | Methods - ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - - private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, - string[] movedFromAssetPaths) - { - Mitigate(); - } - - - /// - /// Runs the mitigation for the editor settings to be deleted. - /// - private static void Mitigate() - { - if (!File.Exists(OldEditorSettingsPath)) return; - - // Remove the file as its not needed anymore as of (2.0.13) - File.Delete(OldEditorSettingsPath); - - AssetDatabase.SaveAssets(); - AssetDatabase.Refresh(); - } - } -} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup/LegacyEditorSettingsRemover.cs.meta b/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup/LegacyEditorSettingsRemover.cs.meta deleted file mode 100644 index 6149409..0000000 --- a/Carter Games/Save Manager/Code/Editor/Systems/Legacy/Editor Settings Asset Cleanup/LegacyEditorSettingsRemover.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 36082022a4cc408fae60dc4cc6c2fea4 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {fileID: 2800000, guid: 40ab1dfa65cdd6247bb1a3d4ea54901c, type: 3} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/.idea/indexLayout.xml b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/.idea/projectSettingsUpdater.xml b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/.idea/projectSettingsUpdater.xml new file mode 100644 index 0000000..86cc6c6 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/.idea/projectSettingsUpdater.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/FileEditorUtil.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/FileEditorUtil.cs index 4bb025c..3dc54c6 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/FileEditorUtil.cs +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/FileEditorUtil.cs @@ -44,76 +44,10 @@ public static class FileEditorUtil /// public const string AssetName = "Save Manager"; - - /// - /// The path to a script in the asset to verify the asset base path. - /// - private static readonly string BasePathScriptPath = $"/Carter Games/{AssetName}/Code/Editor/Utility/{BasePathScriptName}.cs"; - - - /// - /// The base path check script name. - /// - private const string BasePathScriptName = "UtilEditor"; - - - /// - /// The base path cache. - /// - private static string basePath = ""; - /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── - | Properties + | Methods ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - /// - /// The base path for the asset code. - /// - public static string AssetBasePath - { - get - { - if (basePath.Length > 0) return basePath; - basePath = GetBaseAssetPath(); - return basePath; - } - } - - /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── - | Getter Methods - ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - - /// - /// Gets the base path of the asset code, will break if the code is split up by the user. - /// - /// The base path found. - private static string GetBaseAssetPath() - { - string path = string.Empty; - var containsChecks = new List { AssetName, $"/{BasePathScriptName}.cs" }; - - foreach (var scriptFound in AssetDatabase.FindAssets($"t:Script {nameof(UtilEditor)}")) - { - path = AssetDatabase.GUIDToAssetPath(scriptFound); - - foreach (var check in containsChecks) - { - if (!path.Contains(check)) goto SkipAndLoop; - } - - path = AssetDatabase.GUIDToAssetPath(scriptFound); - path = path.Replace(BasePathScriptPath, ""); - - return path; - - // Skips the return as the path contained an invalid element for the asset... - SkipAndLoop: ; - } - - return path; - } - - /// /// Gets a script file in the asset. /// diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/ScriptableRef.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/ScriptableRef.cs index 0dcb19e..85f029a 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/ScriptableRef.cs +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/ScriptableRef.cs @@ -54,11 +54,6 @@ public static class ScriptableRef // Helper Properties /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - /// - /// Gets the path where the asset code is located. - /// - private static string AssetBasePath => FileEditorUtil.AssetBasePath; - /// /// Gets the asset name stored in the file util editor class. diff --git a/Carter Games/Save Manager/Code/Editor/Utility/UtilEditor.cs b/Carter Games/Save Manager/Code/Editor/Utility/UtilEditor.cs index 8425e67..09fc7f1 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/UtilEditor.cs +++ b/Carter Games/Save Manager/Code/Editor/Utility/UtilEditor.cs @@ -41,7 +41,7 @@ public static class UtilEditor // Paths /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ public const string SettingsWindowPath = "Carter Games/Assets/Save Manager"; - public static readonly string CapturesSavePath = $"{AssetBasePath}/Carter Games/Save Manager/Data/Save Profiles/"; + public static readonly string CapturesSavePath = $"{ScriptableRef.FullPathData}/Save Profiles/"; // Filters @@ -120,13 +120,7 @@ public static class UtilEditor /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Properties ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - - /// - /// Gets the path where the asset code is located. - /// - private static string AssetBasePath => FileEditorUtil.AssetBasePath; - - + // Textures/Graphics /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ From 58a7843293f396fa162c0cedac09885884226592 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Thu, 3 Oct 2024 08:01:09 +0100 Subject: [PATCH 3/3] :nut_and_bolt: Updated release date --- Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs b/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs index 51bf309..e1c91b5 100644 --- a/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs +++ b/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs @@ -40,6 +40,6 @@ public static class AssetVersionData /// /// Asset owner is in the UK, so its D/M/Y format. /// - public static string ReleaseDate => "2024/10/01"; + public static string ReleaseDate => "2024/10/03"; } } \ No newline at end of file