-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tool_FileFinder.cs
240 lines (218 loc) · 7.95 KB
/
Tool_FileFinder.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class Tool_FileFinder : EditorWindow
{
//Tool State / Scrollpos
int _ToolState = 0;
int _ToolStateCheck = 1;
Vector2 _ScrollPos = new Vector2();
//Project
string _Project_Type = "";
string _Project_TypeCheck = "";
string _Project_Search = "";
string _Project_SearchCheck = "a";
bool _Project_ExcludeMeta = true;
int _Project_Results = 0;
int _Project_Total = 0;
//Project > Results
string[] _SearchResults = new string[0];
string[] _SearchResultsChange = new string[0];
//Scene
string _Scene_Search = "";
bool _Scene_InsceneInfo = true;
//Scene > Results
bool[] _Scene_Objects_Toggle = new bool[0];
GameObject[] _Scene_Objects = new GameObject[0];
//GetWindow
[MenuItem("Tools/Tool_FileFinder")]
public static void ShowWindow()
{
EditorWindow.GetWindow(typeof(Tool_FileFinder));
}
//Menu/HomePage
void OnGUI()
{
_ToolState = GUILayout.Toolbar(_ToolState, new string[] { "Assets", "Scene" });
if (_ToolState == 0)
{
FileFinder_Search();
FileFinder_SearchProject();
}
else
{
FileFinder_SceneSearch();
_Scene_InsceneInfo = EditorGUILayout.Toggle("InScene Info", _Scene_InsceneInfo);
FileFinder_Scene();
}
//stop focus when switching
if(_ToolStateCheck != _ToolState)
{
EditorGUI.FocusTextInControl("searchproject");
_ToolStateCheck = _ToolState;
}
}
//Project
void FileFinder_Search()
{
_Project_Search = EditorGUILayout.TextField("Search:", _Project_Search);
_Project_Type = EditorGUILayout.TextField("Type:", _Project_Type);
_Project_ExcludeMeta = EditorGUILayout.Toggle("Exlude Meta:", _Project_ExcludeMeta);
GUILayout.Label("(" + _Project_Results + "/" + _Project_Total + ")");
_Project_Results = 0;
_Project_Total = 0;
if (_Project_Search != _Project_SearchCheck || _Project_Type != _Project_TypeCheck)
{
_SearchResults = System.IO.Directory.GetFiles("Assets/", "*" + _Project_Type, System.IO.SearchOption.AllDirectories);
_SearchResultsChange = _SearchResults;
_Project_SearchCheck = _Project_Search;
_Project_TypeCheck = _Project_Type;
}
}
void FileFinder_SearchProject()
{
_ScrollPos = EditorGUILayout.BeginScrollView(_ScrollPos);
for (int i = 0; i < _SearchResults.Length; i++)
{
if (_SearchResults[i].ToLower().Contains(_Project_Search.ToLower()))
{
if(_Project_ExcludeMeta)
{
if (!_SearchResults[i].ToLower().Contains(".meta"))
FileFinder_SearchProject_Results(i);
}
else
FileFinder_SearchProject_Results(i);
}
_Project_Total++;
}
EditorGUILayout.EndScrollView();
}
void FileFinder_SearchProject_Results(int id)
{
GUILayout.BeginHorizontal("Box");
GUILayout.Label(_SearchResults[id], GUILayout.Width(Screen.width - 80));
if (GUILayout.Button("Select", GUILayout.Width(50)))
{
Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(_SearchResults[id]);
}
GUILayout.EndHorizontal();
_Project_Results++;
}
//Scene
void FileFinder_SceneSearch()
{
_Scene_Search = EditorGUILayout.TextField("Search:", _Scene_Search);
GUILayout.Label("(" + _Project_Results + "/" + _Project_Total + ")");
if (GUILayout.Button("Refresh"))
{
_Scene_Objects = new GameObject[0];
}
_Project_Results = 0;
_Project_Total = 0;
if (_Scene_Objects.Length == 0)
{
_Scene_Objects = FindObjectsOfType<GameObject>();
_Scene_Objects_Toggle = new bool[_Scene_Objects.Length];
}
}
void FileFinder_Scene()
{
_ScrollPos = EditorGUILayout.BeginScrollView(_ScrollPos);
try
{
for (int i = 0; i < _Scene_Objects.Length; i++)
{
if (_Scene_Objects[i].name.ToLower().Contains(_Scene_Search.ToLower()))
{
GUILayout.BeginHorizontal("Box");
_Scene_Objects_Toggle[i] = EditorGUILayout.Foldout(_Scene_Objects_Toggle[i], "");
GUILayout.Label(_Scene_Objects[i].name, GUILayout.Width(Screen.width - 80));
if (GUILayout.Button("Select", GUILayout.Width(50)))
{
Selection.activeObject = _Scene_Objects[i];
}
if (_Scene_Objects_Toggle[i])
{
GUILayout.EndHorizontal();
GUILayout.BeginVertical("box");
_Scene_Objects[i].name = EditorGUILayout.TextField("Name:", _Scene_Objects[i].name);
_Scene_Objects[i].transform.position = EditorGUILayout.Vector3Field("Position:", _Scene_Objects[i].transform.position);
_Scene_Objects[i].transform.eulerAngles = EditorGUILayout.Vector3Field("Rotation:", _Scene_Objects[i].transform.eulerAngles);
GUILayout.EndVertical();
GUILayout.BeginHorizontal();
}
GUILayout.EndHorizontal();
_Project_Results++;
}
_Project_Total++;
}
}
catch
{
_Scene_Objects = new GameObject[0];
}
EditorGUILayout.EndScrollView();
}
//wip
void FileFinder_NameChange()
{
_ScrollPos = EditorGUILayout.BeginScrollView(_ScrollPos);
for (int i = 0; i < _SearchResults.Length; i++)
{
if (_SearchResults[i].ToLower().Contains(_Project_Search.ToLower()))
{
GUILayout.BeginHorizontal("Box");
_SearchResultsChange[i] = EditorGUILayout.TextField("Object Name: ", _SearchResultsChange[i]);
if (GUILayout.Button("Save", GUILayout.Width(50)))
{
_SearchResults[i] = _SearchResultsChange[i];
Debug.Log(_SearchResults[i] + " to > " + _SearchResultsChange[i]);
}
if (GUILayout.Button("Revert", GUILayout.Width(50)))
{
_SearchResultsChange[i] = _SearchResults[i];
Debug.Log(_SearchResultsChange[i] + " to > " + _SearchResults[i]);
}
if (GUILayout.Button("Select", GUILayout.Width(50)))
{
Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(_SearchResults[i]);
}
GUILayout.EndHorizontal();
_Project_Results++;
}
_Project_Total++;
}
EditorGUILayout.EndScrollView();
}
//Enable/Disable
void OnEnable()
{
SceneView.duringSceneGui += this.OnSceneGUI;
}
void OnDisable()
{
SceneView.duringSceneGui -= this.OnSceneGUI;
}
//OnSceneGUI
void OnSceneGUI(SceneView sceneView)
{
try
{
if (_Scene_InsceneInfo)
{
Handles.color = new Color(0, 1, 0, 0.1f);
for (int i = 0; i < _Scene_Objects.Length; i++)
{
if (_Scene_Objects[i].name.ToLower().Contains(_Scene_Search.ToLower()))
{
Handles.SphereHandleCap(1, _Scene_Objects[i].transform.position, Quaternion.identity, 3f, EventType.Repaint);
Handles.Label(_Scene_Objects[i].transform.position, _Scene_Objects[i].name);
}
}
}
}
catch { }
}
}