-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScriptFinder.cs
87 lines (73 loc) · 2.9 KB
/
ScriptFinder.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
83
84
85
86
87
// **************************************************************** //
//
// Copyright (c) RimuruDev. All rights reserved.
// Contact me:
// - Gmail: rimuru.dev@gmail.com
// - GitHub: https://github.com/RimuruDev
// - LinkedIn: https://www.linkedin.com/in/rimuru/
// - GitHub Organizations: https://github.com/Rimuru-Dev
//
// **************************************************************** //
#if UNITY_EDITOR
using System.IO;
using UnityEditor;
using UnityEngine;
namespace External.RimuruDev.ScriptFinder.Editor
{
public sealed class ScriptFinder : EditorWindow
{
private const string Title = "Script Finder";
private const string Label = "Script Search";
private const string RootFolderFiels = "Root Folder";
private const string FindInternalButton = "Find Scripts";
private const string FindAllButton = "Find All Project Scripts";
private const string SearchPattern = "*.cs";
private const string СtrlF3 = "%#F3";
private int totalScriptsFound;
private string[] scriptsInFolder;
private string rootFolder = "Internal";
private string MyScriptPath =>
Path.Combine(Application.dataPath, rootFolder);
private static string ProjectScriptPath =>
Application.dataPath;
[MenuItem("RimuruDev Tools/Script Finder " + СtrlF3)]
public static void ShowWindow()
{
var window = GetWindow<ScriptFinder>(Title);
window.Show();
}
private void OnGUI()
{
GUILayout.Label(Label, EditorStyles.boldLabel);
rootFolder = EditorGUILayout.TextField(RootFolderFiels, rootFolder);
FindMyScripts();
FindAllScripts();
}
private void FindAllScripts()
{
if (GUILayout.Button(FindAllButton) && !string.IsNullOrEmpty(ProjectScriptPath))
FindScripts(ProjectScriptPath);
}
private void FindMyScripts()
{
if (GUILayout.Button(FindInternalButton) && !string.IsNullOrEmpty(MyScriptPath))
FindScripts(MyScriptPath);
}
private void FindScripts(string scriptPath)
{
try
{
scriptsInFolder = Directory.GetFiles(scriptPath, SearchPattern, SearchOption.AllDirectories);
}
catch (DirectoryNotFoundException)
{
const string logFormat = "<color=red>{0}</color>";
const string message = "Incorrect name of the root folder. Please specify the correct name of the folder where you want to search for scripts.";
Debug.LogFormat(logFormat, message);
}
totalScriptsFound = scriptsInFolder.Length;
Debug.Log($"<color=magenta>Scripts Found:</color> <color=yellow>{totalScriptsFound}</color>");
}
}
}
#endif