Skip to content

Commit

Permalink
🔩 2.3.0 Release PR > Merge pull request #6 from CarterGames/prerelease
Browse files Browse the repository at this point in the history
📦 2.3.0 Release
  • Loading branch information
JonathanMCarter authored Oct 3, 2024
2 parents 979ea88 + 58a7843 commit 52f8ea1
Show file tree
Hide file tree
Showing 27 changed files with 373 additions and 271 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 2.3.0
## Asset changes

- New editor only save so the build save is in the normal location.
- New save defaults setup that lets users assign defaults outside of constructors when creating save values.
- Save defaults now apply when making a build to all save objects so builds don't have persistent data from editor saves.
- New setting to see save defaults in the editor tab like save keys
- New editor GUI on save objects to see default values.
- Removed some older 2.0.x legacy issue fixers.
- Removed some now redundant API bits.


# 2.2.0
## Asset changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public override void OnInspectorGUI()
InspectorDrawInfoSection();
EditorGUILayout.Space(3.5f);
InspectorDrawValues();
EditorGUILayout.Space(3.5f);
InspectorDrawDefaultValues();

serializedObject.Update();
}
Expand Down Expand Up @@ -240,5 +242,43 @@ private void InspectorDrawValues()
EditorGUILayout.Space(1.5f);
EditorGUILayout.EndVertical();
}


/// <summary>
/// Draws the default values section for the save object.
/// </summary>
private void InspectorDrawDefaultValues()
{
if (!targetSaveObject.IsInitialized) return;

EditorGUILayout.BeginVertical("HelpBox");
EditorGUILayout.Space(.5f);

EditorGUILayout.LabelField("Default Values", EditorStyles.boldLabel);
UtilEditor.DrawHorizontalGUILine();

var prop = serializedObject.GetIterator();

EditorGUI.BeginDisabledGroup(true);

if (prop.NextVisible(true))
{
while (prop.NextVisible(false))
{
if (propertiesLookup.ContainsKey(prop.name)) continue;

EditorGUI.indentLevel++;

EditorGUILayout.PropertyField(serializedObject.Fp(prop.name).Fpr("defaultValue"), new GUIContent(prop.displayName), true);

EditorGUI.indentLevel--;
}
}

EditorGUI.EndDisabledGroup();

EditorGUILayout.Space(1.5f);
EditorGUILayout.EndVertical();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
SaveManager.Save();
}

if (PerUserSettings.ShowDefaultValues)
{
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(property.Fpr("defaultValue"), new GUIContent("Default Value"));
EditorGUI.EndDisabledGroup();
}

EditorGUILayout.EndVertical();

EditorGUI.indentLevel--;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright (c) 2024 Carter Games
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using UnityEditor;
using UnityEngine;

namespace CarterGames.Assets.SaveManager.Editor
{
/// <summary>
/// An editor window to edit the save defaults of a save object.
/// </summary>
public sealed class SaveDefaultsWindow : EditorWindow
{
/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Fields
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

private static SaveObject selected;
private static SerializedObject selectedObject;
private static Vector2 scrollRectPos;

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Open Window Method
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

public static void ShowDefaultsWindow(SaveObject saveObject, SerializedObject serializedObjectForSaveObject)
{
selected = saveObject;
selectedObject = serializedObjectForSaveObject;

GetWindow<SaveDefaultsWindow>(true, $"Default Values - {selected.name}").Show();
}

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Draw Methods
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

private void OnGUI()
{
if (selected == null)
{
Close();
return;
}

scrollRectPos = EditorGUILayout.BeginScrollView(scrollRectPos);

DrawTab();

EditorGUILayout.EndScrollView();
}


private void DrawTab()
{
if (Application.isPlaying)
{
EditorGUILayout.HelpBox(
"You cannot edit the save while in play mode, please exit play mode to edit the save data.",
MessageType.Info);
}

EditorGUILayout.HelpBox(
$"Here you can edit all the default save values on the Save object. These are then set on a fresh save where defaults are used in the resetting.",
MessageType.Info);

EditorGUILayout.BeginVertical("Box");

if (selected != null)
{
ShowPropertiesForObject();
}

EditorGUILayout.EndVertical();
}


private static void ShowPropertiesForObject()
{
var propIterator = selectedObject.GetIterator();

if (!propIterator.NextVisible(true)) return;

while (propIterator.NextVisible(true))
{
var propElement = selectedObject.Fp(propIterator.name);

if (propElement == null) continue;

GUILayout.Space(3.5f);

EditorGUILayout.BeginVertical("HelpBox");

EditorGUILayout.PropertyField(selectedObject.Fp(propIterator.name).Fpr("defaultValue"),
new GUIContent(propIterator.displayName));

EditorGUILayout.EndVertical();
}

GUILayout.Space(3.5f);

selectedObject.ApplyModifiedProperties();
selectedObject.Update();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,15 @@ private void DrawSaveObjectEditor(SaveObject targetSaveObject)
}

EditorGUI.BeginDisabledGroup(Application.isPlaying);
GUI.backgroundColor = UtilEditor.Red;
GUI.backgroundColor = Color.cyan;

if (GUILayout.Button("Defaults", GUILayout.Width(75)))
{
SaveDefaultsWindow.ShowDefaultsWindow(targetSaveObject, editorsLookup[targetSaveObject].serializedObject);
}

GUI.backgroundColor = UtilEditor.Red;

if (GUILayout.Button("-", GUILayout.Width(25)))
{
if (EditorUtility.DisplayDialog("Reset Save Object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class AssetVersionData
/// <summary>
/// The version number of the asset.
/// </summary>
public static string VersionNumber => "2.2.0";
public static string VersionNumber => "2.3.0";


/// <summary>
Expand All @@ -40,6 +40,6 @@ public static class AssetVersionData
/// <remarks>
/// Asset owner is in the UK, so its D/M/Y format.
/// </remarks>
public static string ReleaseDate => "2024/09/27";
public static string ReleaseDate => "2024/10/03";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class SaveManagerSettingsProvider
private static readonly GUIContent PrettyFormat = new GUIContent("Pretty Save Formatting?","Formats the save file into a more readable format when saving.");
private static readonly GUIContent AutoSave = new GUIContent("Auto Save?","Defines if the game saves when exiting the game.");
private static readonly GUIContent SaveKeysToggle = new GUIContent("Show Save Keys?","Defines if the save editor shows the save key for each save value, Use this to condense the UI a tad if you need to.");
private static readonly GUIContent SaveDefaultsToggle = new GUIContent("Show Default Values?","Defines if the save editor shows the default value for each save value, Use this to condense the UI a tad if you need to.");
private static readonly GUIContent Logs = new GUIContent("Show Log Messages?", "Shows log messages for any errors as well as some handy debugging information.");

private const string ExplorerButtonLabel = "Open Save Path In Explorer";
Expand Down Expand Up @@ -238,6 +239,7 @@ private static void DrawGeneralOptions()

// Editor Only Setting....
PerUserSettings.ShowSaveKeys = EditorGUILayout.Toggle(SaveKeysToggle, PerUserSettings.ShowSaveKeys);
PerUserSettings.ShowDefaultValues = EditorGUILayout.Toggle(SaveDefaultsToggle, PerUserSettings.ShowDefaultValues);

// Use save categories...
EditorGUI.BeginChangeCheck();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2024 Carter Games
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System.Reflection;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;

namespace CarterGames.Assets.SaveManager.Editor
{
/// <summary>
/// Handles resetting save objects to defaults on builds, then restoring them when the build is done.
/// </summary>
public sealed class BuildHandlerResetSaveObjects : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
public int callbackOrder { get; }


public void OnPreprocessBuild(BuildReport report)
{
var assets = AssetDatabase.FindAssets($"t:{typeof(SaveObject)}");

if (assets.Length <= 0) return;

foreach (var asset in assets)
{
var fileInstancePath = AssetDatabase.GUIDToAssetPath(asset);
var fileInstance = AssetDatabase.LoadAssetAtPath<SaveObject>(fileInstancePath);

var assetObject = new SerializedObject(fileInstance);

EditorPrefs.SetString(assetObject.targetObject.GetInstanceID().ToString(), EditorJsonUtility.ToJson(assetObject.targetObject));

var propIterator = assetObject.GetIterator();

if (propIterator.NextVisible(true))
{
while (propIterator.NextVisible(true))
{
var propElement = assetObject.Fp(propIterator.name);

if (propElement == null) continue;
if (!propElement.type.Contains("SaveValue")) continue;
if (propElement.propertyType != propIterator.propertyType) continue;

var field = assetObject.targetObject.GetType()
.GetField(propElement.propertyPath.Split('.')[0],
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

field.GetValue(assetObject.targetObject).GetType()
.GetMethod("ResetValue", BindingFlags.Public | BindingFlags.Instance).Invoke(field.GetValue(assetObject.targetObject), new object[] { true });
}
}

assetObject.ApplyModifiedProperties();
assetObject.Update();
}
}


public void OnPostprocessBuild(BuildReport report)
{
var assets = AssetDatabase.FindAssets($"t:{typeof(SaveObject)}");

if (assets.Length <= 0) return;

foreach (var asset in assets)
{
var fileInstancePath = AssetDatabase.GUIDToAssetPath(asset);
var fileInstance = AssetDatabase.LoadAssetAtPath<SaveObject>(fileInstancePath);

var assetObject = new SerializedObject(fileInstance);

EditorJsonUtility.FromJsonOverwrite(EditorPrefs.GetString(assetObject.targetObject.GetInstanceID().ToString()), assetObject.targetObject);
EditorUtility.SetDirty(assetObject.targetObject);
}

AssetDatabase.SaveAssets();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions Carter Games/Save Manager/Code/Editor/Systems/Legacy.meta

This file was deleted.

This file was deleted.

Loading

0 comments on commit 52f8ea1

Please sign in to comment.