226 lines
7.8 KiB
C#
226 lines
7.8 KiB
C#
// ===============================================================================
|
|
// ProjectDashboardTool - Central Control Panel for Unity Projects
|
|
//
|
|
// Creator: Scove
|
|
// Last Updated: 2026-03-03
|
|
// Version: 2.0
|
|
//
|
|
// Purpose:
|
|
// A centralized dashboard to quickly navigate between scenes, start the game
|
|
// from the initialization (Boot) scene, and manage save data / PlayerPrefs.
|
|
//
|
|
// Key Features:
|
|
// 1. Dynamic Scene List: Automatically fetches scenes from Build Settings.
|
|
// 2. 1-Click Play: Instantly loads the Boot scene and enters Play Mode.
|
|
// 3. Data Management: Clear PlayerPrefs, delete save files, or open the Save folder.
|
|
// 4. Color-Coded UI: Prevents accidental data deletion with clear visual warnings.
|
|
//
|
|
// How to Use:
|
|
// 1. Place this script in an 'Editor' folder.
|
|
// 2. Open via: Menu -> Tools -> Project Dashboard.
|
|
// 3. Add your scenes to File -> Build Settings to see them in the list.
|
|
// ===============================================================================
|
|
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEditor.SceneManagement;
|
|
using System.IO;
|
|
|
|
namespace Editor
|
|
{
|
|
public class ProjectDashboardTool : EditorWindow
|
|
{
|
|
private Vector2 sceneScrollPos;
|
|
|
|
[MenuItem("Tools/Project Dashboard")]
|
|
public static void ShowWindow()
|
|
{
|
|
// Create a window with a minimum size
|
|
ProjectDashboardTool window = GetWindow<ProjectDashboardTool>("Dashboard");
|
|
window.minSize = new Vector2(300, 450);
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
EditorGUILayout.Space();
|
|
|
|
DrawPlaySection();
|
|
EditorGUILayout.Space(15);
|
|
|
|
DrawSceneNavigation();
|
|
EditorGUILayout.Space(15);
|
|
|
|
DrawDataManagement();
|
|
}
|
|
|
|
private void DrawPlaySection()
|
|
{
|
|
GUILayout.Label("QUICK PLAY", EditorStyles.boldLabel);
|
|
EditorGUILayout.BeginVertical("box");
|
|
|
|
// Green Play Button
|
|
Color oldColor = GUI.backgroundColor;
|
|
GUI.backgroundColor = new Color(0.4f, 1f, 0.4f); // Light Green
|
|
|
|
if (GUILayout.Button("▶ PLAY GAME (From Boot Scene)", GUILayout.Height(40)))
|
|
{
|
|
PlayFromBootScene();
|
|
}
|
|
|
|
GUI.backgroundColor = oldColor;
|
|
|
|
EditorGUILayout.HelpBox("Automatically saves your current scene, loads the first scene in Build Settings, and presses Play.", MessageType.Info);
|
|
EditorGUILayout.EndVertical();
|
|
}
|
|
|
|
private void DrawSceneNavigation()
|
|
{
|
|
GUILayout.Label("SCENE NAVIGATION (Build Settings)", EditorStyles.boldLabel);
|
|
EditorGUILayout.BeginVertical("box");
|
|
|
|
// Fetch scenes dynamically from Build Settings
|
|
EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
|
|
|
|
if (scenes.Length == 0)
|
|
{
|
|
EditorGUILayout.HelpBox("No scenes found in Build Settings! Please go to File -> Build Settings and add your scenes.", MessageType.Warning);
|
|
}
|
|
else
|
|
{
|
|
sceneScrollPos = EditorGUILayout.BeginScrollView(sceneScrollPos, GUILayout.MaxHeight(200));
|
|
|
|
for (int i = 0; i < scenes.Length; i++)
|
|
{
|
|
if (scenes[i].enabled)
|
|
{
|
|
string scenePath = scenes[i].path;
|
|
string sceneName = Path.GetFileNameWithoutExtension(scenePath);
|
|
|
|
EditorGUILayout.BeginHorizontal();
|
|
GUILayout.Label($"[{i}]", GUILayout.Width(25));
|
|
|
|
if (GUILayout.Button($"Load {sceneName}", GUILayout.Height(25)))
|
|
{
|
|
OpenScene(scenePath);
|
|
}
|
|
EditorGUILayout.EndHorizontal();
|
|
}
|
|
}
|
|
|
|
EditorGUILayout.EndScrollView();
|
|
}
|
|
|
|
EditorGUILayout.EndVertical();
|
|
}
|
|
|
|
private void DrawDataManagement()
|
|
{
|
|
GUILayout.Label("DATA MANAGEMENT", EditorStyles.boldLabel);
|
|
EditorGUILayout.BeginVertical("box");
|
|
|
|
if (GUILayout.Button("Open Save Folder (Explorer/Finder)", GUILayout.Height(30)))
|
|
{
|
|
EditorUtility.RevealInFinder(Application.persistentDataPath);
|
|
}
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
// Red Delete Button
|
|
Color oldColor = GUI.backgroundColor;
|
|
GUI.backgroundColor = new Color(1f, 0.4f, 0.4f); // Light Red
|
|
|
|
if (GUILayout.Button("⚠ Clear PlayerPrefs & Save Data", GUILayout.Height(35)))
|
|
{
|
|
if (EditorUtility.DisplayDialog(
|
|
"Clear All Data?",
|
|
"Are you sure you want to delete all PlayerPrefs and JSON save files?\nThis action cannot be undone.",
|
|
"Yes, Delete Everything",
|
|
"Cancel"))
|
|
{
|
|
ClearAllData();
|
|
}
|
|
}
|
|
|
|
GUI.backgroundColor = oldColor;
|
|
EditorGUILayout.EndVertical();
|
|
}
|
|
|
|
private void PlayFromBootScene()
|
|
{
|
|
EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
|
|
if (scenes.Length == 0)
|
|
{
|
|
Debug.LogError("<b>[Dashboard]</b> Cannot Play: No scenes in Build Settings.");
|
|
return;
|
|
}
|
|
|
|
// Stop playing if currently playing
|
|
if (EditorApplication.isPlaying)
|
|
{
|
|
EditorApplication.isPlaying = false;
|
|
return;
|
|
}
|
|
|
|
// Save current scene and load Scene 0
|
|
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
|
{
|
|
EditorSceneManager.OpenScene(scenes[0].path);
|
|
EditorApplication.isPlaying = true;
|
|
}
|
|
}
|
|
|
|
private void OpenScene(string path)
|
|
{
|
|
if (EditorApplication.isPlaying)
|
|
{
|
|
Debug.LogWarning("<b>[Dashboard]</b> Cannot load scene while in Play Mode.");
|
|
return;
|
|
}
|
|
|
|
if (EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
|
|
{
|
|
EditorSceneManager.OpenScene(path);
|
|
Debug.Log($"<b>[Dashboard]</b> Loaded scene: {Path.GetFileNameWithoutExtension(path)}");
|
|
}
|
|
}
|
|
|
|
private void ClearAllData()
|
|
{
|
|
// 1. Clear Unity PlayerPrefs
|
|
PlayerPrefs.DeleteAll();
|
|
PlayerPrefs.Save();
|
|
|
|
// 2. Clear common save files in persistentDataPath
|
|
string persistentPath = Application.persistentDataPath;
|
|
string[] filesToDelete = new string[]
|
|
{
|
|
"save_data.json",
|
|
"player_data.dat",
|
|
"settings.json"
|
|
};
|
|
|
|
int deletedCount = 0;
|
|
|
|
foreach (string file in filesToDelete)
|
|
{
|
|
string filePath = Path.Combine(persistentPath, file);
|
|
if (File.Exists(filePath))
|
|
{
|
|
File.Delete(filePath);
|
|
deletedCount++;
|
|
}
|
|
}
|
|
|
|
// Alternative: Delete ALL .json files in the folder (Uncomment if needed)
|
|
/*
|
|
string[] allJsonFiles = Directory.GetFiles(persistentPath, "*.json");
|
|
foreach (string file in allJsonFiles) { File.Delete(file); }
|
|
*/
|
|
|
|
Debug.Log($"<color=#FF5555><b>[Dashboard]</b></color> Cleared PlayerPrefs and {deletedCount} save file(s).");
|
|
|
|
// Show notification on the Editor Window
|
|
this.ShowNotification(new GUIContent("Data Cleared Successfully!"));
|
|
}
|
|
}
|
|
} |