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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
// Material/Shader Inspector for Unity 2017/2018
// Copyright (C) 2019 Thryrallo
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
namespace Thry
{
#region Constants
public class PATH
{
public const string TEXTURES_DIR = "Assets/textures";
public const string RSP_NEEDED_PATH = "Assets/";
public const string DELETING_DIR = "Thry/trash";
public const string PERSISTENT_DATA = "Thry/persistent_data";
public const string AFTER_COMPILE_DATA = "Thry/after_compile_data";
public const string MATERIALS_BACKUP_FILE = "Thry/materialsBackup";
public const string THRY_EDITOR_SHADERS = "Thry/shaders";
public const string GRADIENT_INFO_FILE = "Thry/gradients";
public const string TEXT_INFO_FILE = "Thry/text_textures";
public const string MODULES_LOCATION__DATA = "Thry/modules_location_data";
public const string LINKED_MATERIALS_FILE = "Thry/linked_materials.json";
public const string TEMP_VRC_SDK_PACKAGE = "./vrc_sdk_package.unitypackage";
}
public class URL
{
public const string MODULE_COLLECTION = "https://thryeditor.thryrallo.de/files/modules.json";
public const string SETTINGS_MESSAGE_URL = "http://thryeditor.thryrallo.de/message.json";
public const string DATA_SHARE_SEND = "http://thryeditor.thryrallo.de/send_analytics.php";
public const string DATA_SHARE_GET_MY_DATA = "https://thryeditor.thryrallo.de/get_my_data.php";
public const string COUNT_PROJECT = "http://thryeditor.thryrallo.de/count_project.php";
public const string COUNT_USER = "http://thryeditor.thryrallo.de/count_user.php";
}
public class DEFINE_SYMBOLS
{
public const string IMAGING_EXISTS = "IMAGING_DLL_EXISTS";
}
public class RESOURCE_NAME
{
public const string RECT = "thry_rect";
public const string ICON_NAME_LINK = "thryEditor_link";
public const string ICON_NAME_THRY = "thryEditor_iconThry";
}
#endregion
public class DrawingData
{
public static TextureProperty CurrentTextureProperty;
public static Rect LastGuiObjectRect;
public static Rect LastGuiObjectHeaderRect;
public static Rect TooltipCheckRect;
public static bool LastPropertyUsedCustomDrawer;
public static bool LastPropertyDoesntAllowAnimation;
public static DrawerType LastPropertyDrawerType;
public static MaterialPropertyDrawer LastPropertyDrawer;
public static bool IsEnabled = true;
public static ShaderPart LastInitiatedPart;
public static void ResetLastDrawerData()
{
LastPropertyUsedCustomDrawer = false;
LastPropertyDoesntAllowAnimation = false;
LastPropertyDrawer = null;
LastPropertyDrawerType = DrawerType.None;
}
}
public enum DrawerType
{
None, Header
}
public class GradientData
{
public Texture PreviewTexture;
public Gradient Gradient;
}
public enum TextureDisplayType
{
small, big, stylized_big
}
//--------------Shader Data Structs--------------------
#region In Shader Data
public class PropertyOptions
{
public int offset = 0;
public string tooltip = "";
public DefineableAction altClick;
public DefineableAction onClick;
public DefineableCondition condition_show = new DefineableCondition();
public string condition_showS;
public DefineableCondition condition_enable = null;
public PropertyValueAction[] on_value_actions;
public string on_value;
public DefineableAction[] actions;
public ButtonData button_help;
public TextureData texture;
public string[] reference_properties;
public string reference_property;
public bool force_texture_options = false;
public bool hide_in_inspector = false;
public bool is_visible_simple = false;
public string file_name;
public string remote_version_url;
public string generic_string;
}
public class ButtonData
{
public string text = "";
public TextureData texture = null;
public DefineableAction action = new DefineableAction();
public string hover = "";
public DefineableCondition condition_show = new DefineableCondition();
}
public class TextureData
{
public string name = null;
public int width = 128;
public int height = 128;
public char channel = 'r';
public int ansioLevel = 1;
public FilterMode filterMode = FilterMode.Bilinear;
public TextureWrapMode wrapMode = TextureWrapMode.Repeat;
public void ApplyModes(Texture texture)
{
texture.filterMode = filterMode;
texture.wrapMode = wrapMode;
texture.anisoLevel = ansioLevel;
}
public void ApplyModes(string path)
{
TextureImporter importer = (TextureImporter)AssetImporter.GetAtPath(path);
importer.filterMode = filterMode;
importer.wrapMode = wrapMode;
importer.anisoLevel = ansioLevel;
importer.SaveAndReimport();
}
private Texture p_loaded_texture;
public Texture loaded_texture
{
get
{
if (p_loaded_texture == null)
{
string path = FileHelper.FindFile(name, "texture");
if (path != null)
p_loaded_texture = AssetDatabase.LoadAssetAtPath<Texture>(path);
else
p_loaded_texture = new Texture2D(1, 1);
}
return p_loaded_texture;
}
}
}
public class PropertyValueAction
{
public string value;
public DefineableAction[] actions;
public bool Execute(MaterialProperty p)
{
if(
(p.type == MaterialProperty.PropType.Float && p.floatValue.ToString() == value) ||
(p.type == MaterialProperty.PropType.Range && p.floatValue.ToString() == value) ||
(p.type == MaterialProperty.PropType.Color && p.colorValue.ToString() == value) ||
(p.type == MaterialProperty.PropType.Vector && p.vectorValue.ToString() == value) ||
(p.type == MaterialProperty.PropType.Texture && ((p.textureValue == null) == (value == "0"))) ||
(p.type == MaterialProperty.PropType.Texture && ((p.textureValue != null) == (value == "1"))) ||
(p.type == MaterialProperty.PropType.Texture && (p.textureValue != null && p.textureValue.name == value))
)
{
foreach (DefineableAction a in actions)
a.Perform();
return true;
}
return false;
}
private static PropertyValueAction ParseForThryParser(string s)
{
return Parse(s);
}
// value,property1=value1,property2=value2
public static PropertyValueAction Parse(string s)
{
s = s.Trim();
string[] parts = s.Split(',');
if (parts.Length > 0)
{
PropertyValueAction propaction = new PropertyValueAction();
propaction.value = parts[0];
List<DefineableAction> actions = new List<DefineableAction>();
for (int i = 1; i < parts.Length; i++)
{
actions.Add(DefineableAction.Parse(parts[i]));
}
propaction.actions = actions.ToArray();
return propaction;
}
return null;
}
private static PropertyValueAction[] ParseToArrayForThryParser(string s)
{
return ParseToArray(s);
}
public static PropertyValueAction[] ParseToArray(string s)
{
//s = v,p1=v1,p2=v2;v3
List<PropertyValueAction> propactions = new List<PropertyValueAction>();
string[] parts = s.Split(';');
foreach (string p in parts)
{
PropertyValueAction propertyValueAction = PropertyValueAction.Parse(p);
if (propertyValueAction != null)
propactions.Add(propertyValueAction);
}
return propactions.ToArray();
}
}
public class DefineableAction
{
public DefineableActionType type = DefineableActionType.NONE;
public string data = "";
public void Perform()
{
switch (type)
{
case DefineableActionType.URL:
Application.OpenURL(data);
break;
case DefineableActionType.SET_PROPERTY:
string[] set = Regex.Split(data, @"=");
if (set.Length > 1)
MaterialHelper.SetMaterialValue(set[0].Trim(), set[1].Trim());
break;
case DefineableActionType.SET_TAG:
string[] keyValue = Regex.Split(data, @"=");
foreach (Material m in ShaderEditor.Active.Materials)
m.SetOverrideTag(keyValue[0].Trim(), keyValue[1].Trim());
break;
case DefineableActionType.SET_SHADER:
Shader shader = Shader.Find(data);
if (shader != null)
{
foreach (Material m in ShaderEditor.Active.Materials)
m.shader = shader;
}
break;
}
}
private static DefineableAction ParseForThryParser(string s)
{
return Parse(s);
}
public static DefineableAction Parse(string s)
{
s = s.Trim();
DefineableAction action = new DefineableAction();
if (s.StartsWith("http") || s.StartsWith("www"))
{
action.type = DefineableActionType.URL;
action.data = s;
}
else if (s.StartsWith("tag::"))
{
action.type = DefineableActionType.SET_TAG;
action.data = s.Replace("tag::", "");
}
else if (s.StartsWith("shader="))
{
action.type = DefineableActionType.SET_SHADER;
action.data = s.Replace("shader=", "");
}
else if (s.Contains("="))
{
action.type = DefineableActionType.SET_PROPERTY;
action.data = s;
}
return action;
}
public static DefineableAction ParseDrawerParameter(string s)
{
s = s.Trim();
DefineableAction action = new DefineableAction();
if (s.StartsWith("youtube#"))
{
action.type = DefineableActionType.URL;
action.data = "https://www.youtube.com/watch?v="+s.Substring(8);
}
return action;
}
public override string ToString()
{
return $"{{{type},{data}}}";
}
}
public enum DefineableActionType
{
NONE,
URL,
SET_PROPERTY,
SET_SHADER,
SET_TAG
}
public class DefineableCondition
{
public DefineableConditionType type = DefineableConditionType.NONE;
public string data = "";
public DefineableCondition condition1;
public DefineableCondition condition2;
CompareType _compareType;
string _obj;
ShaderProperty _propertyObj;
string _value;
float _floatValue;
bool _hasConstantValue;
bool _constantValue;
bool _isInit = false;
public void Init()
{
if (_isInit) return;
_hasConstantValue = true;
if (type == DefineableConditionType.NONE) { _constantValue = true; }
else if (type == DefineableConditionType.TRUE) { _constantValue = true; }
else if (type == DefineableConditionType.FALSE) { _constantValue = false; }
else
{
var (compareType, compareString) = GetComparetor();
_compareType = compareType;
string[] parts = Regex.Split(data, compareString);
_obj = parts[0];
_value = parts[parts.Length - 1];
_floatValue = Parser.ParseFloat(_value);
if (ShaderEditor.Active != null && ShaderEditor.Active.PropertyDictionary.ContainsKey(_obj))
_propertyObj = ShaderEditor.Active.PropertyDictionary[_obj];
if (type == DefineableConditionType.EDITOR_VERSION) InitEditorVersion();
else if (type == DefineableConditionType.VRC_SDK_VERSION) InitVRCSDKVersion();
else _hasConstantValue = false;
}
_isInit = true;
}
void InitEditorVersion()
{
int c_ev = Helper.CompareVersions(Config.Singleton.verion, _value);
if (_compareType == CompareType.EQUAL) _constantValue = c_ev == 0;
if (_compareType == CompareType.NOT_EQUAL) _constantValue = c_ev != 0;
if (_compareType == CompareType.SMALLER) _constantValue = c_ev == 1;
if (_compareType == CompareType.BIGGER) _constantValue = c_ev == -1;
if (_compareType == CompareType.BIGGER_EQ) _constantValue = c_ev == -1 || c_ev == 0;
if (_compareType == CompareType.SMALLER_EQ) _constantValue = c_ev == 1 || c_ev == 0;
}
void InitVRCSDKVersion()
{
if (VRCInterface.Get().Sdk_information.type == VRCInterface.VRC_SDK_Type.NONE)
{
_constantValue = false;
return;
}
int c_vrc = Helper.CompareVersions(VRCInterface.Get().Sdk_information.installed_version, _value);
if (_compareType == CompareType.EQUAL) _constantValue = c_vrc == 0;
if (_compareType == CompareType.NOT_EQUAL) _constantValue = c_vrc != 0;
if (_compareType == CompareType.SMALLER) _constantValue = c_vrc == 1;
if (_compareType == CompareType.BIGGER) _constantValue = c_vrc == -1;
if (_compareType == CompareType.BIGGER_EQ) _constantValue = c_vrc == -1 || c_vrc == 0;
if (_compareType == CompareType.SMALLER_EQ) _constantValue = c_vrc == 1 || c_vrc == 0;
}
public bool Test()
{
Init();
if (_hasConstantValue) return _constantValue;
switch (type)
{
case DefineableConditionType.PROPERTY_BOOL:
if (_propertyObj == null) return false;
if (_compareType == CompareType.NONE) return _propertyObj.MaterialProperty.floatValue == 1;
if (_compareType == CompareType.EQUAL) return _propertyObj.MaterialProperty.floatValue == _floatValue;
if (_compareType == CompareType.NOT_EQUAL) return _propertyObj.MaterialProperty.floatValue != _floatValue;
if (_compareType == CompareType.SMALLER) return _propertyObj.MaterialProperty.floatValue < _floatValue;
if (_compareType == CompareType.BIGGER) return _propertyObj.MaterialProperty.floatValue > _floatValue;
if (_compareType == CompareType.BIGGER_EQ) return _propertyObj.MaterialProperty.floatValue >= _floatValue;
if (_compareType == CompareType.SMALLER_EQ) return _propertyObj.MaterialProperty.floatValue <= _floatValue;
break;
case DefineableConditionType.TEXTURE_SET:
if (_propertyObj == null) return false;
return _propertyObj.MaterialProperty.textureValue != null;
case DefineableConditionType.DROPDOWN:
if (_propertyObj == null) return false;
if (_compareType == CompareType.NONE) return _propertyObj.MaterialProperty.floatValue == 1;
if (_compareType == CompareType.EQUAL) return "" + _propertyObj.MaterialProperty.floatValue == _value;
if (_compareType == CompareType.NOT_EQUAL) return "" + _propertyObj.MaterialProperty.floatValue != _value;
break;
case DefineableConditionType.AND:
if(condition1!=null&&condition2!=null) return condition1.Test() && condition2.Test();
break;
case DefineableConditionType.OR:
if (condition1 != null && condition2 != null) return condition1.Test() || condition2.Test();
break;
}
return true;
}
private (CompareType,string) GetComparetor()
{
if (data.Contains("=="))
return (CompareType.EQUAL,"==");
if (data.Contains("!="))
return (CompareType.NOT_EQUAL,"!=");
if (data.Contains(">="))
return (CompareType.BIGGER_EQ,">=");
if (data.Contains("<="))
return (CompareType.SMALLER_EQ,"<=");
if (data.Contains(">"))
return (CompareType.BIGGER,">");
if (data.Contains("<"))
return (CompareType.SMALLER,"<");
return (CompareType.NONE,"##");
}
public override string ToString()
{
switch (type)
{
case DefineableConditionType.PROPERTY_BOOL:
return data;
case DefineableConditionType.EDITOR_VERSION:
return "EDITOR_VERSION" + data;
case DefineableConditionType.VRC_SDK_VERSION:
return "VRC_SDK_VERSION" + data;
case DefineableConditionType.AND:
if (condition1 != null && condition2 != null) return "("+condition1.ToString() + "&&" + condition2.ToString()+")";
break;
case DefineableConditionType.OR:
if (condition1 != null && condition2 != null) return "("+condition1.ToString()+"||"+condition2.ToString()+")";
break;
}
return "";
}
private static DefineableCondition ParseForThryParser(string s)
{
return Parse(s);
}
public static DefineableCondition Parse(string s)
{
s = Strip(s);
int depth = 0;
for (int i = 0; i < s.Length - 1; i++)
{
char c = s[i];
char cc = s[i + 1];
if (c == '(')
depth++;
else if (c == ')')
depth--;
if (depth == 0)
{
if (c == '&' && cc == '&')
{
DefineableCondition con = new DefineableCondition();
con.type = DefineableConditionType.AND;
con.condition1 = Parse(s.Substring(0, i));
con.condition2 = Parse(s.Substring(i + 2, s.Length - i - 2));
return con;
}
if (c == '|' && cc == '|')
{
DefineableCondition con = new DefineableCondition();
con.type = DefineableConditionType.OR;
con.condition1 = Parse(s.Substring(0, i));
con.condition2 = Parse(s.Substring(i + 2, s.Length - i - 2));
return con;
}
}
}
for (int i = 0; i < s.Length - 1; i++)
{
char c = s[i];
char cc = s[i + 1];
if (c == '(')
depth++;
else if (c == ')')
depth--;
if (depth == 0)
{
if (c == '>' || c=='<' || c=='=' || c == '!')
{
DefineableCondition con = new DefineableCondition();
con.data = s;
con.type = DefineableConditionType.PROPERTY_BOOL;
if (s.StartsWith("VRCSDK"))
{
con.type = DefineableConditionType.VRC_SDK_VERSION;
con.data = s.Replace("VRCSDK", "");
}else if (s.StartsWith("ThryEditor"))
{
con.type = DefineableConditionType.VRC_SDK_VERSION;
con.data = s.Replace("ThryEditor", "");
}
return con;
}
}
}
return new DefineableCondition();
}
private static string Strip(string s)
{
s = s.Trim();
if (s.StartsWith("(") == false)
return s;
bool stripKlammer = true;
int depth = 0;
int i = 0;
foreach (char c in s)
{
if (c == '(')
depth++;
else if (c == ')')
depth--;
if (depth == 0 && i != 0 && i != s.Length - 1)
stripKlammer = false;
i++;
}
if (stripKlammer)
return Strip(s.Substring(1, s.Length - 2));
return s;
}
}
enum CompareType { NONE,BIGGER,SMALLER,EQUAL,NOT_EQUAL,BIGGER_EQ,SMALLER_EQ }
public enum DefineableConditionType
{
NONE,
TRUE,
FALSE,
PROPERTY_BOOL,
EDITOR_VERSION,
VRC_SDK_VERSION,
TEXTURE_SET,
DROPDOWN,
AND,
OR
}
#endregion
#region Module Data
public class Module
{
public string id;
public string url = "";
public string author;
public string path;
public bool is_being_installed_or_removed = false;
public bool available_requirement_fullfilled = true;
public bool update_available = false;
public ModuleLocationData location_data;
public ModuleInfo available_module = null;
public ModuleInfo installed_module = null;
public bool ui_expanded = false;
}
public class ModuleInfo
{
public string name = "";
public string version = "0";
public string description = "";
public string classname = "";
public DefineableCondition requirement;
public List<string> files;
}
public class ModuleLocationData
{
public string guid;
public string classname;
public string[] files;
}
#endregion
}
|