-
Notifications
You must be signed in to change notification settings - Fork 1
/
Class1.cs
82 lines (69 loc) · 2.77 KB
/
Class1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using UnityEditor;
using UnityEngine;
using System.IO;
namespace UnityRageQuiter
{
public class RageQuiter : EditorWindow
{
[MenuItem("Window/RageQuiter")]
public static void ShowWindow()
{
// Create the window
GetWindow<RageQuiter>("RageQuiter");
}
private void OnGUI()
{
// Create the label to go above the button
GUILayout.Label("Press to RAGE QUIT!", EditorStyles.boldLabel);
// Create the rage quit button
if (GUILayout.Button("RAGE QUIT!"))
{
// Launch a confirmation warning to the user
bool confirm = EditorUtility.DisplayDialog("Confirm Rage Quit", "Are you sure you want to rage quit your Unity project? All files will be purged.", "Yes", "No");
// If the user confirms
if (confirm)
{
// Call the function that deletes all the assets
DeleteAllFilesInAssetsFolder();
// Wish the user good luck in the console
Debug.Log("Good luck next time.");
}
}
}
private void DeleteAllFilesInAssetsFolder()
{
// Get the path to the Assets folder
string assetsPath = Application.dataPath;
// Get all files within the Assets folder and its subdirectories
string[] allFiles = Directory.GetFiles(assetsPath, "*", SearchOption.AllDirectories);
// Iterate through all the asset files
foreach (string filePath in allFiles)
{
// Skip the script's own file
if (IsFileWithinEditorFolder(filePath))
continue;
try
{
// Try to delete each file
File.Delete(filePath);
Debug.Log("Deleted file: " + filePath);
}
catch (System.Exception ex)
{
// Print a warning in the console if any issues arrise
Debug.LogWarning("Failed to delete file: " + filePath + ". Error: " + ex.Message);
}
}
// Refresh the AssetDatabase to reflect changes in the Unity Editor
AssetDatabase.Refresh();
}
// Function to check if a file is in the editor folder which is where the script is located
private bool IsFileWithinEditorFolder(string filePath)
{
// Path to the Editor folder
string editorFolderPath = Path.Combine(Application.dataPath, "Editor");
// Check if the file is within the Editor folder
return filePath.StartsWith(editorFolderPath);
}
}
}