MPV of save/load system

This commit is contained in:
Michal Pikulski
2025-10-27 14:00:37 +01:00
parent 690e8b4507
commit f5c1ae51cd
15 changed files with 1234 additions and 17 deletions

View File

@@ -0,0 +1,63 @@
using System.IO;
using UnityEditor;
using UnityEngine;
namespace Editor.Tools
{
/// <summary>
/// Editor utility to clear all save data from the SaveLoadManager's save folder
/// </summary>
public static class ClearSavesMenuItem
{
[MenuItem("AppleHills/Clear Saves")]
private static void ClearSaves()
{
// Construct the save folder path (matches SaveLoadManager.DefaultSaveFolder)
string saveFolder = Path.Combine(Application.persistentDataPath, "GameSaves");
if (!Directory.Exists(saveFolder))
{
Debug.Log($"[ClearSaves] Save folder does not exist: {saveFolder}");
EditorUtility.DisplayDialog("Clear Saves", "No save data found to clear.", "OK");
return;
}
// Confirm with the user
bool confirmed = EditorUtility.DisplayDialog(
"Clear Saves",
$"Are you sure you want to delete all save data?\n\nFolder: {saveFolder}",
"Delete All",
"Cancel"
);
if (!confirmed)
{
Debug.Log("[ClearSaves] User cancelled save deletion");
return;
}
try
{
// Delete all files in the save folder
string[] files = Directory.GetFiles(saveFolder);
int deletedCount = 0;
foreach (string file in files)
{
File.Delete(file);
deletedCount++;
Debug.Log($"[ClearSaves] Deleted: {file}");
}
Debug.Log($"[ClearSaves] Successfully deleted {deletedCount} save file(s)");
EditorUtility.DisplayDialog("Clear Saves", $"Successfully deleted {deletedCount} save file(s).", "OK");
}
catch (System.Exception ex)
{
Debug.LogError($"[ClearSaves] Failed to clear saves: {ex}");
EditorUtility.DisplayDialog("Clear Saves", $"Error clearing saves:\n{ex.Message}", "OK");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 747ab9e66b014771bc1486f9ab073f90
timeCreated: 1761569785