diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6d286c1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# 2.2.0 +## Asset changes + +- Added support for git URL importing of the asset over .unityPackage. This is considered the recommended install method going forward for ease of updates etc. +- Added porting tool to transfer user asset settings to the new location required for the git URL update. +- Updated scriptable asset flow with the latest from the cart library which is more modular and easy to use on the backend. +- Some additional helper classes for more performant editor operations from within the asset. \ No newline at end of file diff --git a/CHANGELOG.md.meta b/CHANGELOG.md.meta new file mode 100644 index 0000000..10ad390 --- /dev/null +++ b/CHANGELOG.md.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 04fbb2653bde40d68dce25537e636b84 +timeCreated: 1726417832 \ No newline at end of file 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 389158f..afa955f 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.Assets.SaveManager.Editor", + "name": "CarterGames.SaveManager.Editor", "rootNamespace": "CarterGames.Assets.SaveManager.Editor", "references": [ "GUID:5fed357a0eb29414bb1d1667107777c5", diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Inspectors/SaveManagerAssetIndexInspector.cs b/Carter Games/Save Manager/Code/Editor/Custom Editors/Inspectors/SaveManagerAssetIndexInspector.cs index d777cde..fefa903 100644 --- a/Carter Games/Save Manager/Code/Editor/Custom Editors/Inspectors/SaveManagerAssetIndexInspector.cs +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Inspectors/SaveManagerAssetIndexInspector.cs @@ -95,7 +95,7 @@ private void DrawAllReferencesSection() EditorGUI.indentLevel++; EditorGUI.BeginDisabledGroup(Application.isPlaying); - EditorGUILayout.PropertyField(serializedObject.Fp("assets")); + EditorGUILayout.PropertyField(serializedObject.Fp("assets").Fpr("list")); EditorGUI.EndDisabledGroup(); EditorGUI.indentLevel--; diff --git a/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/Sub Windows/Profile Tab/SaveProfileListGUI.cs b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/Sub Windows/Profile Tab/SaveProfileListGUI.cs index cdaf50e..acc3012 100644 --- a/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/Sub Windows/Profile Tab/SaveProfileListGUI.cs +++ b/Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Editor Window/Sub Windows/Profile Tab/SaveProfileListGUI.cs @@ -199,7 +199,7 @@ private static void LoadSaveProfile(TextAsset data) // Null Data if (data == null) { - SmLog.Normal("No data found in the profile, so nothing was loaded."); + SaveManagerLogger.Log("No data found in the profile, so nothing was loaded."); return; } @@ -214,7 +214,7 @@ private static void LoadSaveProfile(TextAsset data) } catch (Exception e) { - SmLog.Error($"Failed to read to {UtilEditor.AssetGlobalRuntimeSettings.SavePath} with the exception: {e}"); + SaveManagerLogger.LogError($"Failed to read to {UtilEditor.AssetGlobalRuntimeSettings.SavePath} with the exception: {e}"); return; } diff --git a/Carter Games/Save Manager/Code/Editor/Info.meta b/Carter Games/Save Manager/Code/Editor/Info.meta new file mode 100644 index 0000000..2297cf2 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Info.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5d002c8a1145412ca8d6350792f58f43 +timeCreated: 1726862174 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/AssetVersionData.cs b/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs similarity index 93% rename from Carter Games/Save Manager/Code/Editor/Utility/AssetVersionData.cs rename to Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs index 5cc6e3d..e58d0c7 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/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.1.8"; + public static string VersionNumber => "2.2.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 => "20/05/2024"; + public static string ReleaseDate => "2024/09/27"; } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/AssetVersionData.cs.meta b/Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs.meta similarity index 100% rename from Carter Games/Save Manager/Code/Editor/Utility/AssetVersionData.cs.meta rename to Carter Games/Save Manager/Code/Editor/Info/AssetVersionData.cs.meta 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 51cb694..d51989f 100644 --- a/Carter Games/Save Manager/Code/Editor/Settings Provider/SaveManagerSettingsProvider.cs +++ b/Carter Games/Save Manager/Code/Editor/Settings Provider/SaveManagerSettingsProvider.cs @@ -94,7 +94,7 @@ private static SerializedObject SettingsAssetObject [MenuItem("Tools/Carter Games/Save Manager/Edit Settings", priority = 0)] public static void OpenSettings() { - SettingsService.OpenProjectSettings("Project/Carter Games/Save Manager"); + SettingsService.OpenProjectSettings("Carter Games/Assets/Save Manager"); } /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Initialize/AssetInitializer.cs b/Carter Games/Save Manager/Code/Editor/Systems/Initialize/AssetInitializer.cs index 746f254..e104d3f 100644 --- a/Carter Games/Save Manager/Code/Editor/Systems/Initialize/AssetInitializer.cs +++ b/Carter Games/Save Manager/Code/Editor/Systems/Initialize/AssetInitializer.cs @@ -82,7 +82,7 @@ private static void TryInitialize() /// private static async void InitializeEditorClasses() { - var initClasses = InterfaceHelper.GetAllInterfacesInstancesOfType(); + var initClasses = AssemblyHelper.GetClassesOfType().ToArray(); if (initClasses.Length > 0) { diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Initialize/AssetReloadHandler.cs b/Carter Games/Save Manager/Code/Editor/Systems/Initialize/AssetReloadHandler.cs index 3c7ebe4..0697c74 100644 --- a/Carter Games/Save Manager/Code/Editor/Systems/Initialize/AssetReloadHandler.cs +++ b/Carter Games/Save Manager/Code/Editor/Systems/Initialize/AssetReloadHandler.cs @@ -21,6 +21,7 @@ * THE SOFTWARE. */ +using System.Linq; using System.Threading.Tasks; using CarterGames.Common; using UnityEditor; @@ -69,7 +70,7 @@ private static void FireReloadCalls() /// private static async void CallListeners() { - var reloadClasses = InterfaceHelper.GetAllInterfacesInstancesOfType(); + var reloadClasses = AssemblyHelper.GetClassesOfType().ToArray(); if (reloadClasses.Length > 0) { diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Save Profiles/SaveProfilesStore.cs b/Carter Games/Save Manager/Code/Editor/Systems/Save Profiles/SaveProfilesStore.cs index 8eeb8ed..15c6d60 100644 --- a/Carter Games/Save Manager/Code/Editor/Systems/Save Profiles/SaveProfilesStore.cs +++ b/Carter Games/Save Manager/Code/Editor/Systems/Save Profiles/SaveProfilesStore.cs @@ -29,7 +29,7 @@ namespace CarterGames.Assets.SaveManager.Editor { [Serializable] [CreateAssetMenu(fileName = "Save Profile Store", menuName = "Carter Games/Save Manager/Save Profile Store", order = 6)] - public sealed class SaveProfilesStore : ScriptableObject + public sealed class SaveProfilesStore : SaveManagerAsset { [SerializeField] private List profiles; diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/InstallMethodChecker.cs b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/InstallMethodChecker.cs new file mode 100644 index 0000000..eda0dbd --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/InstallMethodChecker.cs @@ -0,0 +1,93 @@ +/* + * 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 NONINFRINGEMENT. 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 UnityEditor.PackageManager; +using UnityEditor.PackageManager.Requests; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// A class to help redirect the user to the right update location for the asset. In theory... + /// + public sealed class InstallMethodChecker : IAssetEditorInitialize + { + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Methods + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static ListRequest PackageManifestRequest { get; set; } + + + private static bool HasChecked + { + get => SessionState.GetBool("VersionValidation_InstallMethod_Checked", false); + set => SessionState.SetBool("VersionValidation_InstallMethod_Checked", value); + } + + + public static bool IsPackageInstalled + { + get => SessionState.GetBool("VersionValidation_InstallMethod_IsPackageManager", false); + set => SessionState.SetBool("VersionValidation_InstallMethod_IsPackageManager", value); + } + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | IAssetEditorInitialize Implementation + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + public int InitializeOrder { get; } + + + public void OnEditorInitialized() + { + if (HasChecked) return; + + PackageManifestRequest = Client.List(); + + EditorApplication.update -= OnPackageManagerGetResolved; + EditorApplication.update += OnPackageManagerGetResolved; + } + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Methods + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static void OnPackageManagerGetResolved() + { + if (!PackageManifestRequest.IsCompleted) return; + + EditorApplication.update -= OnPackageManagerGetResolved; + + if (PackageManifestRequest.Status != StatusCode.Success) return; + + HasChecked = true; + + foreach (var result in PackageManifestRequest.Result) + { + if (result.packageId.Equals("games.carter.thecart")) continue; + IsPackageInstalled = true; + } + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/InterfaceHelper.cs.meta b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/InstallMethodChecker.cs.meta similarity index 86% rename from Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/InterfaceHelper.cs.meta rename to Carter Games/Save Manager/Code/Editor/Systems/Version Validator/InstallMethodChecker.cs.meta index aeb9caa..d3ed8f8 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/InterfaceHelper.cs.meta +++ b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/InstallMethodChecker.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 8be781c060ce41e18bc659ba153fe286 +guid: 203a0cc55316276498f0e7eb5b2a778e MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionAutoCheck.cs b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionAutoCheck.cs index b900288..923d9d5 100644 --- a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionAutoCheck.cs +++ b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionAutoCheck.cs @@ -1,20 +1,20 @@ /* * 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 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 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 diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionChecker.cs b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionChecker.cs index 6214808..0e7733a 100644 --- a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionChecker.cs +++ b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionChecker.cs @@ -1,20 +1,20 @@ /* * 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 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 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 diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionData.cs b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionData.cs index 29c46e7..4abb3a9 100644 --- a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionData.cs +++ b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionData.cs @@ -1,20 +1,20 @@ /* * 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 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 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 @@ -90,14 +90,12 @@ public string ReleaseDate /// If the entry is a match or not on all values (major/minor/patch). public bool Match(string toCompare) { - var current = VersionNumber; - var remote = new VersionNumber(toCompare); + var aVN = VersionNumber; + var bVN = new VersionNumber(toCompare); - return current.Major.Equals(remote.Major) && - current.Minor.Equals(remote.Minor) && - current.Patch.Equals(remote.Patch); + return aVN.Major.Equals(bVN.Major) && aVN.Minor.Equals(bVN.Minor) && aVN.Patch.Equals(bVN.Patch); } - + /// /// Gets if the entry is a higher version than the converted version. @@ -106,20 +104,15 @@ public bool Match(string toCompare) /// If the entry is greater on any (major/minor/patch) value. public bool IsHigherVersion(string toCompare) { - var current = VersionNumber; - var remote = new VersionNumber(toCompare); + var aVN = VersionNumber; + var bVN = new VersionNumber(toCompare); if (Match(toCompare)) { return false; } - if (current.Major < remote.Major) return true; - if (current.Major.Equals(remote.Major) && current.Minor < remote.Minor) return true; - - return current.Major.Equals(remote.Major) && - current.Minor.Equals(remote.Minor) && - current.Patch < remote.Patch; + return (aVN.Major < bVN.Major) || (aVN.Minor < bVN.Minor) || (aVN.Patch < bVN.Patch); } } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionEditorGUI.cs b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionEditorGUI.cs index aebe569..bacbf73 100644 --- a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionEditorGUI.cs +++ b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionEditorGUI.cs @@ -1,20 +1,20 @@ /* * 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 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 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 @@ -56,15 +56,6 @@ public static void ShowResponseDialogue(bool showIfUptoDate = true) { VersionChecker.ResponseReceived.RemoveAnonymous("versionCheckManual"); - if (VersionChecker.Versions.Data == null) - { - EditorUtility.DisplayDialog("Update Checker", - $"Either you are offline or the system for version checking is broken or missing an entry.", - "Continue"); - - return; - } - if (VersionChecker.IsNewerVersion) { if (!showIfUptoDate) return; @@ -74,16 +65,26 @@ public static void ShowResponseDialogue(bool showIfUptoDate = true) } else if (!VersionChecker.IsLatestVersion) { - if (EditorUtility.DisplayDialog("Update Checker", - $"You are using an older version of this package.\n\nCurrent: {VersionInfo.ProjectVersionNumber}\nLatest: {VersionChecker.LatestVersionNumberString}", - "Latest Release", "Continue")) + if (InstallMethodChecker.IsPackageInstalled) + { + EditorUtility.DisplayDialog("Update Checker", + $"You are using an older version of this package.\n\nCurrent: {VersionInfo.ProjectVersionNumber}\nLatest: {VersionChecker.LatestVersionNumberString}\n\nYou can get the latest release from the package manager.", + "Continue"); + } + else { - Application.OpenURL(VersionChecker.DownloadURL); + if (EditorUtility.DisplayDialog("Update Checker", + $"You are using an older version of this package.\n\nCurrent: {VersionInfo.ProjectVersionNumber}\nLatest: {VersionChecker.LatestVersionNumberString}", + "Latest Release", "Continue")) + { + Application.OpenURL(VersionChecker.DownloadURL); + } } } else { if (!showIfUptoDate) return; + EditorUtility.DisplayDialog("Update Checker", "You are using the latest version!", "Continue"); diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionNumber.cs b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionNumber.cs index d54992c..b2012bb 100644 --- a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionNumber.cs +++ b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionNumber.cs @@ -1,20 +1,20 @@ /* * 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 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 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 diff --git a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionPacket.cs b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionPacket.cs index 744b8cc..83be7e9 100644 --- a/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionPacket.cs +++ b/Carter Games/Save Manager/Code/Editor/Systems/Version Validator/VersionPacket.cs @@ -1,20 +1,20 @@ /* * 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 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 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 @@ -46,6 +46,6 @@ public sealed class VersionPacket /// /// The data received for this package. /// - public VersionData Data => data.FirstOrDefault(t => t.Key.Equals(VersionInfo.Key)); + public VersionData Data => data.First(t => t.Key.Equals(VersionInfo.Key)); } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/AssetDatabaseHelper.cs b/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/AssetDatabaseHelper.cs new file mode 100644 index 0000000..3477ddd --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/AssetDatabaseHelper.cs @@ -0,0 +1,125 @@ +/* + * 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 NONINFRINGEMENT. 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.Collections.Generic; +using System.Linq; +using UnityEditor; + +namespace CarterGames.Assets.SaveManager.Editor +{ + public static class AssetDatabaseHelper + { + /// + /// Gets if asset database can find an asset at the defined path. + /// + /// The path top find. + /// The type to try and get. + /// If the asset exists in the asset database. + public static bool FileIsInProject(string path) where T : SaveManagerAsset + { + if (string.IsNullOrEmpty(path)) return false; + return AssetDatabase.LoadAssetAtPath(path, typeof(T)) != null; + } + + + + /// + /// Gets the string paths for any asset of the type not in the expected location. + /// + /// The path the asset should be at. + /// The type to check for. + /// The paths for any asset not where it should be. + public static IEnumerable GetAssetPathNotAtPath(string expectedPath) where T : SaveManagerAsset + { + if (TryGetPathsToAssetsNotAtPath(expectedPath, out var result)) + { + return result; + } + + return null; + } + + + /// + /// Returns if an instance of the asset type is not where it should be. + /// + /// The path it should be at. + /// The type to try and get. + /// If the asset correctly exists in the asset database. + public static bool TypeExistsElsewhere(string expectedPath) where T : SaveManagerAsset + { + return TryGetTypeNotAtPath(expectedPath, out _); + } + + + /// + /// A helper method to get assets of a type not at the expected path. + /// + /// The path the asset should be at. + /// The result of the operation. + /// The type to try and get. + /// If it was successful at finding any assets at the wrong path. + private static bool TryGetTypeNotAtPath(string expectedPath, out IEnumerable result) where T : SaveManagerAsset + { + if (!TryGetPathsToAssetsNotAtPath(expectedPath, out var paths)) + { + result = null; + return false; + } + + result = paths.Select(t => AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(t))); + return true; + } + + + /// + /// A helper method to get paths of any asset of a type not at the expected path. + /// + /// The path the asset should be at. + /// The result of the operation. + /// The type to try and get. + /// If it was successful at finding any assets at the wrong path. + private static bool TryGetPathsToAssetsNotAtPath(string expectedPath, out IEnumerable result) where T : SaveManagerAsset + { + result = null; + + if (string.IsNullOrEmpty(expectedPath)) return false; + var assets = AssetDatabase.FindAssets($"t:{typeof(T).FullName}"); + + if (assets.Length <= 1) + { + if (AssetDatabase.GUIDToAssetPath(assets.First()) == expectedPath) return false; + + result = new string[1] + { + AssetDatabase.GUIDToAssetPath(assets.First()) + }; + + return true; + } + + result = assets.Where(t => AssetDatabase.GUIDToAssetPath(t) != expectedPath).Select(AssetDatabase.GUIDToAssetPath); + return true; + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/AssetDatabaseHelper.cs.meta b/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/AssetDatabaseHelper.cs.meta new file mode 100644 index 0000000..4655f55 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/AssetDatabaseHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: adfc469878234224ba5edd8c79398d63 +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/Editor Method Aid/SerializedPropertyHelper.cs b/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/SerializedPropertyHelper.cs index 945441e..89fe7b2 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/SerializedPropertyHelper.cs +++ b/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/SerializedPropertyHelper.cs @@ -86,5 +86,30 @@ public static SerializedProperty Fpr(this SerializedProperty property, string pr { return property.FindPropertyRelative(propName); } + + + /// + /// Copies data from one instance of an asset to another. + /// + /// The asset to read from. + /// The asset to assign to. + public static void TransferProperties(SerializedObject read, SerializedObject target) + { + var dest = target; + var propIterator = read.GetIterator(); + + if (propIterator.NextVisible(true)) + { + while (propIterator.NextVisible(true)) + { + var propElement = dest.FindProperty(propIterator.name); + + if (propElement == null || propElement.propertyType != propIterator.propertyType) continue; + dest.CopyFromSerializedProperty(propIterator); + } + } + + dest.ApplyModifiedProperties(); + } } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Porting.meta b/Carter Games/Save Manager/Code/Editor/Utility/Porting.meta new file mode 100644 index 0000000..fb19c76 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Porting.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 28234908f9cf44af98492645fe380c11 +timeCreated: 1726411760 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Porting/SaveManagerAssetPort.cs b/Carter Games/Save Manager/Code/Editor/Utility/Porting/SaveManagerAssetPort.cs new file mode 100644 index 0000000..ca3993d --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Porting/SaveManagerAssetPort.cs @@ -0,0 +1,68 @@ +/* + * 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 CarterGames.Common; + +namespace CarterGames.Assets.SaveManager.Editor.Porting +{ + /// + /// Handles porting the asset data assets from 2.1.8 -> plugin version 2.2.0+ + /// + public sealed class SaveManagerAssetPort : IAssetEditorInitialize, IAssetEditorReload + { + // IAssetEditorInitialize Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + public int InitializeOrder => 2000; + + + public void OnEditorInitialized() + { + TryPortAssets(); + } + + // IAssetEditorReload Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + public void OnEditorReloaded() + { + TryPortAssets(); + } + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Methods + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + /// + /// Tries to port the assets, if they are already ported nothing will happen. + /// + private void TryPortAssets() + { + foreach (var porting in AssemblyHelper.GetClassesOfType()) + { + if (!porting.CanPort) continue; + porting.PortAsset(); + } + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Porting/SaveManagerAssetPort.cs.meta b/Carter Games/Save Manager/Code/Editor/Utility/Porting/SaveManagerAssetPort.cs.meta new file mode 100644 index 0000000..7df92a8 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Porting/SaveManagerAssetPort.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b1a7f0329ead46c691b17f3994432ab0 +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/Defenitions.meta b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions.meta new file mode 100644 index 0000000..645bda9 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 288fbb13a8914d85ba98dddb6850cf2e +timeCreated: 1726407819 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefAssetIndex.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefAssetIndex.cs new file mode 100644 index 0000000..0eae7f4 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefAssetIndex.cs @@ -0,0 +1,77 @@ +/* + * 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; +using UnityEditor; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// Handles the creation and referencing of the asset index file. + /// + public sealed class ScriptableAssetDefAssetIndex : IScriptableAssetDef, ILegacyAssetPort + { + // IScriptableAssetDef Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static AssetIndex cache; + private static SerializedObject objCache; + + public Type AssetType => typeof(AssetIndex); + public string DataAssetFileName => "[Save Manager] Asset Index.asset"; + public string DataAssetFilter => $"t:{typeof(AssetIndex).FullName}"; + public string DataAssetPath => $"{ScriptableRef.FullPathResources}{DataAssetFileName}"; + + public AssetIndex AssetRef => ScriptableRef.GetOrCreateAsset(this, ref cache); + public SerializedObject ObjectRef => ScriptableRef.GetOrCreateAssetObject(this, ref objCache); + + public void TryCreate() + { + ScriptableRef.GetOrCreateAsset(this, ref cache); + } + + // ILegacyAssetPort Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + public bool CanPort => AssetDatabaseHelper.TypeExistsElsewhere(DataAssetPath); + + + public void PortAsset() + { + TryCreate(); + + var assets = AssetDatabaseHelper.GetAssetPathNotAtPath(DataAssetPath); + + if (assets != null) + { + foreach (var entry in assets) + { + AssetDatabase.DeleteAsset(entry); + } + } + + AssetDatabase.SaveAssets(); + AssetIndexHandler.UpdateIndex(); + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefAssetIndex.cs.meta b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefAssetIndex.cs.meta new file mode 100644 index 0000000..29a4527 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefAssetIndex.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ef4d4045d14246ec9fb2ee5bb035ecce +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/Defenitions/ScriptableAssetDefEncryptionAsset.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefEncryptionAsset.cs new file mode 100644 index 0000000..e6a24de --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefEncryptionAsset.cs @@ -0,0 +1,82 @@ +/* + * 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; +using System.Linq; +using UnityEditor; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// Handles the creation and referencing of the encryption asset file. + /// + public sealed class ScriptableAssetDefEncryptionAsset : IScriptableAssetDef, ILegacyAssetPort + { + // IScriptableAssetDef Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static EncryptionKeyAsset cache; + private static SerializedObject objCache; + + public Type AssetType => typeof(EncryptionKeyAsset); + public string DataAssetFileName => "[Save Manager] Encryption Key Asset.asset"; + public string DataAssetFilter => $"t:{typeof(EncryptionKeyAsset).FullName}"; + public string DataAssetPath => $"{ScriptableRef.FullPathData}{DataAssetFileName}"; + + public EncryptionKeyAsset AssetRef => ScriptableRef.GetOrCreateAsset(this, ref cache); + public SerializedObject ObjectRef => ScriptableRef.GetOrCreateAssetObject(this, ref objCache); + + public void TryCreate() + { + ScriptableRef.GetOrCreateAsset(this, ref cache); + } + + // ILegacyAssetPort Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + public bool CanPort => AssetDatabaseHelper.TypeExistsElsewhere(DataAssetPath); + + + public void PortAsset() + { + TryCreate(); + + var assets = AssetDatabaseHelper.GetAssetPathNotAtPath(DataAssetPath).ToArray(); + + if (assets.Length <= 0) return; + + SerializedPropertyHelper.TransferProperties( + new SerializedObject(AssetDatabase.LoadAssetAtPath(assets[0], typeof(EncryptionKeyAsset))), ObjectRef); + + ObjectRef.ApplyModifiedProperties(); + ObjectRef.Update(); + + foreach (var entry in assets) + { + AssetDatabase.DeleteAsset(entry); + } + + AssetDatabase.SaveAssets(); + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefEncryptionAsset.cs.meta b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefEncryptionAsset.cs.meta new file mode 100644 index 0000000..87ac5c7 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefEncryptionAsset.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cb81d13408944baa9eb7ab96f08a234d +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/Defenitions/ScriptableAssetDefSaveData.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveData.cs new file mode 100644 index 0000000..0992d90 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveData.cs @@ -0,0 +1,82 @@ +/* + * 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; +using System.Linq; +using UnityEditor; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// Handles the creation and referencing of the save data asset file. + /// + public sealed class ScriptableAssetDefSaveData : IScriptableAssetDef, ILegacyAssetPort + { + // IScriptableAssetDef Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static SaveData cache; + private static SerializedObject objCache; + + public Type AssetType => typeof(SaveData); + public string DataAssetFileName => "[Save Manager] Save Data Asset.asset"; + public string DataAssetFilter => $"t:{typeof(SaveData).FullName}"; + public string DataAssetPath => $"{ScriptableRef.FullPathData}{DataAssetFileName}"; + + public SaveData AssetRef => ScriptableRef.GetOrCreateAsset(this, ref cache); + public SerializedObject ObjectRef => ScriptableRef.GetOrCreateAssetObject(this, ref objCache); + + public void TryCreate() + { + ScriptableRef.GetOrCreateAsset(this, ref cache); + } + + // ILegacyAssetPort Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + public bool CanPort => AssetDatabaseHelper.TypeExistsElsewhere(DataAssetPath); + + + public void PortAsset() + { + TryCreate(); + + var assets = AssetDatabaseHelper.GetAssetPathNotAtPath(DataAssetPath).ToArray(); + + if (assets.Length <= 0) return; + + SerializedPropertyHelper.TransferProperties( + new SerializedObject(AssetDatabase.LoadAssetAtPath(assets[0], typeof(SaveData))), ObjectRef); + + ObjectRef.ApplyModifiedProperties(); + ObjectRef.Update(); + + foreach (var entry in assets) + { + AssetDatabase.DeleteAsset(entry); + } + + AssetDatabase.SaveAssets(); + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveData.cs.meta b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveData.cs.meta new file mode 100644 index 0000000..c7f4a93 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 77fe941de555464fba5cbc72c7b486c1 +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/Defenitions/ScriptableAssetDefSaveProfilesAsset.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveProfilesAsset.cs new file mode 100644 index 0000000..37a8ae8 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveProfilesAsset.cs @@ -0,0 +1,82 @@ +/* + * 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; +using System.Linq; +using UnityEditor; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// Handles the creation and referencing of the save profiles asset file. + /// + public sealed class ScriptableAssetDefSaveProfilesAsset : IScriptableAssetDef, ILegacyAssetPort + { + // IScriptableAssetDef Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static SaveProfilesStore cache; + private static SerializedObject objCache; + + public Type AssetType => typeof(SaveProfilesStore); + public string DataAssetFileName => "[Save Manager] Save Profile Asset.asset"; + public string DataAssetFilter => $"t:{typeof(SaveProfilesStore).FullName}"; + public string DataAssetPath => $"{ScriptableRef.FullPathData}{DataAssetFileName}"; + + public SaveProfilesStore AssetRef => ScriptableRef.GetOrCreateAsset(this, ref cache); + public SerializedObject ObjectRef => ScriptableRef.GetOrCreateAssetObject(this, ref objCache); + + public void TryCreate() + { + ScriptableRef.GetOrCreateAsset(this, ref cache); + } + + // ILegacyAssetPort Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + public bool CanPort => AssetDatabaseHelper.TypeExistsElsewhere(DataAssetPath); + + public void PortAsset() + { + TryCreate(); + + var assets = AssetDatabaseHelper.GetAssetPathNotAtPath(DataAssetPath).ToArray(); + + if (assets.Length <= 0) return; + + SerializedPropertyHelper.TransferProperties( + new SerializedObject(AssetDatabase.LoadAssetAtPath(assets[0], typeof(SaveProfilesStore))), ObjectRef); + + ObjectRef.ApplyModifiedProperties(); + ObjectRef.Update(); + + foreach (var entry in assets) + { + AssetDatabase.DeleteAsset(entry); + } + + AssetDatabase.SaveAssets(); + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveProfilesAsset.cs.meta b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveProfilesAsset.cs.meta new file mode 100644 index 0000000..d0cdb58 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSaveProfilesAsset.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5c113e7716c64f56b7559ceb33afb437 +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/Defenitions/ScriptableAssetDefSettingsAsset.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSettingsAsset.cs new file mode 100644 index 0000000..9bb3ca9 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSettingsAsset.cs @@ -0,0 +1,82 @@ +/* + * 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; +using System.Linq; +using UnityEditor; + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// Handles the creation and referencing of the settings asset file. + /// + public sealed class ScriptableAssetDefSettingsAsset : IScriptableAssetDef, ILegacyAssetPort + { + // IScriptableAssetDef Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static AssetGlobalRuntimeSettings cache; + private static SerializedObject objCache; + + public Type AssetType => typeof(AssetGlobalRuntimeSettings); + public string DataAssetFileName => "[Save Manager] Runtime Settings Asset.asset"; + public string DataAssetFilter => $"t:{typeof(AssetGlobalRuntimeSettings).FullName}"; + public string DataAssetPath => $"{ScriptableRef.FullPathData}{DataAssetFileName}"; + + public AssetGlobalRuntimeSettings AssetRef => ScriptableRef.GetOrCreateAsset(this, ref cache); + public SerializedObject ObjectRef => ScriptableRef.GetOrCreateAssetObject(this, ref objCache); + + public void TryCreate() + { + ScriptableRef.GetOrCreateAsset(this, ref cache); + } + + // ILegacyAssetPort Implementation + /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + public bool CanPort => AssetDatabaseHelper.TypeExistsElsewhere(DataAssetPath); + + + public void PortAsset() + { + TryCreate(); + + var assets = AssetDatabaseHelper.GetAssetPathNotAtPath(DataAssetPath).ToArray(); + + if (assets.Length <= 0) return; + + SerializedPropertyHelper.TransferProperties( + new SerializedObject(AssetDatabase.LoadAssetAtPath(assets[0], typeof(AssetGlobalRuntimeSettings))), ObjectRef); + + ObjectRef.ApplyModifiedProperties(); + ObjectRef.Update(); + + foreach (var entry in assets) + { + AssetDatabase.DeleteAsset(entry); + } + + AssetDatabase.SaveAssets(); + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSettingsAsset.cs.meta b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSettingsAsset.cs.meta new file mode 100644 index 0000000..51ddda6 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Defenitions/ScriptableAssetDefSettingsAsset.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d9cd5541b84d4efcba472748e54327fb +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/Interfaces.meta b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces.meta new file mode 100644 index 0000000..80f45bd --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3f22bacb9026482d9bc1ee2dfd16f474 +timeCreated: 1726863572 \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/ILegacyAssetPort.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/ILegacyAssetPort.cs new file mode 100644 index 0000000..434600e --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/ILegacyAssetPort.cs @@ -0,0 +1,34 @@ +/* + * 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. + */ + +namespace CarterGames.Assets.SaveManager.Editor +{ + /// + /// Implement to port from an older asset setup to a newer one. + /// + public interface ILegacyAssetPort + { + bool CanPort { get; } + void PortAsset(); + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/ILegacyAssetPort.cs.meta b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/ILegacyAssetPort.cs.meta new file mode 100644 index 0000000..c9c5460 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/ILegacyAssetPort.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 342eb641ba33465a9dad1893343c9c8d +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/Editor Method Aid/InterfaceHelper.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/IScriptableAssetDef.cs similarity index 65% rename from Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/InterfaceHelper.cs rename to Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/IScriptableAssetDef.cs index 857c742..2596fb2 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/Editor Method Aid/InterfaceHelper.cs +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/IScriptableAssetDef.cs @@ -22,23 +22,22 @@ */ using System; -using System.Linq; +using UnityEditor; namespace CarterGames.Assets.SaveManager.Editor { - public static class InterfaceHelper - { - /// - /// Gets all the interface implementations and returns the result (Editor Only) - /// - /// An Array of the interface type - public static T[] GetAllInterfacesInstancesOfType() - { - var types = AppDomain.CurrentDomain.GetAssemblies() - .SelectMany(x => x.GetTypes()) - .Where(x => x.IsClass && typeof(T).IsAssignableFrom(x)); - - return types.Select(type => (T)Activator.CreateInstance(type)).ToArray(); - } - } + /// + /// Implement to define a scriptable asset in the asset. + /// + /// The type of the asset itself. + public interface IScriptableAssetDef where T : SaveManagerAsset + { + Type AssetType { get; } + string DataAssetFileName { get; } + string DataAssetFilter { get; } + string DataAssetPath { get; } + T AssetRef { get; } + SerializedObject ObjectRef { get; } + void TryCreate(); + } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/IScriptableAssetDef.cs.meta b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/IScriptableAssetDef.cs.meta new file mode 100644 index 0000000..76f4885 --- /dev/null +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/Interfaces/IScriptableAssetDef.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7b2c99e0319b490e88b316c13ad730ef +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/ScriptableObjectInitialize.cs b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/ScriptableObjectInitialize.cs index 127abe6..b7a7e38 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/ScriptableObjectInitialize.cs +++ b/Carter Games/Save Manager/Code/Editor/Utility/Scriptable Assets/ScriptableObjectInitialize.cs @@ -26,7 +26,7 @@ namespace CarterGames.Assets.SaveManager.Editor /// /// Handles any logic for generating/updating the scriptable objects for the asset where needed. /// - public class ScriptableObjectInitialize : IAssetEditorInitialize, IAssetEditorReload + public sealed class ScriptableObjectInitialize : IAssetEditorInitialize, IAssetEditorReload { /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | IAssetEditorInitialize @@ -43,7 +43,7 @@ public class ScriptableObjectInitialize : IAssetEditorInitialize, IAssetEditorRe /// public void OnEditorInitialized() { - if (ScriptableRef.HasAllAssets) return; + if (ScriptableRef.HasAllAssets()) return; ScriptableRef.TryCreateAssets(); } @@ -56,7 +56,7 @@ public void OnEditorInitialized() /// public void OnEditorReloaded() { - if (ScriptableRef.HasAllAssets) return; + if (ScriptableRef.HasAllAssets()) return; ScriptableRef.TryCreateAssets(); } } 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 b203656..0dcb19e 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 @@ -21,7 +21,10 @@ * THE SOFTWARE. */ -using System.IO; +using System; +using System.Collections.Generic; +using System.Linq; +using CarterGames.Common; using UnityEditor; namespace CarterGames.Assets.SaveManager.Editor @@ -34,39 +37,16 @@ public static class ScriptableRef /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Fields ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - - // Asset Paths - /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - private static readonly string AssetIndexPath = $"{AssetBasePath}/Carter Games/{AssetName}/Resources/Asset Index.asset"; - private static readonly string SettingsAssetPath = $"{AssetBasePath}/Carter Games/{AssetName}/Data/Runtime Settings.asset"; - private static readonly string CapturesObjectAssetPath = $"{AssetBasePath}/Carter Games/{AssetName}/Data/Save Profiles Container.asset"; - private static readonly string SaveDataPath = $"{AssetBasePath}/Carter Games/{AssetName}/Data/Save Data.asset"; - private static readonly string EncryptionKeyAssetPath = $"{AssetBasePath}/Carter Games/{AssetName}/Data/Encryption Key.asset"; - - // Asset Filters - /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - private static readonly string RuntimeSettingsFilter = $"t:{typeof(AssetGlobalRuntimeSettings).FullName}"; - private static readonly string AssetIndexFilter = $"t:{typeof(AssetIndex).FullName}"; - private static readonly string SaveProfilesStoreFilter = $"t:{typeof(SaveProfilesStore).FullName}"; - private static readonly string SaveDataFilter = $"t:{typeof(SaveData).FullName}"; - private static readonly string SaveDataEncryptionKeyFilter = $"t:{typeof(EncryptionKeyAsset).FullName}"; - - - // Asset Caches - /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - private static AssetGlobalRuntimeSettings assetGlobalRuntimeSettingsCache; - private static AssetIndex assetIndexCache; - private static SaveProfilesStore saveProfilesStoreCache; - private static SaveData saveDataCache; - private static EncryptionKeyAsset encryptionKeyAssetCache; + private static readonly string Root = $"Assets/Plugins/Carter Games/"; + private static readonly string PathResources = $"{AssetName}/Resources/"; + private static readonly string PathData = $"{AssetName}/Data/"; + + public static readonly string FullPathResources = $"{Root}{PathResources}"; + public static readonly string FullPathData = $"{Root}{PathData}"; + private static Dictionary> cacheLookup; - // SerializedObject Caches - /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - private static SerializedObject settingsAssetRuntimeObjectCache; - private static SerializedObject settingsAssetEditorObjectCache; - /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Properties ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ @@ -84,121 +64,141 @@ public static class ScriptableRef /// Gets the asset name stored in the file util editor class. /// private static string AssetName => FileEditorUtil.AssetName; - - // Asset Properties + + // Asset References /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + /// - /// The asset index for the asset. + /// Handles a lookup of all the assets in the project. /// - public static AssetIndex AssetIndex => - FileEditorUtil.CreateSoGetOrAssignAssetCache(ref assetIndexCache, AssetIndexFilter, AssetIndexPath, AssetName, $"{AssetName}/Resources/Asset Index.asset"); + private static Dictionary> AssetLookup + { + get + { + if (cacheLookup != null) + { + if (cacheLookup.Count > 0) return cacheLookup; + } + + cacheLookup = new Dictionary>(); + + foreach (var elly in AssemblyHelper.GetClassesOfType>()) + { + cacheLookup.Add(elly.AssetType, elly); + } + + return cacheLookup; + } + } + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Methods + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ /// - /// The runtime settings for the asset. + /// Gets if all the assets needed for the asset to function are in the project at the expected paths. /// - public static AssetGlobalRuntimeSettings RuntimeAssetGlobalRuntimeSettings => - FileEditorUtil.CreateSoGetOrAssignAssetCache(ref assetGlobalRuntimeSettingsCache, RuntimeSettingsFilter, SettingsAssetPath, AssetName, $"{AssetName}/Data/Runtime Settings.asset"); + public static bool HasAllAssets() + { + return AssetLookup.All(t => HasAsset(t.Value)); + } /// - /// The save profiles for the asset. + /// Tries to create any missing assets when called. /// - public static SaveProfilesStore SaveProfiles => - FileEditorUtil.CreateSoGetOrAssignAssetCache(ref saveProfilesStoreCache, SaveProfilesStoreFilter, CapturesObjectAssetPath, AssetName, $"{AssetName}/Data/Save Profiles Container.asset"); - + public static void TryCreateAssets() + { + foreach (var entry in AssetLookup) + { + entry.Value.TryCreate(); + } + } + /// - /// The save data for the asset. + /// Gets a scriptable asset definition. /// - public static SaveData SaveData => - FileEditorUtil.CreateSoGetOrAssignAssetCache(ref saveDataCache, SaveDataFilter, SaveDataPath, AssetName, $"{AssetName}/Data/Save Data.asset"); + /// The type of the scriptable asset. + /// The asset definition found. + public static IScriptableAssetDef GetAssetDef() where T : SaveManagerAsset + { + if (AssetLookup.ContainsKey(typeof(T))) + { + return (IScriptableAssetDef) AssetLookup[typeof(T)]; + } + + return null; + } /// - /// The encryption key asset for the asset. + /// Tries to get a scriptable asset definition. /// - public static EncryptionKeyAsset EncryptionKey => - FileEditorUtil.CreateSoGetOrAssignAssetCache(ref encryptionKeyAssetCache, SaveDataEncryptionKeyFilter, EncryptionKeyAssetPath, AssetName, $"{AssetName}/Data/Encryption Key.asset"); + /// The asset found. + /// The type of the scriptable asset. + /// If it was successful or not. + public static bool TryGetAssetDef(out IScriptableAssetDef asset) where T : SaveManagerAsset + { + asset = GetAssetDef(); + return asset != null; + } + + + /// + /// Gets if an asset if currently in the project. + /// + /// The definition to check + /// The type of the scriptable asset. + /// If the asset exists. + private static bool HasAsset(IScriptableAssetDef def) where T : SaveManagerAsset + { + return AssetDatabaseHelper.FileIsInProject(def.DataAssetPath); + } - // Object Properties - /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ /// - /// The runtime SerializedObject for the asset. + /// Tries to create the asset requested. /// - public static SerializedObject RuntimeSettingsObject => - FileEditorUtil.CreateGetOrAssignSerializedObjectCache(ref settingsAssetRuntimeObjectCache, RuntimeAssetGlobalRuntimeSettings); + /// The definition to use. + /// The cache for the definition. + /// The type of the scriptable asset. + public static void TryCreateAsset(IScriptableAssetDef def, ref T cache) where T : SaveManagerAsset + { + if (cache != null) return; + GetOrCreateAsset(def, ref cache); + } - // Assets Initialized Check - /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ /// - /// Gets if all the assets needed for the asset to function are in the project at the expected paths. + /// Gets the existing reference or creates on if its not in the project currently. /// - public static bool HasAllAssets => - File.Exists(AssetIndexPath) && File.Exists(SettingsAssetPath) && - File.Exists(EncryptionKeyAssetPath) && - File.Exists(SaveDataPath) && File.Exists(CapturesObjectAssetPath); - + /// The definition to use. + /// The cache for the definition. + /// The type of the scriptable asset. + /// The asset reference. + public static T GetOrCreateAsset(IScriptableAssetDef def, ref T cache) where T : SaveManagerAsset + { + return FileEditorUtil.CreateSoGetOrAssignAssetCache( + ref cache, + def.DataAssetFilter, + def.DataAssetPath, + AssetName, $"{PathData}{def.DataAssetFileName}"); + } + /// - /// Tries to create any missing assets when called. + /// Gets the existing reference or creates on if its not in the project currently. /// - public static void TryCreateAssets() + /// The definition to use. + /// The cache for the definition. + /// The type of the scriptable asset. + /// The object reference + public static SerializedObject GetOrCreateAssetObject(IScriptableAssetDef def, ref SerializedObject objCache) where T : SaveManagerAsset { - if (assetIndexCache == null) - { - FileEditorUtil.CreateSoGetOrAssignAssetCache( - ref assetIndexCache, - AssetIndexFilter, - AssetIndexPath, - AssetName, $"{AssetName}/Resources/Asset Index.asset"); - } - - - if (assetGlobalRuntimeSettingsCache == null) - { - FileEditorUtil.CreateSoGetOrAssignAssetCache( - ref assetGlobalRuntimeSettingsCache, - RuntimeSettingsFilter, - SettingsAssetPath, - AssetName, $"{AssetName}/Data/Runtime Settings.asset"); - } - - - if (saveProfilesStoreCache == null) - { - FileEditorUtil.CreateSoGetOrAssignAssetCache( - ref saveProfilesStoreCache, - SaveProfilesStoreFilter, - CapturesObjectAssetPath, - AssetName, $"{AssetName}/Data/Save Profiles Container.asset"); - } - - - if (encryptionKeyAssetCache == null) - { - FileEditorUtil.CreateSoGetOrAssignAssetCache( - ref encryptionKeyAssetCache, - SaveDataEncryptionKeyFilter, - EncryptionKeyAssetPath, - AssetName, $"{AssetName}/Data/Encryption Key.asset"); - - } - - - if (saveDataCache == null) - { - FileEditorUtil.CreateSoGetOrAssignAssetCache( - ref saveDataCache, - SaveDataFilter, - SaveDataPath, - AssetName, $"{AssetName}/Data/Save Data.asset"); - - } + return FileEditorUtil.CreateGetOrAssignSerializedObjectCache(ref objCache, def.AssetRef); } } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Editor/Utility/UtilEditor.cs b/Carter Games/Save Manager/Code/Editor/Utility/UtilEditor.cs index b74cd1a..8425e67 100644 --- a/Carter Games/Save Manager/Code/Editor/Utility/UtilEditor.cs +++ b/Carter Games/Save Manager/Code/Editor/Utility/UtilEditor.cs @@ -40,7 +40,7 @@ public static class UtilEditor // Paths /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - public const string SettingsWindowPath = "Project/Carter Games/Save Manager"; + public const string SettingsWindowPath = "Carter Games/Assets/Save Manager"; public static readonly string CapturesSavePath = $"{AssetBasePath}/Carter Games/Save Manager/Data/Save Profiles/"; @@ -191,53 +191,34 @@ public static class UtilEditor // Assets /* ────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - /// - /// Gets if there is a settings asset in the project. - /// - public static bool HasInitialized - { - get - { - AssetIndexHandler.UpdateIndex(); - return ScriptableRef.HasAllAssets; - } - } - - /// /// Gets/Sets the save manager settings asset. /// - public static AssetGlobalRuntimeSettings AssetGlobalRuntimeSettings => ScriptableRef.RuntimeAssetGlobalRuntimeSettings; - - - /// - /// Gets/Sets the save manager editor settings asset. - /// - public static SerializedObject SettingsObject => ScriptableRef.RuntimeSettingsObject; + public static AssetGlobalRuntimeSettings AssetGlobalRuntimeSettings => ScriptableRef.GetAssetDef().AssetRef; /// /// Gets/Sets the save manager save profiles asset. /// - public static SaveProfilesStore SaveProfiles => ScriptableRef.SaveProfiles; + public static SaveProfilesStore SaveProfiles => ScriptableRef.GetAssetDef().AssetRef; /// /// Gets/Sets the save manager save data asset. /// - public static SaveData SaveData => ScriptableRef.SaveData; + public static SaveData SaveData => ScriptableRef.GetAssetDef().AssetRef; /// /// Gets/Sets the save manager save data asset. /// - public static EncryptionKeyAsset EncryptionKeyAsset => ScriptableRef.EncryptionKey; + public static EncryptionKeyAsset EncryptionKeyAsset => ScriptableRef.GetAssetDef().AssetRef; /// /// Gets/Sets the save manager save data asset. /// - public static AssetIndex AssetIndex => ScriptableRef.AssetIndex; + public static AssetIndex AssetIndex => ScriptableRef.GetAssetDef().AssetRef; /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Draw Methods 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 67db39d..6f6976c 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.Assets.SaveManager.Runtime", + "name": "CarterGames.SaveManager.Runtime", "rootNamespace": "CarterGames.Assets.SaveManager", "references": [ "GUID:0dd839a085d98c5478abb31237806e7c" diff --git a/Carter Games/Save Manager/Code/Runtime/Common/AssemblyHelper.cs b/Carter Games/Save Manager/Code/Runtime/Common/AssemblyHelper.cs new file mode 100644 index 0000000..00aa661 --- /dev/null +++ b/Carter Games/Save Manager/Code/Runtime/Common/AssemblyHelper.cs @@ -0,0 +1,158 @@ +/* + * 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 NONINFRINGEMENT. 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; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace CarterGames.Common +{ + /// + /// A helper class for assembly related logic. + /// + public static class AssemblyHelper + { + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Fields + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + private static Assembly[] saveManagerAssemblies; + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Properties + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + /// + /// Gets all the cart assemblies to use when checking in internally only. + /// + private static Assembly[] SaveManagerAssemblies + { + get + { + if (saveManagerAssemblies != null) return saveManagerAssemblies; + saveManagerAssemblies = GetCartAssemblies(); + return saveManagerAssemblies; + } + } + + /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── + | Methods + ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ + + /// + /// The assemblies for the library. + /// + /// Returns all the assemblies for the cart. + private static Assembly[] GetCartAssemblies() + { +#if UNITY_EDITOR + return new Assembly[3] + { + Assembly.Load("CarterGames.SaveManager.Editor"), + Assembly.Load("CarterGames.SaveManager.Runtime"), + Assembly.Load("CarterGames.SaveManager.Common"), + }; +#else + return new Assembly[2] + { + Assembly.Load("CarterGames.SaveManager.Runtime"), + Assembly.Load("CarterGames.SaveManager.Common") + }; +#endif + } + + + /// + /// Gets the number of classes of the requested type in the project. + /// + /// Check internally to the asset only. + /// The type to find. + /// The total in the project. + public static int CountClassesOfType(bool internalCheckOnly = true) + { + var assemblies = internalCheckOnly ? SaveManagerAssemblies : AppDomain.CurrentDomain.GetAssemblies(); + + return assemblies.SelectMany(x => x.GetTypes()) + .Count(x => x.IsClass && typeof(T).IsAssignableFrom(x)); + } + + + /// + /// Gets the number of classes of the requested type in the project. + /// + /// The assemblies to check through. + /// The type to find. + /// The total in the project. + public static int CountClassesOfType(params Assembly[] assemblies) + { + return assemblies.SelectMany(x => x.GetTypes()) + .Count(x => x.IsClass && typeof(T).IsAssignableFrom(x)); + } + + + /// + /// Gets all the classes of the entered type in the project. + /// + /// Check internally to the asset only. + /// The type to find. + /// All the implementations of the entered class. + public static IEnumerable GetClassesOfType(bool internalCheckOnly = true) + { + var assemblies = internalCheckOnly ? SaveManagerAssemblies : AppDomain.CurrentDomain.GetAssemblies(); + + return assemblies.SelectMany(x => x.GetTypes()) + .Where(x => x.IsClass && typeof(T).IsAssignableFrom(x) && x.FullName != typeof(T).FullName) + .Select(type => (T)Activator.CreateInstance(type)); + } + + + /// + /// Gets all the classes of the entered type in the project. + /// + /// Check internally to the asset only. + /// The type to find. + /// All the implementations of the entered class. + public static IEnumerable GetClassesNamesOfType(bool internalCheckOnly = true) + { + var assemblies = internalCheckOnly ? SaveManagerAssemblies : AppDomain.CurrentDomain.GetAssemblies(); + + return assemblies.SelectMany(x => x.GetTypes()) + .Where(x => x.IsClass && typeof(T).IsAssignableFrom(x) && x.FullName != typeof(T).FullName); + } + + + /// + /// Gets all the classes of the entered type in the project. + /// + /// The assemblies to check through. + /// The type to find. + /// All the implementations of the entered class. + public static IEnumerable GetClassesOfType(params Assembly[] assemblies) + { + return assemblies.SelectMany(x => x.GetTypes()) + .Where(x => x.IsClass && typeof(T).IsAssignableFrom(x) && x.FullName != typeof(T).FullName) + .Select(type => (T)Activator.CreateInstance(type)); + } + } +} \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Runtime/Common/AssemblyHelper.cs.meta b/Carter Games/Save Manager/Code/Runtime/Common/AssemblyHelper.cs.meta new file mode 100644 index 0000000..75fa9db --- /dev/null +++ b/Carter Games/Save Manager/Code/Runtime/Common/AssemblyHelper.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 95dd3e583d064e96a0950749c0317c3e +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/Data/AssetAccessor.cs b/Carter Games/Save Manager/Code/Runtime/Data/AssetAccessor.cs index ab43531..922833d 100644 --- a/Carter Games/Save Manager/Code/Runtime/Data/AssetAccessor.cs +++ b/Carter Games/Save Manager/Code/Runtime/Data/AssetAccessor.cs @@ -36,7 +36,7 @@ public static class AssetAccessor | Fields ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - private const string IndexPath = "Asset Index"; + private const string IndexPath = "[Save Manager] Asset Index"; // A cache of all the assets found... private static AssetIndex indexCache; diff --git a/Carter Games/Save Manager/Code/Runtime/Logger/SmLog.cs b/Carter Games/Save Manager/Code/Runtime/Logger/SaveManagerLogger.cs similarity index 96% rename from Carter Games/Save Manager/Code/Runtime/Logger/SmLog.cs rename to Carter Games/Save Manager/Code/Runtime/Logger/SaveManagerLogger.cs index c3b2ace..89f608d 100644 --- a/Carter Games/Save Manager/Code/Runtime/Logger/SmLog.cs +++ b/Carter Games/Save Manager/Code/Runtime/Logger/SaveManagerLogger.cs @@ -28,7 +28,7 @@ namespace CarterGames.Assets.SaveManager /// /// A logging class for messages within the asset. /// - public static class SmLog + public static class SaveManagerLogger { /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Constants @@ -55,7 +55,7 @@ public static class SmLog /// Displays a normal debug message for the build versions asset... /// /// The message to show... - public static void Normal(string message) + public static void Log(string message) { if (!ShowLogs) return; Debug.Log($"{LogPrefix}{message}"); @@ -66,7 +66,7 @@ public static void Normal(string message) /// Displays a warning debug message for the build versions asset... /// /// The message to show... - public static void Warning(string message) + public static void LogWarning(string message) { if (!ShowLogs) return; Debug.LogWarning($"{LogPrefix}{WarningPrefix}{message}"); @@ -77,7 +77,7 @@ public static void Warning(string message) /// Displays a error debug message for the build versions asset... /// /// The message to show... - public static void Error(string message) + public static void LogError(string message) { if (!ShowLogs) return; Debug.LogError($"{LogPrefix}{ErrorPrefix}{message}"); diff --git a/Carter Games/Save Manager/Code/Runtime/Logger/SmLog.cs.meta b/Carter Games/Save Manager/Code/Runtime/Logger/SaveManagerLogger.cs.meta similarity index 100% rename from Carter Games/Save Manager/Code/Runtime/Logger/SmLog.cs.meta rename to Carter Games/Save Manager/Code/Runtime/Logger/SaveManagerLogger.cs.meta diff --git a/Carter Games/Save Manager/Code/Runtime/Save Data/Values/SaveValue.cs b/Carter Games/Save Manager/Code/Runtime/Save Data/Values/SaveValue.cs index 8a93857..f7894c1 100644 --- a/Carter Games/Save Manager/Code/Runtime/Save Data/Values/SaveValue.cs +++ b/Carter Games/Save Manager/Code/Runtime/Save Data/Values/SaveValue.cs @@ -37,10 +37,8 @@ public class SaveValue : SaveValueBase | Fields ───────────────────────────────────────────────────────────────────────────────────────────────────────────── */ - /// - /// The value of the save value. - /// [SerializeField] private T value; + [SerializeField] private T defaultValue; /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── | Properties @@ -107,6 +105,7 @@ public SaveValue(string key, T value) { this.key = key; this.value = value; + defaultValue = value; } /* ───────────────────────────────────────────────────────────────────────────────────────────────────────────── @@ -116,8 +115,7 @@ public SaveValue(string key, T value) /// /// Initializes the save value for use. /// - /// The default value to initialise to. - public void Initialize(T defaultValue) + public void Initialize() { ValueObject = defaultValue; } @@ -137,9 +135,9 @@ public override void AssignFromObject(SaveValueBase data) /// /// Resets the save value to its default setup. /// - public override void ResetValue() + public override void ResetValue(bool useDefault = true) { - Value = default; + Value = useDefault ? defaultValue : default; } } } \ No newline at end of file diff --git a/Carter Games/Save Manager/Code/Runtime/Save Data/Values/SaveValueBase.cs b/Carter Games/Save Manager/Code/Runtime/Save Data/Values/SaveValueBase.cs index 02362ed..5a4beab 100644 --- a/Carter Games/Save Manager/Code/Runtime/Save Data/Values/SaveValueBase.cs +++ b/Carter Games/Save Manager/Code/Runtime/Save Data/Values/SaveValueBase.cs @@ -57,7 +57,7 @@ public abstract class SaveValueBase /// /// Reset the value on call. /// - public abstract void ResetValue(); + public abstract void ResetValue(bool useDefault = true); /// diff --git a/Carter Games/Save Manager/Code/Runtime/SaveManager.cs b/Carter Games/Save Manager/Code/Runtime/SaveManager.cs index 5779eed..1df4d3e 100644 --- a/Carter Games/Save Manager/Code/Runtime/SaveManager.cs +++ b/Carter Games/Save Manager/Code/Runtime/SaveManager.cs @@ -251,7 +251,7 @@ private static void SaveToFile(SerializableDictionary> Lo } catch (Exception e) { - SmLog.Error($"Failed to read to {savePath} with the exception: {e}"); + SaveManagerLogger.LogError($"Failed to read to {savePath} with the exception: {e}"); return new SerializableDictionary>(); } } @@ -126,7 +126,7 @@ public SerializableDictionary> Lo } catch (Exception e) { - SmLog.Error($"Failed to read to {savePath} with the exception: {e}"); + SaveManagerLogger.LogError($"Failed to read to {savePath} with the exception: {e}"); return new SerializableDictionary>(); } } diff --git a/Carter Games/Save Manager/Code/Runtime/Saving/Handlers/WebSaveHandler.cs b/Carter Games/Save Manager/Code/Runtime/Saving/Handlers/WebSaveHandler.cs index 8b64caa..64fb0f6 100644 --- a/Carter Games/Save Manager/Code/Runtime/Saving/Handlers/WebSaveHandler.cs +++ b/Carter Games/Save Manager/Code/Runtime/Saving/Handlers/WebSaveHandler.cs @@ -89,7 +89,7 @@ public SerializableDictionary> Lo } catch (Exception e) { - SmLog.Error($"Failed to read to {savePath} with the exception: {e}"); + SaveManagerLogger.LogError($"Failed to read to {savePath} with the exception: {e}"); return new SerializableDictionary>(); } } @@ -134,7 +134,7 @@ public SerializableDictionary> Lo } catch (Exception e) { - SmLog.Error($"Failed to read to {savePath} with the exception: {e}"); + SaveManagerLogger.LogError($"Failed to read to {savePath} with the exception: {e}"); return new SerializableDictionary>(); } } @@ -150,7 +150,7 @@ public SerializableDictionary> Lo /// The path to create the file in. private void CreateFile(string path) { - SmLog.Normal("File does not exist to load at the current save path."); + SaveManagerLogger.Log("File does not exist to load at the current save path."); var split = path.Split('/'); var pathBuilt = string.Empty; 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 7ca52a2..8658e05 100644 --- a/Carter Games/Save Manager/Demo/Data/Example Save Object.asset +++ b/Carter Games/Save Manager/Demo/Data/Example Save Object.asset @@ -16,13 +16,17 @@ MonoBehaviour: saveKey: Example playerName: key: examplePlayerName - value: Isabelle + value: Emily + defaultValue: playerHealth: key: examplePlayerHealth value: -102 + defaultValue: 0 playerPosition: key: examplePlayerPosition value: {x: 0, y: 0, z: 0} + defaultValue: {x: 0, y: 0, z: 0} playerShield: key: examplePlayerShield value: 4 + defaultValue: 0 diff --git a/Carter Games/Save Manager/Demo/Scene/SaveManagerExampleScene.unity b/Carter Games/Save Manager/Demo/Scene/SaveManagerExampleScene.unity index 1cc3bdd..cf291b3 100644 --- a/Carter Games/Save Manager/Demo/Scene/SaveManagerExampleScene.unity +++ b/Carter Games/Save Manager/Demo/Scene/SaveManagerExampleScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641275, b: 0.5748171, a: 1} + m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.5748172, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: diff --git a/LICENSE.meta b/LICENSE.meta new file mode 100644 index 0000000..73d2364 --- /dev/null +++ b/LICENSE.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: ccd1c4498b9f279419970bfb99a8676f +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index 4d66e41..60eb512 100644 --- a/README.md +++ b/README.md @@ -2,38 +2,55 @@ Save Manager is a FREE local save system for Unity games. - +

## Badges ![CodeFactor](https://www.codefactor.io/repository/github/cartergames/SaveManager/badge?style=for-the-badge) -![GitHub all releases](https://img.shields.io/github/downloads/CarterGames/SaveManager/total?style=for-the-badge) +![GitHub all releases](https://img.shields.io/github/downloads/CarterGames/SaveManager/total?style=for-the-badge&color=8d6ca1) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/CarterGames/SaveManager?style=for-the-badge) ![GitHub repo size](https://img.shields.io/github/repo-size/CarterGames/SaveManager?style=for-the-badge) -![Unity](https://img.shields.io/badge/Unity-2020.3.x_or_higher-critical?style=for-the-badge) - +![Unity](https://img.shields.io/badge/Unity-2020.3.x_or_higher-critical?style=for-the-badge&color=8b8b8b) +![Static Badge](https://img.shields.io/badge/License-MIT-blue?style=for-the-badge) +

## Key Features -✔️ Save editor window for edit the save in edit mode
+✔️ Save editor window for editing the save data in edit mode
✔️ Save profiles to load save states in the editor
✔️ Modular save setup
-✔️ Save Encryption avalible with AES Encryption
+✔️ Save Encryption available with AES Encryption
✔️ Auto Save & Load Options
✔️ WebGL support!
-✔️ Custom savable dictionary type incluided.
+✔️ Custom savable dictionary type included.
✔️ Regularly updated and maintained with ❤️ - +

## How To Install -Either download and import the package from the releases section or the Unity Asset Store and use the package manager. Alternatively, download this repo and copy all files into your project. +### Unity Package Manager (Git URL) [Recommended] +Release: +
+The most up-to-date version of the repo that is considered stable enough for public use. +``` +https://github.com/CarterGames/SaveManager.git +``` + +Pre-release: +
+Used to prepare future releases before releasing them, checking for bugs mainly. Will have the latest features but may not be stable just yet. Use at your own risk. +``` +https://github.com/CarterGames/SaveManager.git#prerelease +``` + +Either download and import the package from the releases section or the Unity Asset Store and use the package manager. Alternatively, download this repo and copy all files into your project. +

## Setup & Basic Usage The asset is now installed, just make your save objects and save values to start saving elements of your game. You can see how to do this here. You can manually save the game by calling SaveManager.Save() & SaveManager.Load() respectively. - +

## Documentation -You can access a online of the documentation here: Online Documentation. A offline copy if provided with the package and asset if needed. - +You can access a online of the documentation here: Online Documentation. An offline copy is provided with the package and asset if needed. +

## Unity Supported Versions -The asset is developed and maintained in 2020.3.x and make use for avalible .Net updates in the version. Older versions of Unity are not supported for this asset. The asset has been tested pre-release in versions: 2020.3.0f1 & 2022.2.15f1. - +The asset is developed and maintained in 2020.3.x and make use of available .Net updates in the version. Older versions of Unity are not supported for this asset. The asset has been tested pre-release in its development version: 2020.3.0f1. +

## Authors - Jonathan Carter - +

## Licence MIT Licence diff --git a/README.md.meta b/README.md.meta new file mode 100644 index 0000000..470bc64 --- /dev/null +++ b/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 68a7949d8abd3ad4983a1d660d0c7356 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..62f2b37 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "games.carter.savemanager", + "version": "2.2.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", + "unityRelease": "0f1", + "documentationUrl": "https://carter.games/savemanager", + "licensesUrl": "https://github.com/CarterGames/SaveManager/blob/main/LICENSE", + "author": { + "name": "Carter Games", + "email": "hello@carter.games", + "url": "https://carter.games/savemanager" + } +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..d029522 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 940447b4d9ed4853b1cfbb0e30fdc104 +timeCreated: 1726416751 \ No newline at end of file