From 0639bc3ecfede23c2b6cefc4c5d9160e0fe6b4cc Mon Sep 17 00:00:00 2001 From: Jonathan Date: Mon, 1 Jan 2024 20:23:32 +0000 Subject: [PATCH] :package: 2.1.0 Release - Save categories added as a togglable feature. - Some minor backend changes. --- Carter Games.meta | 2 +- Carter Games/Save Manager.meta | 2 +- .../CarterGames.SaveManager.Editor.asmdef | 2 +- .../SaveManagerSettingsProvider.cs | 15 +- .../Editor Window/SaveManagerEditorWindow.cs | 5 + .../Editor Window/Sub Windows/EditorTab.cs | 220 +++++++++++------- .../Code/Editor/Systems/Attributes.meta | 3 + .../Attributes/SaveCategoryAttributeData.cs | 70 ++++++ .../SaveCategoryAttributeData.cs.meta | 11 + .../Attributes/SaveCategoryAttributeHelper.cs | 84 +++++++ .../SaveCategoryAttributeHelper.cs.meta | 11 + .../Code/Editor/Utility/AssetVersionData.cs | 4 +- .../Per User Settings/PerUserSettings.cs | 15 +- .../CarterGames.SaveManager.Runtime.asmdef | 2 +- .../Code/Runtime/Data/SettingsAssetRuntime.cs | 7 - .../Save Manager/Code/Runtime/Logger/SmLog.cs | 2 +- .../Runtime/Save Data/Objects/SaveObject.cs | 38 ++- .../Code/Runtime/Save Data/SaveData.cs | 2 +- .../Save Manager/Code/Runtime/SaveManager.cs | 6 +- .../Utility/Per User Settings Runtime.meta | 3 + .../PerUserSettingsRuntime.cs | 109 +++++++++ .../PerUserSettingsRuntime.cs.meta | 11 + .../Code/Runtime/Utility/Perf Settings.meta | 3 + .../{ => Perf Settings}/PrefSetting.cs | 0 .../{ => Perf Settings}/PrefSetting.cs.meta | 0 .../{ => Perf Settings}/PrefUseOption.cs | 0 .../{ => Perf Settings}/PrefUseOption.cs.meta | 0 27 files changed, 519 insertions(+), 108 deletions(-) create mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Attributes.meta create mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeData.cs create mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeData.cs.meta create mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeHelper.cs create mode 100644 Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeHelper.cs.meta create mode 100644 Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime.meta create mode 100644 Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime/PerUserSettingsRuntime.cs create mode 100644 Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime/PerUserSettingsRuntime.cs.meta create mode 100644 Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings.meta rename Carter Games/Save Manager/Code/Runtime/Utility/{ => Perf Settings}/PrefSetting.cs (100%) rename Carter Games/Save Manager/Code/Runtime/Utility/{ => Perf Settings}/PrefSetting.cs.meta (100%) rename Carter Games/Save Manager/Code/Runtime/Utility/{ => Perf Settings}/PrefUseOption.cs (100%) rename Carter Games/Save Manager/Code/Runtime/Utility/{ => Perf Settings}/PrefUseOption.cs.meta (100%) diff --git a/Carter Games.meta b/Carter Games.meta index 93396db..c90df93 100644 --- a/Carter Games.meta +++ b/Carter Games.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 9b150e45df5e6cf419ddb163013bdc55 +guid: 095444ce400fc0343809991319c4cc7e folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Carter Games/Save Manager.meta b/Carter Games/Save Manager.meta index c631f98..dfa162b 100644 --- a/Carter Games/Save Manager.meta +++ b/Carter Games/Save Manager.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: b50c1b28e9c0e29479cc162408fc29cf +guid: 3a5fd1648a350914da17fdf40d29cc2e folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Carter Games/Save Manager/Code/Editor/CarterGames.SaveManager.Editor.asmdef b/Carter Games/Save Manager/Code/Editor/CarterGames.SaveManager.Editor.asmdef index afa955f..389158f 100644 --- a/Carter Games/Save Manager/Code/Editor/CarterGames.SaveManager.Editor.asmdef +++ b/Carter Games/Save Manager/Code/Editor/CarterGames.SaveManager.Editor.asmdef @@ -1,5 +1,5 @@ { - "name": "CarterGames.SaveManager.Editor", + "name": "CarterGames.Assets.SaveManager.Editor", "rootNamespace": "CarterGames.Assets.SaveManager.Editor", "references": [ "GUID:5fed357a0eb29414bb1d1667107777c5", diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Settings Provider/SaveManagerSettingsProvider.cs b/Carter Games/Save Manager/Code/Editor/Custom Editors/Settings Provider/SaveManagerSettingsProvider.cs index 4d7df3f..2ea3d48 100644 --- a/Carter Games/Save Manager/Code/Editor/Custom Editors/Settings Provider/SaveManagerSettingsProvider.cs +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Settings Provider/SaveManagerSettingsProvider.cs @@ -235,11 +235,23 @@ private static void DrawGeneralOptions() PerUserSettings.VersionValidationAutoCheckOnLoad); // Show Logs... - EditorGUILayout.PropertyField(SettingsAssetObject.Fp("showLogs"), Logs); + PerUserSettingsRuntime.ShowDebugLogs = EditorGUILayout.Toggle(Logs, PerUserSettingsRuntime.ShowDebugLogs); // Editor Only Setting.... PerUserSettings.ShowSaveKeys = EditorGUILayout.Toggle(SaveKeysToggle, PerUserSettings.ShowSaveKeys); + // Use save categories... + EditorGUI.BeginChangeCheck(); + + PerUserSettings.SaveEditorOrganiseByCategory = EditorGUILayout.Toggle(new GUIContent("Show Save Categories", + "Organises the save editor by category attribute [SaveCategory()]."), + PerUserSettings.SaveEditorOrganiseByCategory); + + if (EditorGUI.EndChangeCheck()) + { + SaveManagerEditorWindow.RequestRepaint.Raise(); + } + if (GUILayout.Button("Reset Settings")) { if (EditorUtility.DisplayDialog("Reset Save Manager Settings", @@ -247,7 +259,6 @@ private static void DrawGeneralOptions() "Reset Settings", "Cancel")) { PerUserSettings.ResetPrefs(); - // PerUserSettingsRuntime.ResetPrefs(); } } diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/SaveManagerEditorWindow.cs b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/SaveManagerEditorWindow.cs index 2c38639..2125e06 100644 --- a/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/SaveManagerEditorWindow.cs +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/SaveManagerEditorWindow.cs @@ -51,6 +51,9 @@ public sealed class SaveManagerEditorWindow : EditorWindow /// Raises when a new save object is added to the data. /// public static readonly Evt SaveObjectAddedToSaveData = new Evt(); + + + public static readonly Evt RequestRepaint = new Evt(); /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Window Access Method @@ -80,6 +83,8 @@ private void OnGUI() { Initialize(); + RequestRepaint.Add(Repaint); + EditorGUILayout.Space(17.5f); EditorGUI.BeginChangeCheck(); 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 c9711ae..d277515 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 @@ -10,11 +10,12 @@ public sealed class EditorTab /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Fields ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private const string DemoSaveObjectFullName = "CarterGames.Assets.SaveManager.Demo.ExampleSaveObject"; private Dictionary editorsLookup; private Dictionary soLookup; - private Dictionary demoLookup; - + private static Rect deselectRect; /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── @@ -25,9 +26,8 @@ public void Initialize() { soLookup = new Dictionary(); editorsLookup = new Dictionary(); - demoLookup = new Dictionary(); } - + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Draw Methods ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ @@ -35,7 +35,7 @@ public void Initialize() public void DrawTab(List saveObjects) { if (saveObjects.Count <= 0) return; - + if (Application.isPlaying) { EditorGUILayout.HelpBox( @@ -43,7 +43,8 @@ public void DrawTab(List saveObjects) MessageType.Info); } - PerUserSettings.SaveEditorTabScrollRectPos = EditorGUILayout.BeginScrollView(PerUserSettings.SaveEditorTabScrollRectPos); + PerUserSettings.SaveEditorTabScrollRectPos = + EditorGUILayout.BeginScrollView(PerUserSettings.SaveEditorTabScrollRectPos); foreach (var saveObj in saveObjects) { @@ -57,36 +58,21 @@ public void DrawTab(List saveObjects) { sObj = new SerializedObject(saveObj); } - - if (saveObj.GetType().FullName == "CarterGames.Assets.SaveManager.Demo.ExampleSaveObject") - { - if (demoLookup.ContainsKey(saveObj)) continue; - demoLookup.Add(saveObj, sObj); - } - else - { - if (soLookup.ContainsKey(saveObj)) continue; - soLookup.Add(saveObj, sObj); - } + + if (soLookup.ContainsKey(saveObj)) continue; + soLookup.Add(saveObj, sObj); } if (soLookup.Count > 0) { - DrawSaveObjects(" Save Objects", ref soLookup); + DrawSaveObjects(); } - - - if (demoLookup.Count > 0) - { - GUILayout.Space(12.5f); - DrawSaveObjects(" Demo Save Objects", ref demoLookup); - } - + EditorGUILayout.Space(5f); EditorGUILayout.EndScrollView(); - + // UtilEditor.CreateDeselectZone(ref deselectRect); } @@ -94,81 +80,145 @@ public void DrawTab(List saveObjects) /// /// Draws a collection of save objects. /// - /// The name for the section. - /// The lookup for the objects. - private void DrawSaveObjects(string sectionName, ref Dictionary lookup) + private void DrawSaveObjects() { - EditorGUILayout.LabelField(sectionName, EditorStyles.boldLabel); - - - foreach (var pair in lookup) + if (PerUserSettings.SaveEditorOrganiseByCategory) { - if (!editorsLookup.ContainsKey(pair.Key)) - { - editorsLookup.Add(pair.Key, (SaveObjectEditor) UnityEditor.Editor.CreateEditor(pair.Key)); - } - - - EditorGUILayout.BeginVertical(editorsLookup[pair.Key].serializedObject.Fp("isExpanded").boolValue ? "HelpBox" : "Box"); - - EditorGUILayout.BeginHorizontal(); - - EditorGUI.BeginChangeCheck(); - - editorsLookup[pair.Key].serializedObject.Fp("isExpanded").boolValue = - EditorGUILayout.Foldout(editorsLookup[pair.Key].serializedObject.Fp("isExpanded").boolValue, pair.Key.name); - - if (EditorGUI.EndChangeCheck()) + + var didHaveUncategorized = false; + var hasDrawnLine = false; + + + // Uncategorized Save Objects + /* ────────────────────────────────────────────────────────────────────────────────────────────────── */ + foreach (var saveObject in SaveCategoryAttributeHelper.GetObjectsInCategory("Uncategorized")) { - editorsLookup[pair.Key].serializedObject.ApplyModifiedProperties(); - editorsLookup[pair.Key].serializedObject.Update(); - - SaveManager.Save(); + if (saveObject.GetType().FullName == DemoSaveObjectFullName) continue; + DrawSaveObjectEditor(saveObject); + didHaveUncategorized = true; } - EditorGUI.BeginDisabledGroup(Application.isPlaying); - GUI.backgroundColor = UtilEditor.Red; - - if (GUILayout.Button("-", GUILayout.Width(25))) + + // Categorized Save Objects + /* ────────────────────────────────────────────────────────────────────────────────────────────────── */ + foreach (var category in SaveCategoryAttributeHelper.GetCategoryNames()) { - if (EditorUtility.DisplayDialog("Reset Save Object", - "Are you sure you want to reset all values on this save object?", "Reset", "Cancel")) + if (category.Equals("Uncategorized")) continue; + + var saveObjectsInCategory = SaveCategoryAttributeHelper.GetObjectsInCategory(category); + + EditorGUILayout.LabelField(category, EditorStyles.boldLabel); + + if (didHaveUncategorized && !hasDrawnLine && saveObjectsInCategory.Count > 0) { - // Reset Save Object - pair.Key.ResetObjectSaveValues(); - - editorsLookup[pair.Key].serializedObject.ApplyModifiedProperties(); - editorsLookup[pair.Key].serializedObject.Update(); - - SaveManager.Save(); - GUI.FocusControl(null); - - return; + UtilEditor.DrawHorizontalGUILine(); + hasDrawnLine = true; + } + + foreach (var saveObject in saveObjectsInCategory) + { + if (saveObject.GetType().FullName == DemoSaveObjectFullName) + continue; + DrawSaveObjectEditor(saveObject); } } + } + else + { + // Non-Categorized - But without demo save object. + /* ────────────────────────────────────────────────────────────────────────────────────────────────── */ + foreach (var objKp in soLookup) + { + if (objKp.Key.GetType().FullName == DemoSaveObjectFullName) continue; + DrawSaveObjectEditor(objKp.Key); + } + } + + + // Demo Save Object + /* ────────────────────────────────────────────────────────────────────────────────────────────────────── */ + var demoSaveObject = soLookup.FirstOrDefault(t => + t.Key.GetType().FullName == DemoSaveObjectFullName).Key; + + if (demoSaveObject == null) return; + + UtilEditor.DrawHorizontalGUILine(); + EditorGUILayout.LabelField("Asset Demo Save Object", EditorStyles.boldLabel); + DrawSaveObjectEditor(demoSaveObject); + } - GUI.backgroundColor = Color.white; - - EditorGUILayout.EndHorizontal(); - - GUILayout.Space(2.5f); - - if (editorsLookup[pair.Key].serializedObject.Fp("isExpanded").boolValue) + private void DrawSaveObjectEditor(SaveObject targetSaveObject) + { + if (!editorsLookup.ContainsKey(targetSaveObject)) + { + editorsLookup.Add(targetSaveObject, + (SaveObjectEditor)UnityEditor.Editor.CreateEditor(targetSaveObject)); + } + + EditorGUILayout.BeginVertical(editorsLookup[targetSaveObject].serializedObject.Fp("isExpanded").boolValue + ? "HelpBox" + : "Box"); + + EditorGUILayout.BeginHorizontal(); + + EditorGUI.BeginChangeCheck(); + + editorsLookup[targetSaveObject].serializedObject.Fp("isExpanded").boolValue = + EditorGUILayout.Foldout(editorsLookup[targetSaveObject].serializedObject.Fp("isExpanded").boolValue, + targetSaveObject.name); + + if (EditorGUI.EndChangeCheck()) + { + editorsLookup[targetSaveObject].serializedObject.ApplyModifiedProperties(); + editorsLookup[targetSaveObject].serializedObject.Update(); + + SaveManager.Save(); + } + + EditorGUI.BeginDisabledGroup(Application.isPlaying); + GUI.backgroundColor = UtilEditor.Red; + + if (GUILayout.Button("-", GUILayout.Width(25))) + { + if (EditorUtility.DisplayDialog("Reset Save Object", + "Are you sure you want to reset all values on this save object?", "Reset", "Cancel")) { - editorsLookup[pair.Key].EditorWindowGUI(); - GUILayout.Space(1.5f); + // Reset Save Object + targetSaveObject.ResetObjectSaveValues(); + + editorsLookup[targetSaveObject].serializedObject.ApplyModifiedProperties(); + editorsLookup[targetSaveObject].serializedObject.Update(); + + SaveManager.Save(); + GUI.FocusControl(null); + + return; } - - EditorGUI.EndDisabledGroup(); - - EditorGUILayout.EndVertical(); - - GUILayout.Space(4f); } + + GUI.backgroundColor = Color.white; + + EditorGUILayout.EndHorizontal(); + + GUILayout.Space(2.5f); + + + if (editorsLookup[targetSaveObject].serializedObject.Fp("isExpanded").boolValue) + { + editorsLookup[targetSaveObject].EditorWindowGUI(); + GUILayout.Space(1.5f); + } + + EditorGUI.EndDisabledGroup(); + + EditorGUILayout.EndVertical(); + + GUILayout.Space(4f); } + public void RepaintAll() { foreach (var keyPair in editorsLookup) diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Attributes.meta b/Carter Games/Save Manager/Code/Editor/Systems/Attributes.meta new file mode 100644 index 0000000..9cb35d5 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Systems/Attributes.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b71418a5236241868e712607da0f9a0b +timeCreated: 1704017867 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeData.cs b/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeData.cs new file mode 100644 index 0000000..f9aca30 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeData.cs @@ -0,0 +1,70 @@ +using System; +using UnityEngine; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// Handles the data for a save category to be processed. + /// + [Serializable] + public sealed class SaveCategoryAttributeData + { + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Fields + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + [SerializeField, HideInInspector] private string categoryName; + [SerializeField, HideInInspector] private int orderInCategory; + [SerializeField] private SaveObject saveObject; + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Properties + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + /// + /// The name of the category. + /// + public string CategoryName => categoryName; + + + /// + /// The order it should be shown in the category. + /// + public int OrderInCategory => orderInCategory; + + + /// + /// The save object the category applies to. + /// + public SaveObject SaveObject => saveObject; + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Constructors + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + /// + /// A new attribute data for the entered save object. + /// + /// The object to use. + public SaveCategoryAttributeData(SaveObject saveObject) + { + categoryName = "Uncategorized"; + orderInCategory = 0; + this.saveObject = saveObject; + } + + + /// + /// A new attribute data for the entered save object. + /// + /// The category to sort into. + /// The order to apply for the object in the category. + /// The object to use. + public SaveCategoryAttributeData(string categoryName, int order, SaveObject saveObject) + { + this.categoryName = categoryName; + orderInCategory = order; + this.saveObject = saveObject; + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeData.cs.meta b/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeData.cs.meta new file mode 100644 index 0000000..f869703 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ca3ff55b06f741fe95c680e79c710fff +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/Attributes/SaveCategoryAttributeHelper.cs b/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeHelper.cs new file mode 100644 index 0000000..df85e03 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeHelper.cs @@ -0,0 +1,84 @@ +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// A helper class to get the save objects in their categories via reflection. + /// + public static class SaveCategoryAttributeHelper + { + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Fields + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private const string SaveObjectAndCategoryName = "CarterGames.Assets.SaveManager.SaveObject+SaveCategoryAttribute"; + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Methods + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + /// + /// Handles getting all the save objects with categories and putting those without into their own category. + /// + /// The data ready for use. + private static IEnumerable GetObjectsWithCategory() + { + var saveObjects = AssetAccessor.GetAsset().Data; + var data = new List(); + + foreach (var saveObj in saveObjects) + { + var attributes = saveObj.GetType().GetCustomAttributes(); + + if (!attributes.Any(t => t.ToString().Equals(SaveObjectAndCategoryName))) + { + data.Add(new SaveCategoryAttributeData(saveObj)); + continue; + } + + var category = attributes.First(t => t.ToString().Equals(SaveObjectAndCategoryName)); + + var categoryName = category.GetType() + .GetField("Category", BindingFlags.Public | BindingFlags.Instance)?.GetValue(category).ToString(); + + var order = int.Parse(category.GetType() + .GetField("OrderInCategory", BindingFlags.Public | BindingFlags.Instance)?.GetValue(category).ToString() ?? string.Empty); + + data.Add(new SaveCategoryAttributeData(categoryName, order, saveObj)); + } + + return data; + } + + + /// + /// Gets all the save objects in the category named. + /// + /// The category to look for. + /// A list of save objects in that category ordered correctly. + public static List GetObjectsInCategory(string categoryName) + { + return GetObjectsWithCategory() + .Where(t => t.CategoryName.Equals(categoryName)) + .OrderByDescending(t => t.OrderInCategory) + .Select(t => t.SaveObject) + .ToList(); + } + + + /// + /// Gets a list of all the defined save categories. + /// + /// The categories currently defined. + public static List GetCategoryNames() + { + return GetObjectsWithCategory() + .OrderBy(t => t.CategoryName) + .Select(t => t.CategoryName) + .Distinct() + .ToList(); + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeHelper.cs.meta b/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeHelper.cs.meta new file mode 100644 index 0000000..8abffbc --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Systems/Attributes/SaveCategoryAttributeHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f7bb8b817b624202ad93acca6ee31a88 +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/AssetVersionData.cs b/Carter Games/Save Manager/Code/Editor/Utility/AssetVersionData.cs index ed71c80..5a92ce8 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/AssetVersionData.cs +++ b/Carter Games/Save Manager/Code/Editor/Utility/AssetVersionData.cs @@ -31,7 +31,7 @@ public static class AssetVersionData /// /// The version number of the asset. /// - public static string VersionNumber => "2.0.16"; + public static string VersionNumber => "2.1.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 => "24/12/2023"; + public static string ReleaseDate => "01/01/2024"; } } \ No newline at end of file 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 3cea320..78425d1 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 @@ -55,6 +55,8 @@ public static class PerUserSettings private static readonly string SaveEditorTabScrollRectPosId = $"{UniqueId}_CarterGames_SaveManager_EditorSettings_EditorTabScrollRectPos"; private static readonly string SaveProfileTabScrollRectPosId = $"{UniqueId}_CarterGames_SaveManager_EditorSettings_ProfileTabScrollRectPos"; + + private static readonly string SaveEditorOrganiseByCategoryId = $"{UniqueId}_CarterGames_SaveManager_EditorSettings_OrganiseByCategory"; /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Properties @@ -63,6 +65,9 @@ public static class PerUserSettings /// /// The unique if for the assets settings to be per project... /// + /// + /// Saved to player pref to allow settings to be different per project in the same editor version. + /// private static string UniqueId => (string)GetOrCreateValue(UniqueIdId, SettingType.PlayerPref, Guid.NewGuid().ToString()); @@ -71,7 +76,7 @@ public static class PerUserSettings /// public static bool VersionValidationAutoCheckOnLoad { - get => (bool) GetOrCreateValue(AutoValidationAutoCheckId, SettingType.EditorPref); + get => (bool) GetOrCreateValue(AutoValidationAutoCheckId, SettingType.EditorPref, true); set => SetValue(AutoValidationAutoCheckId, SettingType.EditorPref, value); } @@ -189,6 +194,13 @@ public static Vector2 SaveProfileTabScrollRectPos set => SetValue(SaveProfileTabScrollRectPosId, SettingType.EditorPref, value); } + + public static bool SaveEditorOrganiseByCategory + { + get => (bool)GetOrCreateValue(SaveEditorOrganiseByCategoryId, SettingType.EditorPref, true); + set => SetValue(SaveEditorOrganiseByCategoryId, SettingType.EditorPref, value); + } + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Methods ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ @@ -403,6 +415,7 @@ public static void ResetPrefs() LastSaveObjectName = string.Empty; LastSaveObjectFileName = string.Empty; JustCreatedSaveObject = false; + SaveEditorOrganiseByCategory = true; } } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Runtime/CarterGames.SaveManager.Runtime.asmdef b/Carter Games/Save Manager/Code/Runtime/CarterGames.SaveManager.Runtime.asmdef index 6f6976c..67db39d 100644 --- a/Carter Games/Save Manager/Code/Runtime/CarterGames.SaveManager.Runtime.asmdef +++ b/Carter Games/Save Manager/Code/Runtime/CarterGames.SaveManager.Runtime.asmdef @@ -1,5 +1,5 @@ { - "name": "CarterGames.SaveManager.Runtime", + "name": "CarterGames.Assets.SaveManager.Runtime", "rootNamespace": "CarterGames.Assets.SaveManager", "references": [ "GUID:0dd839a085d98c5478abb31237806e7c" diff --git a/Carter Games/Save Manager/Code/Runtime/Data/SettingsAssetRuntime.cs b/Carter Games/Save Manager/Code/Runtime/Data/SettingsAssetRuntime.cs index 477980d..0040303 100644 --- a/Carter Games/Save Manager/Code/Runtime/Data/SettingsAssetRuntime.cs +++ b/Carter Games/Save Manager/Code/Runtime/Data/SettingsAssetRuntime.cs @@ -48,7 +48,6 @@ public sealed class SettingsAssetRuntime : SaveManagerAsset [SerializeField] private bool prettify; [SerializeField] private bool autoLoadOnEntry = true; [SerializeField] private bool autoSaveOnExit = true; - [SerializeField] private bool showLogs; /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Properties @@ -106,12 +105,6 @@ public SaveData SaveData public EncryptionOption Encryption => encryptionOption; - /// - /// Defines if the asset will throw log messages at you or not. - /// - public bool ShowLogs => showLogs; - - /// /// Defines if the json formatting is laid out nicely or not. /// diff --git a/Carter Games/Save Manager/Code/Runtime/Logger/SmLog.cs b/Carter Games/Save Manager/Code/Runtime/Logger/SmLog.cs index 7f1277b..30e8caa 100644 --- a/Carter Games/Save Manager/Code/Runtime/Logger/SmLog.cs +++ b/Carter Games/Save Manager/Code/Runtime/Logger/SmLog.cs @@ -45,7 +45,7 @@ public static class SmLog /// /// Gets if the logs should be shown. /// - private static bool ShowLogs => AssetAccessor.GetAsset().ShowLogs; + private static bool ShowLogs => PerUserSettingsRuntime.ShowDebugLogs; /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Methods diff --git a/Carter Games/Save Manager/Code/Runtime/Save Data/Objects/SaveObject.cs b/Carter Games/Save Manager/Code/Runtime/Save Data/Objects/SaveObject.cs index 290c190..31fcce2 100644 --- a/Carter Games/Save Manager/Code/Runtime/Save Data/Objects/SaveObject.cs +++ b/Carter Games/Save Manager/Code/Runtime/Save Data/Objects/SaveObject.cs @@ -60,7 +60,7 @@ public Dictionary Lookup get { if (lookupCache is { } && lookupCache.Count > 0) return lookupCache; - lookupCache = GetSaveValue(); + lookupCache = GetSaveValues(); return lookupCache; } } @@ -156,7 +156,7 @@ public virtual void ResetObjectSaveValues() /// Gets the save values on this object. /// /// A dictionary as an object. - public virtual SerializableDictionary GetSaveValue() + public virtual SerializableDictionary GetSaveValues() { var dic = new SerializableDictionary(); @@ -229,5 +229,39 @@ public void ResetElement(string key) if (!Lookup.ContainsKey(key)) return; Lookup[key].ResetValue(); } + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Save Object Attributes + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + /// + /// Defines the save category of a save object. Cannot be applied to any other class except save objects. + /// + [AttributeUsage(AttributeTargets.Class)] + protected sealed class SaveCategoryAttribute : Attribute + { + /// + /// The name of the category to use. + /// + public string Category; + + + /// + /// The order of the object in the category. + /// + public int OrderInCategory; + + + /// + /// Defines a save category with the entered value. + /// + /// The name of the category to use. + /// The order of the object in the category. Def = 0. + public SaveCategoryAttribute(string category, int order = 0) + { + Category = category; + OrderInCategory = order; + } + } } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Runtime/Save Data/SaveData.cs b/Carter Games/Save Manager/Code/Runtime/Save Data/SaveData.cs index 4d68668..129bfb8 100644 --- a/Carter Games/Save Manager/Code/Runtime/Save Data/SaveData.cs +++ b/Carter Games/Save Manager/Code/Runtime/Save Data/SaveData.cs @@ -67,7 +67,7 @@ public SerializableDictionary> Se foreach (var saveValue in Data) { - var data = saveValue.GetSaveValue(); + var data = saveValue.GetSaveValues(); var converted = new SerializableDictionary(); diff --git a/Carter Games/Save Manager/Code/Runtime/SaveManager.cs b/Carter Games/Save Manager/Code/Runtime/SaveManager.cs index a37aebf..ba80adb 100644 --- a/Carter Games/Save Manager/Code/Runtime/SaveManager.cs +++ b/Carter Games/Save Manager/Code/Runtime/SaveManager.cs @@ -314,7 +314,7 @@ public static void ProcessLoadedData(SerializableDictionary GetSaveValuesLookup(string if (!SaveDataLookup.ContainsKey(saveKey)) return null; - var d = SaveDataLookup[saveKey].GetSaveValue(); + var d = SaveDataLookup[saveKey].GetSaveValues(); var converted = new SerializableDictionary(); foreach (var pair in d) @@ -599,7 +599,7 @@ public static void UpdateAndSaveObject(SaveObject saveObject) if (!TryGetSaveValuesLookup(saveObject.SaveKey, out var data)) return; - var d = saveObject.GetSaveValue(); + var d = saveObject.GetSaveValues(); var converted = new SerializableDictionary(); foreach (var pair in d) diff --git a/Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime.meta b/Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime.meta new file mode 100644 index 0000000..ffd4d19 --- /dev/null +++ b/Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 187bf7d525e74e6cb8ec8538bfa005dc +timeCreated: 1704034711 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime/PerUserSettingsRuntime.cs b/Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime/PerUserSettingsRuntime.cs new file mode 100644 index 0000000..1aff5de --- /dev/null +++ b/Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime/PerUserSettingsRuntime.cs @@ -0,0 +1,109 @@ +using UnityEngine; + +namespace CarterGames.Assets.SaveManager +{ + /// + /// Handles the per user settings that are for runtime use. + /// + public static class PerUserSettingsRuntime + { + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Fields + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static readonly string DebugLogId = "CarterGames_SaveManager_Settings_ShowDebugLogs"; + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Properties + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + /// + /// Should the asset show the debug logs. + /// + public static bool ShowDebugLogs + { + get => (bool) GetOrCreateValue(DebugLogId, true); + set => SetValue(DebugLogId, value); + } + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Methods + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static object GetOrCreateValue(string key, object defaultValue = null) + { + if (PlayerPrefs.HasKey(key)) + { + switch (typeof(T)) + { + case var x when x == typeof(bool): + return PlayerPrefs.GetInt(key) == 1; + case var x when x == typeof(int): + return PlayerPrefs.GetInt(key); + case var x when x == typeof(float): + return PlayerPrefs.GetFloat(key); + case var x when x == typeof(string): + return PlayerPrefs.GetString(key); + case var x when x == typeof(Vector2): + return JsonUtility.FromJson(PlayerPrefs.GetString(key)); + default: + return null; + } + } + + switch (typeof(T)) + { + case var x when x == typeof(bool): + PlayerPrefs.SetInt(key, defaultValue == null ? 0 : defaultValue.ToString().ToLower() == "true" ? 1 : 0); + return PlayerPrefs.GetInt(key) == 1; + case var x when x == typeof(int): + PlayerPrefs.SetInt(key, defaultValue == null ? 0 : (int) defaultValue); + return PlayerPrefs.GetInt(key); + case var x when x == typeof(float): + PlayerPrefs.SetFloat(key, defaultValue == null ? 0 : (float) defaultValue); + return PlayerPrefs.GetFloat(key); + case var x when x == typeof(string): + PlayerPrefs.SetString(key, (string) defaultValue); + return PlayerPrefs.GetString(key); + case var x when x == typeof(Vector2): + PlayerPrefs.SetString(key, defaultValue == null ? JsonUtility.ToJson(Vector2.zero) : JsonUtility.ToJson(defaultValue)); + return JsonUtility.FromJson(PlayerPrefs.GetString(key)); + default: + return null; + } + } + + + private static void SetValue(string key, object value) + { + switch (typeof(T)) + { + case var x when x == typeof(bool): + PlayerPrefs.SetInt(key, ((bool)value) ? 1 : 0); + break; + case var x when x == typeof(int): + PlayerPrefs.SetInt(key, (int)value); + break; + case var x when x == typeof(float): + PlayerPrefs.SetFloat(key, (float)value); + break; + case var x when x == typeof(string): + PlayerPrefs.SetString(key, (string)value); + break; + case var x when x == typeof(Vector2): + PlayerPrefs.SetString(key, JsonUtility.ToJson(value)); + break; + default: + break; + } + + PlayerPrefs.Save(); + } + + + public static void ResetPrefs() + { + ShowDebugLogs = true; + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime/PerUserSettingsRuntime.cs.meta b/Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime/PerUserSettingsRuntime.cs.meta new file mode 100644 index 0000000..5c33c6e --- /dev/null +++ b/Carter Games/Save Manager/Code/Runtime/Utility/Per User Settings Runtime/PerUserSettingsRuntime.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 62b71687f98847d89873028acdf6193c +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/Runtime/Utility/Perf Settings.meta b/Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings.meta new file mode 100644 index 0000000..318c740 --- /dev/null +++ b/Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6981afd490294595904d2424885612fc +timeCreated: 1704036270 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Runtime/Utility/PrefSetting.cs b/Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings/PrefSetting.cs similarity index 100% rename from Carter Games/Save Manager/Code/Runtime/Utility/PrefSetting.cs rename to Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings/PrefSetting.cs diff --git a/Carter Games/Save Manager/Code/Runtime/Utility/PrefSetting.cs.meta b/Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings/PrefSetting.cs.meta similarity index 100% rename from Carter Games/Save Manager/Code/Runtime/Utility/PrefSetting.cs.meta rename to Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings/PrefSetting.cs.meta diff --git a/Carter Games/Save Manager/Code/Runtime/Utility/PrefUseOption.cs b/Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings/PrefUseOption.cs similarity index 100% rename from Carter Games/Save Manager/Code/Runtime/Utility/PrefUseOption.cs rename to Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings/PrefUseOption.cs diff --git a/Carter Games/Save Manager/Code/Runtime/Utility/PrefUseOption.cs.meta b/Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings/PrefUseOption.cs.meta similarity index 100% rename from Carter Games/Save Manager/Code/Runtime/Utility/PrefUseOption.cs.meta rename to Carter Games/Save Manager/Code/Runtime/Utility/Perf Settings/PrefUseOption.cs.meta