Skip to content

Commit

Permalink
📦 2.1.0 Release
Browse files Browse the repository at this point in the history
- Save categories added as a togglable feature.
- Some minor backend changes.
  • Loading branch information
JonathanMCarter committed Jan 1, 2024
1 parent f37d589 commit 0639bc3
Show file tree
Hide file tree
Showing 27 changed files with 519 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Carter Games.meta

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

2 changes: 1 addition & 1 deletion Carter Games/Save Manager.meta

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
@@ -1,5 +1,5 @@
{
"name": "CarterGames.SaveManager.Editor",
"name": "CarterGames.Assets.SaveManager.Editor",
"rootNamespace": "CarterGames.Assets.SaveManager.Editor",
"references": [
"GUID:5fed357a0eb29414bb1d1667107777c5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,30 @@ private static void DrawGeneralOptions()
PerUserSettings.VersionValidationAutoCheckOnLoad);

// Show Logs...
EditorGUILayout.PropertyField(SettingsAssetObject.Fp("showLogs"), Logs);
PerUserSettingsRuntime.ShowDebugLogs = EditorGUILayout.Toggle(Logs, PerUserSettingsRuntime.ShowDebugLogs);

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

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

PerUserSettings.SaveEditorOrganiseByCategory = EditorGUILayout.Toggle(new GUIContent("Show Save Categories",
"Organises the save editor by category attribute [SaveCategory()]."),
PerUserSettings.SaveEditorOrganiseByCategory);

if (EditorGUI.EndChangeCheck())
{
SaveManagerEditorWindow.RequestRepaint.Raise();
}

if (GUILayout.Button("Reset Settings"))
{
if (EditorUtility.DisplayDialog("Reset Save Manager Settings",
"Are you sure that you want to reset all settings for the asset to their defaults. This only applies to you. Other users of the project will have to do this for their settings themselves.",
"Reset Settings", "Cancel"))
{
PerUserSettings.ResetPrefs();
// PerUserSettingsRuntime.ResetPrefs();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public sealed class SaveManagerEditorWindow : EditorWindow
/// Raises when a new save object is added to the data.
/// </summary>
public static readonly Evt SaveObjectAddedToSaveData = new Evt();


public static readonly Evt RequestRepaint = new Evt();

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Window Access Method
Expand Down Expand Up @@ -80,6 +83,8 @@ private void OnGUI()
{
Initialize();

RequestRepaint.Add(Repaint);

EditorGUILayout.Space(17.5f);

EditorGUI.BeginChangeCheck();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ public sealed class EditorTab
/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
| Fields
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */

private const string DemoSaveObjectFullName = "CarterGames.Assets.SaveManager.Demo.ExampleSaveObject";

private Dictionary<SaveObject, SaveObjectEditor> editorsLookup;
private Dictionary<SaveObject, SerializedObject> soLookup;
private Dictionary<SaveObject, SerializedObject> demoLookup;


private static Rect deselectRect;

/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
Expand All @@ -25,25 +26,25 @@ public void Initialize()
{
soLookup = new Dictionary<SaveObject, SerializedObject>();
editorsLookup = new Dictionary<SaveObject, SaveObjectEditor>();
demoLookup = new Dictionary<SaveObject, SerializedObject>();
}

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

public void DrawTab(List<SaveObject> saveObjects)
{
if (saveObjects.Count <= 0) return;

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);
}

PerUserSettings.SaveEditorTabScrollRectPos = EditorGUILayout.BeginScrollView(PerUserSettings.SaveEditorTabScrollRectPos);
PerUserSettings.SaveEditorTabScrollRectPos =
EditorGUILayout.BeginScrollView(PerUserSettings.SaveEditorTabScrollRectPos);

foreach (var saveObj in saveObjects)
{
Expand All @@ -57,118 +58,167 @@ public void DrawTab(List<SaveObject> saveObjects)
{
sObj = new SerializedObject(saveObj);
}


if (saveObj.GetType().FullName == "CarterGames.Assets.SaveManager.Demo.ExampleSaveObject")
{
if (demoLookup.ContainsKey(saveObj)) continue;
demoLookup.Add(saveObj, sObj);
}
else
{
if (soLookup.ContainsKey(saveObj)) continue;
soLookup.Add(saveObj, sObj);
}

if (soLookup.ContainsKey(saveObj)) continue;
soLookup.Add(saveObj, sObj);
}


if (soLookup.Count > 0)
{
DrawSaveObjects(" Save Objects", ref soLookup);
DrawSaveObjects();
}


if (demoLookup.Count > 0)
{
GUILayout.Space(12.5f);
DrawSaveObjects(" Demo Save Objects", ref demoLookup);
}


EditorGUILayout.Space(5f);
EditorGUILayout.EndScrollView();

// UtilEditor.CreateDeselectZone(ref deselectRect);
}


/// <summary>
/// Draws a collection of save objects.
/// </summary>
/// <param name="sectionName">The name for the section.</param>
/// <param name="lookup">The lookup for the objects.</param>
private void DrawSaveObjects(string sectionName, ref Dictionary<SaveObject, SerializedObject> lookup)
private void DrawSaveObjects()
{
EditorGUILayout.LabelField(sectionName, EditorStyles.boldLabel);


foreach (var pair in lookup)
if (PerUserSettings.SaveEditorOrganiseByCategory)
{
if (!editorsLookup.ContainsKey(pair.Key))
{
editorsLookup.Add(pair.Key, (SaveObjectEditor) UnityEditor.Editor.CreateEditor(pair.Key));
}


EditorGUILayout.BeginVertical(editorsLookup[pair.Key].serializedObject.Fp("isExpanded").boolValue ? "HelpBox" : "Box");

EditorGUILayout.BeginHorizontal();

EditorGUI.BeginChangeCheck();

editorsLookup[pair.Key].serializedObject.Fp("isExpanded").boolValue =
EditorGUILayout.Foldout(editorsLookup[pair.Key].serializedObject.Fp("isExpanded").boolValue, pair.Key.name);

if (EditorGUI.EndChangeCheck())

var didHaveUncategorized = false;
var hasDrawnLine = false;


// Uncategorized Save Objects
/* ────────────────────────────────────────────────────────────────────────────────────────────────── */
foreach (var saveObject in SaveCategoryAttributeHelper.GetObjectsInCategory("Uncategorized"))
{
editorsLookup[pair.Key].serializedObject.ApplyModifiedProperties();
editorsLookup[pair.Key].serializedObject.Update();

SaveManager.Save();
if (saveObject.GetType().FullName == DemoSaveObjectFullName) continue;
DrawSaveObjectEditor(saveObject);
didHaveUncategorized = true;
}

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

if (GUILayout.Button("-", GUILayout.Width(25)))

// Categorized Save Objects
/* ────────────────────────────────────────────────────────────────────────────────────────────────── */
foreach (var category in SaveCategoryAttributeHelper.GetCategoryNames())
{
if (EditorUtility.DisplayDialog("Reset Save Object",
"Are you sure you want to reset all values on this save object?", "Reset", "Cancel"))
if (category.Equals("Uncategorized")) continue;

var saveObjectsInCategory = SaveCategoryAttributeHelper.GetObjectsInCategory(category);

EditorGUILayout.LabelField(category, EditorStyles.boldLabel);

if (didHaveUncategorized && !hasDrawnLine && saveObjectsInCategory.Count > 0)
{
// Reset Save Object
pair.Key.ResetObjectSaveValues();

editorsLookup[pair.Key].serializedObject.ApplyModifiedProperties();
editorsLookup[pair.Key].serializedObject.Update();

SaveManager.Save();
GUI.FocusControl(null);

return;
UtilEditor.DrawHorizontalGUILine();
hasDrawnLine = true;
}

foreach (var saveObject in saveObjectsInCategory)
{
if (saveObject.GetType().FullName == DemoSaveObjectFullName)
continue;
DrawSaveObjectEditor(saveObject);
}
}
}
else
{
// Non-Categorized - But without demo save object.
/* ────────────────────────────────────────────────────────────────────────────────────────────────── */
foreach (var objKp in soLookup)
{
if (objKp.Key.GetType().FullName == DemoSaveObjectFullName) continue;
DrawSaveObjectEditor(objKp.Key);
}
}


// Demo Save Object
/* ────────────────────────────────────────────────────────────────────────────────────────────────────── */
var demoSaveObject = soLookup.FirstOrDefault(t =>
t.Key.GetType().FullName == DemoSaveObjectFullName).Key;

if (demoSaveObject == null) return;

UtilEditor.DrawHorizontalGUILine();
EditorGUILayout.LabelField("Asset Demo Save Object", EditorStyles.boldLabel);
DrawSaveObjectEditor(demoSaveObject);
}

GUI.backgroundColor = Color.white;

EditorGUILayout.EndHorizontal();

GUILayout.Space(2.5f);


if (editorsLookup[pair.Key].serializedObject.Fp("isExpanded").boolValue)
private void DrawSaveObjectEditor(SaveObject targetSaveObject)
{
if (!editorsLookup.ContainsKey(targetSaveObject))
{
editorsLookup.Add(targetSaveObject,
(SaveObjectEditor)UnityEditor.Editor.CreateEditor(targetSaveObject));
}

EditorGUILayout.BeginVertical(editorsLookup[targetSaveObject].serializedObject.Fp("isExpanded").boolValue
? "HelpBox"
: "Box");

EditorGUILayout.BeginHorizontal();

EditorGUI.BeginChangeCheck();

editorsLookup[targetSaveObject].serializedObject.Fp("isExpanded").boolValue =
EditorGUILayout.Foldout(editorsLookup[targetSaveObject].serializedObject.Fp("isExpanded").boolValue,
targetSaveObject.name);

if (EditorGUI.EndChangeCheck())
{
editorsLookup[targetSaveObject].serializedObject.ApplyModifiedProperties();
editorsLookup[targetSaveObject].serializedObject.Update();

SaveManager.Save();
}

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

if (GUILayout.Button("-", GUILayout.Width(25)))
{
if (EditorUtility.DisplayDialog("Reset Save Object",
"Are you sure you want to reset all values on this save object?", "Reset", "Cancel"))
{
editorsLookup[pair.Key].EditorWindowGUI();
GUILayout.Space(1.5f);
// Reset Save Object
targetSaveObject.ResetObjectSaveValues();

editorsLookup[targetSaveObject].serializedObject.ApplyModifiedProperties();
editorsLookup[targetSaveObject].serializedObject.Update();

SaveManager.Save();
GUI.FocusControl(null);

return;
}

EditorGUI.EndDisabledGroup();

EditorGUILayout.EndVertical();

GUILayout.Space(4f);
}

GUI.backgroundColor = Color.white;

EditorGUILayout.EndHorizontal();

GUILayout.Space(2.5f);


if (editorsLookup[targetSaveObject].serializedObject.Fp("isExpanded").boolValue)
{
editorsLookup[targetSaveObject].EditorWindowGUI();
GUILayout.Space(1.5f);
}

EditorGUI.EndDisabledGroup();

EditorGUILayout.EndVertical();

GUILayout.Space(4f);
}



public void RepaintAll()
{
foreach (var keyPair in editorsLookup)
Expand Down
3 changes: 3 additions & 0 deletions Carter Games/Save Manager/Code/Editor/Systems/Attributes.meta

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

Loading

0 comments on commit 0639bc3

Please sign in to comment.