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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
|
// Material/Shader Inspector for Unity 2017/2018
// Copyright (C) 2019 Thryrallo
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
namespace Thry
{
public class Settings : EditorWindow
{
public static void firstTimePopup()
{
Settings window = (Settings)EditorWindow.GetWindow(typeof(Settings));
window.isFirstPopop = true;
window.Show();
}
public static void updatedPopup(int compare)
{
Settings window = (Settings)EditorWindow.GetWindow(typeof(Settings));
window.updatedVersion = compare;
window.Show();
}
public new void Show()
{
base.Show();
this.titleContent = new GUIContent("Thry Settings");
}
public ModuleSettings[] moduleSettings;
private bool isFirstPopop = false;
private int updatedVersion = 0;
private bool is_init = false;
public static ButtonData thry_message = null;
//---------------------Stuff checkers and fixers-------------------
public void Awake()
{
InitVariables();
}
private void InitVariables()
{
List<Type> subclasses = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(type => type.IsSubclassOf(typeof(ModuleSettings))).ToList();
moduleSettings = new ModuleSettings[subclasses.Count];
int i = 0;
foreach(Type classtype in subclasses)
{
moduleSettings[i++] = (ModuleSettings)Activator.CreateInstance(classtype);
}
is_init = true;
if (thry_message == null)
WebHelper.DownloadStringASync(Thry.URL.SETTINGS_MESSAGE_URL, delegate (string s) { thry_message = Parser.ParseToObject<ButtonData>(s); });
}
//------------------Main GUI
void OnGUI()
{
if (!is_init || moduleSettings==null) InitVariables();
GUILayout.Label("ShaderUI v" + Config.Singleton.verion);
GUINotification();
drawLine();
GUIMessage();
LocaleDropdown();
GUIEditor();
drawLine();
foreach(ModuleSettings s in moduleSettings)
{
s.Draw();
drawLine();
}
GUIModulesInstalation();
}
//--------------------------GUI Helpers-----------------------------
private static void drawLine()
{
Rect rect = EditorGUILayout.GetControlRect(false, 1);
rect.height = 1;
EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 1));
}
private void GUINotification()
{
if (isFirstPopop)
GUILayout.Label(" " + Locale.editor.Get("first_install_message"), Styles.greenStyle);
else if (updatedVersion == -1)
GUILayout.Label(" " + Locale.editor.Get("update_message"), Styles.greenStyle);
else if (updatedVersion == 1)
GUILayout.Label(" " + Locale.editor.Get("downgrade_message"), Styles.orangeStyle);
}
private void GUIMessage()
{
if(thry_message!=null && thry_message.text.Length > 0)
{
GUIStyle style = new GUIStyle();
style.richText = true;
style.margin = new RectOffset(7, 0, 0, 0);
style.wordWrap = true;
GUILayout.Label(new GUIContent(thry_message.text,thry_message.hover), style);
Rect r = GUILayoutUtility.GetLastRect();
if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition))
thry_message.action.Perform();
drawLine();
}
}
bool is_editor_expanded = true;
private void GUIEditor()
{
is_editor_expanded = Foldout(Locale.editor.Get("header_editor"), is_editor_expanded);
if (is_editor_expanded)
{
EditorGUI.indentLevel += 2;
Dropdown("default_texture_type");
Toggle("showRenderQueue");
Toggle("renameAnimatedProps");
Toggle("showManualReloadButton");
GUIGradients();
EditorGUI.indentLevel -= 2;
}
}
private static void GUIGradients()
{
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
Text("gradient_name", false);
string gradient_name = Config.Singleton.gradient_name;
if (gradient_name.Contains("<hash>"))
GUILayout.Label(Locale.editor.Get("gradient_good_naming"), Styles.greenStyle, GUILayout.ExpandWidth(false));
else if (gradient_name.Contains("<material>"))
if (gradient_name.Contains("<prop>"))
GUILayout.Label(Locale.editor.Get("gradient_good_naming"), Styles.greenStyle, GUILayout.ExpandWidth(false));
else
GUILayout.Label(Locale.editor.Get("gradient_add_hash_or_prop"), Styles.orangeStyle, GUILayout.ExpandWidth(false));
else if (gradient_name.Contains("<prop>"))
GUILayout.Label(Locale.editor.Get("gradient_add_material"), Styles.orangeStyle, GUILayout.ExpandWidth(false));
else
GUILayout.Label(Locale.editor.Get("gradient_add_material_or_prop"), Styles.redStyle, GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();
}
private class TextPopup : EditorWindow
{
public string text = "";
private Vector2 scroll;
void OnGUI()
{
EditorGUILayout.SelectableLabel(Locale.editor.Get("my_data_header"), EditorStyles.boldLabel);
Rect last = GUILayoutUtility.GetLastRect();
Rect data_rect = new Rect(0, last.height, Screen.width, Screen.height - last.height);
scroll = EditorGUILayout.BeginScrollView(scroll, GUILayout.Width(data_rect.width), GUILayout.Height(data_rect.height));
GUILayout.TextArea(text);
EditorGUILayout.EndScrollView();
}
}
private void GUIModulesInstalation()
{
if (ModuleHandler.GetFirstPartyModules() == null)
return;
if (ModuleHandler.GetFirstPartyModules().Count > 0) {
EditorGUILayout.BeginHorizontal();
GUILayout.Label(Locale.editor.Get("header_modules"), EditorStyles.boldLabel);
if (GUILayout.Button("Reload"))
ModuleHandler.ForceReloadModules();
EditorGUILayout.EndHorizontal();
}
bool disabled = ModuleHandler.GetFirstPartyModules().Any(m => m.is_being_installed_or_removed);
disabled |= ModuleHandler.GetThirdPartyModules().Any(m => m.is_being_installed_or_removed);
EditorGUI.BeginDisabledGroup(disabled);
foreach (Module module in ModuleHandler.GetFirstPartyModules())
{
ModuleUI(module);
}
GUILayout.Label(Locale.editor.Get("header_thrird_party"), EditorStyles.boldLabel);
foreach (Module module in ModuleHandler.GetThirdPartyModules())
{
ModuleUI(module);
}
EditorGUI.EndDisabledGroup();
}
private void ModuleUI(Module module)
{
string text = " " + module.available_module.name;
if (module.update_available)
text = " " + text;
module.ui_expanded = Foldout(text, module.ui_expanded);
Rect rect = GUILayoutUtility.GetLastRect();
rect.x += 20;
rect.y += 1;
rect.width = 20;
rect.height -= 4;
bool is_installed = module.installed_module != null;
EditorGUI.BeginDisabledGroup(!module.available_requirement_fullfilled);
EditorGUI.BeginChangeCheck();
bool install = GUI.Toggle(rect, is_installed, "");
if(EditorGUI.EndChangeCheck()){
ModuleHandler.InstallRemoveModule(module, install);
}
if (module.update_available)
{
rect.x += 20;
rect.width = 55;
GUIStyle style = new GUIStyle(EditorStyles.miniButton);
style.fixedHeight = 17;
if (GUI.Button(rect, "Update",style))
ModuleHandler.UpdateModule(module);
}
//add update notification
if (module.ui_expanded)
{
EditorGUI.indentLevel += 1;
ModuleUIDetails(module);
EditorGUI.indentLevel -= 1;
}
EditorGUI.EndDisabledGroup();
}
private void ModuleUIDetails(Module module)
{
float prev_label_width = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 130;
EditorGUILayout.HelpBox(module.available_module.description, MessageType.Info);
if (module.installed_module != null)
EditorGUILayout.LabelField("Installed Version: ", module.installed_module.version);
EditorGUILayout.LabelField("Available Version: ", module.available_module.version);
if (module.available_module.requirement != null)
{
if (module.available_requirement_fullfilled)
EditorGUILayout.LabelField(Locale.editor.Get("requirements") + ": ", module.available_module.requirement.ToString(), Styles.greenStyle);
else
EditorGUILayout.LabelField(Locale.editor.Get("requirements") + ": ", module.available_module.requirement.ToString(), Styles.redStyle);
}
EditorGUILayout.LabelField("Url: ", module.url);
if (module.author != null)
EditorGUILayout.LabelField("Author: ", module.author);
EditorGUIUtility.labelWidth = prev_label_width;
}
private static void Text(string configField, bool createHorizontal = true)
{
Text(configField, Locale.editor.Get(configField), Locale.editor.Get(configField + "_tooltip"), createHorizontal);
}
private static void Text(string configField, string[] content, bool createHorizontal=true)
{
Text(configField, content[0], content[1], createHorizontal);
}
private static void Text(string configField, string text, string tooltip, bool createHorizontal)
{
Config config = Config.Singleton;
System.Reflection.FieldInfo field = typeof(Config).GetField(configField);
if (field != null)
{
string value = (string)field.GetValue(config);
if (createHorizontal)
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false));
GUILayout.Space(57);
GUILayout.Label(new GUIContent(text, tooltip), GUILayout.ExpandWidth(false));
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.DelayedTextField("", value, GUILayout.ExpandWidth(false));
if (EditorGUI.EndChangeCheck())
{
field.SetValue(config, value);
config.Save();
}
if (createHorizontal)
GUILayout.EndHorizontal();
}
}
private static void Toggle(string configField, GUIStyle label_style = null)
{
Toggle(configField, Locale.editor.Get(configField), Locale.editor.Get(configField + "_tooltip"), label_style);
}
private static void Toggle(string configField, string[] content, GUIStyle label_style = null)
{
Toggle(configField, content[0], content[1], label_style);
}
private static void Toggle(string configField, string label, string hover, GUIStyle label_style = null)
{
Config config = Config.Singleton;
System.Reflection.FieldInfo field = typeof(Config).GetField(configField);
if (field != null)
{
bool value = (bool)field.GetValue(config);
if (Toggle(value, label, hover, label_style) != value)
{
field.SetValue(config, !value);
config.Save();
ShaderEditor.RepaintActive();
}
}
}
private static void Dropdown(string configField)
{
Dropdown(configField, Locale.editor.Get(configField),Locale.editor.Get(configField+"_tooltip"));
}
private static void Dropdown(string configField, string[] content)
{
Dropdown(configField, content[0], content[1]);
}
private static void Dropdown(string configField, string label, string hover, GUIStyle label_style = null)
{
Config config = Config.Singleton;
System.Reflection.FieldInfo field = typeof(Config).GetField(configField);
if (field != null)
{
Enum value = (Enum)field.GetValue(config);
EditorGUI.BeginChangeCheck();
EditorGUILayout.BeginHorizontal();
GUILayout.Space(57);
GUILayout.Label(new GUIContent(label, hover), GUILayout.ExpandWidth(false));
value = EditorGUILayout.EnumPopup(value,GUILayout.ExpandWidth(false));
EditorGUILayout.EndHorizontal();
if(EditorGUI.EndChangeCheck())
{
field.SetValue(config, value);
config.Save();
ShaderEditor.RepaintActive();
}
}
}
private static void LocaleDropdown()
{
EditorGUI.BeginChangeCheck();
EditorGUILayout.BeginHorizontal();
GUILayout.Label(new GUIContent(Locale.editor.Get("locale"), Locale.editor.Get("locale_tooltip")), GUILayout.ExpandWidth(false));
Locale.editor.selected_locale_index = EditorGUILayout.Popup(Locale.editor.selected_locale_index, Locale.editor.available_locales, GUILayout.ExpandWidth(false));
if(Locale.editor.Get("translator").Length>0)
GUILayout.Label(Locale.editor.Get("translation") +": "+Locale.editor.Get("translator"), GUILayout.ExpandWidth(false));
EditorGUILayout.EndHorizontal();
if(EditorGUI.EndChangeCheck())
{
Config.Singleton.locale = Locale.editor.available_locales[Locale.editor.selected_locale_index];
Config.Singleton.Save();
ShaderEditor.ReloadActive();
}
}
private static bool Toggle(bool val, string text, GUIStyle label_style = null)
{
return Toggle(val, text, "",label_style);
}
private static bool Toggle(bool val, string text, string tooltip, GUIStyle label_style=null)
{
GUILayout.BeginHorizontal();
GUILayout.Space(35);
val = GUILayout.Toggle(val, new GUIContent("", tooltip), GUILayout.ExpandWidth(false));
if(label_style==null)
GUILayout.Label(new GUIContent(text, tooltip));
else
GUILayout.Label(new GUIContent(text, tooltip),label_style);
GUILayout.EndHorizontal();
return val;
}
private static bool Foldout(string text, bool expanded)
{
return Foldout(new GUIContent(text), expanded);
}
private static bool Foldout(GUIContent content, bool expanded)
{
var rect = GUILayoutUtility.GetRect(16f + 20f, 22f, Styles.dropDownHeader);
rect = EditorGUI.IndentedRect(rect);
GUI.Box(rect, content, Styles.dropDownHeader);
var toggleRect = new Rect(rect.x + 4f, rect.y + 2f, 13f, 13f);
Event e = Event.current;
if (e.type == EventType.Repaint)
EditorStyles.foldout.Draw(toggleRect, false, false, expanded, false);
if (e.type == EventType.MouseDown && toggleRect.Contains(e.mousePosition) && !e.alt)
{
expanded = !expanded;
e.Use();
}
return expanded;
}
}
}
|