using System.IO; using UnityEditor; using UnityEngine; namespace Editor.Tools { /// /// Editor utility to clear all save data from the SaveLoadManager's save folder /// 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"); } } } }