-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔩 2.3.0 Release PR > Merge pull request #6 from CarterGames/prerelease
📦 2.3.0 Release
- Loading branch information
Showing
27 changed files
with
373 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Carter Games/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
126 changes: 126 additions & 0 deletions
126
...mes/Save Manager/Code/Editor/Custom Editors/Windows/Defaults Window/SaveDefaultsWindow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...eanup/LegacyEditorSettingsRemover.cs.meta → ...efaults Window/SaveDefaultsWindow.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Carter Games/Save Manager/Code/Editor/Systems/Build Handlers.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
Carter Games/Save Manager/Code/Editor/Systems/Build Handlers/BuildHandlerResetSaveObjects.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ex Cleanup/LegacyIndexRemovalTool.cs.meta → ...lers/BuildHandlerResetSaveObjects.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
Carter Games/Save Manager/Code/Editor/Systems/Legacy/Asset Index Cleanup.meta
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.