Skip to content

Commit 368c307

Browse files
committed
Merge branch 'master' of github.com:JLChnToZ/UnityScriptTester
2 parents 6ae4c21 + 293dd03 commit 368c307

File tree

11 files changed

+491
-354
lines changed

11 files changed

+491
-354
lines changed

UInspectorPlus/.editorconfig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[*]
2+
end_of_line = crlf
3+
4+
[*.xml]
5+
indent_style = space
6+
7+
# My C# coding style (Modified K&R)
8+
[*.cs]
9+
csharp_new_line_before_open_brace = none
10+
csharp_new_line_before_else = false
11+
csharp_new_line_before_catch = false
12+
csharp_new_line_before_finally = false
13+
csharp_new_line_before_members_in_object_initializers = true
14+
csharp_new_line_before_members_in_anonymous_types = true
15+
csharp_new_line_between_query_expression_clauses = true
16+
csharp_indent_case_contents = true
17+
csharp_indent_switch_labels = true
18+
csharp_indent_labels= no_change
19+
csharp_space_after_cast = false
20+
csharp_space_after_keywords_in_control_flow_statements = false
21+
csharp_space_between_method_declaration_parameter_list_parentheses = false
22+
csharp_space_between_method_call_parameter_list_parentheses = false
23+
csharp_space_before_colon_in_inheritance_clause = false
24+
csharp_space_after_colon_in_inheritance_clause = true
25+
csharp_space_around_binary_operators = before_and_after
26+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
27+
csharp_space_between_method_call_name_and_opening_parenthesis = false
28+
csharp_space_between_method_call_empty_parameter_list_parentheses = false

UInspectorPlus/ComponentMethodDrawer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public ComponentMethodDrawer(Type type)
9696
public string Filter {
9797
get { return filter; }
9898
set {
99+
if(filter == value) return;
99100
filter = value;
100101
InitComponentMethods(false);
101102
}

UInspectorPlus/Helpers.cs

Lines changed: 130 additions & 91 deletions
Large diffs are not rendered by default.

UInspectorPlus/HexEdit.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class HexEdit: InspectorDrawer {
1515

1616
public float Height {
1717
get {
18-
if (Data == null) return 0;
18+
if(Data == null) return 0;
1919
return (Data.Length + columns) / columns * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
2020
}
2121
}
@@ -25,7 +25,7 @@ public HexEdit(object target, Type targetType, bool shown, bool showProps, bool
2525
}
2626

2727
protected override void Draw(bool readOnly) {
28-
if (Data != null)
28+
if(Data != null)
2929
Draw(EditorGUILayout.GetControlRect(
3030
false, Height, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight * 3), GUILayout.ExpandHeight(true)
3131
));
@@ -36,18 +36,18 @@ protected override void Draw(bool readOnly) {
3636
private void Draw(Rect viewport) {
3737
float height = EditorGUIUtility.singleLineHeight;
3838
float padHeight = height + EditorGUIUtility.standardVerticalSpacing;
39-
if (Data != null) {
39+
if(Data != null) {
4040
temp.text = Data.Length.ToString("X8");
4141
Vector2 labelSize = GUI.skin.label.CalcSize(temp);
4242
Rect contentRect = new Rect(0, 0, labelSize.x + (columns * 1.7F + 2) * height, Height);
4343
GUI.Box(viewport, GUIContent.none, GUI.skin.textArea);
4444
scrollPos = GUI.BeginScrollView(viewport, scrollPos, contentRect);
4545
bool changed = GUI.changed;
4646
GUI.changed = false;
47-
for (int start = Mathf.FloorToInt(scrollPos.y / padHeight) * columns,
47+
for(int start = Mathf.FloorToInt(scrollPos.y / padHeight) * columns,
4848
end = Math.Min(Data.Length, start + Mathf.CeilToInt(viewport.height / padHeight) * columns),
4949
col = start; col < end; col++) {
50-
if (col % columns == 0) {
50+
if(col % columns == 0) {
5151
temp.text = col.ToString("X8");
5252
GUI.Label(new Rect(0, col / columns * padHeight, labelSize.x, labelSize.y), temp);
5353
}
@@ -60,11 +60,11 @@ private void Draw(Rect viewport) {
6060
Data[col].ToString("X2"),
6161
2, GUI.skin.label
6262
);
63-
if (GUI.changed) {
63+
if(GUI.changed) {
6464
GUI.changed = false;
6565
changed = true;
6666
int val;
67-
if (int.TryParse(newValue, NumberStyles.HexNumber, null, out val))
67+
if(int.TryParse(newValue, NumberStyles.HexNumber, null, out val))
6868
Data[col] = unchecked((byte)val);
6969
}
7070
string newStr = GUI.TextField(
@@ -76,7 +76,7 @@ private void Draw(Rect viewport) {
7676
Byte2String(Data[col]),
7777
1, GUI.skin.label
7878
);
79-
if (GUI.changed) {
79+
if(GUI.changed) {
8080
GUI.changed = false;
8181
changed = true;
8282
Data[col] = newStr.Length > 0 ? unchecked((byte)newStr[0]) : (byte)0;
@@ -88,8 +88,8 @@ private void Draw(Rect viewport) {
8888
}
8989

9090
private static string Byte2String(byte b) {
91-
if (b < 32) return ((char)(b | 0x2400)).ToString();
92-
if (b >= 127) return ".";
91+
if(b < 32) return ((char)(b | 0x2400)).ToString();
92+
if(b >= 127) return ".";
9393
return ((char)b).ToString();
9494
}
9595
}

UInspectorPlus/InspectorChildWindow.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,21 @@ private void OnGUI() {
3131
GUILayout.BeginHorizontal(EditorStyles.toolbar);
3232
updateProps = GUILayout.Toggle(updateProps, "Update Props", EditorStyles.toolbarButton);
3333
GUILayout.Space(8);
34-
drawer.searchText = EditorGUILayout.TextField(drawer.searchText, Helper.GetGUIStyle("ToolbarSeachTextField"));
35-
if (GUILayout.Button(
36-
GUIContent.none,
37-
Helper.GetGUIStyle(
38-
string.IsNullOrEmpty(drawer.searchText) ?
39-
"ToolbarSeachCancelButtonEmpty" :
40-
"ToolbarSeachCancelButton"
41-
)
42-
)) {
43-
drawer.searchText = string.Empty;
44-
GUI.FocusControl(null);
45-
}
34+
drawer.searchText = Helper.ToolbarSearchField(drawer.searchText ?? string.Empty);
4635
GUILayout.FlexibleSpace();
4736
GUILayout.EndHorizontal();
4837
scrollPos = GUILayout.BeginScrollView(scrollPos);
4938
EditorGUILayout.Space();
5039
drawer.Draw(false, isReadOnly);
51-
if (drawer.changed) {
40+
if(drawer.changed) {
5241
drawer.changed = false;
53-
if (parent != null && !parent.IsReadOnly &&
54-
((parent.requiredType != null && parent.requiredType.IsValueType) || parent.Value != drawer.target) &&
55-
!Helper.AssignValue(parent.Info, parent.Target, drawer.target) && Helper.FetchValue(parent.Info, parent.Target, out var reverted))
56-
drawer.target = reverted;
42+
if(parent != null && !parent.IsReadOnly &&
43+
((parent.requiredType != null && parent.requiredType.IsValueType) || parent.Value != drawer.target))
44+
if(!Helper.AssignValue(parent.Info, parent.Target, drawer.target)) {
45+
object reverted;
46+
if(Helper.FetchValue(parent.Info, parent.Target, out reverted))
47+
drawer.target = reverted;
48+
}
5749
}
5850
GUILayout.FlexibleSpace();
5951
GUILayout.EndScrollView();
@@ -64,7 +56,7 @@ private void OnDestroy() {
6456
}
6557

6658
private void OnInspectorUpdate() {
67-
if (EditorGUIUtility.editingTextField)
59+
if(EditorGUIUtility.editingTextField)
6860
return;
6961
UpdateValues();
7062
}

UInspectorPlus/InspectorDrawer.cs

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,19 @@ public static void RegisterCustomInspectorDrawer<T>(Type targetType, int priorit
3737
}
3838

3939
public static InspectorDrawer GetDrawer(object target, Type targetType, bool shown, bool showProps, bool showPrivateFields, bool showObsolete, bool showMethods) {
40-
foreach (var type in AppDomain.CurrentDomain.GetAssemblies()
40+
foreach(var type in AppDomain.CurrentDomain.GetAssemblies()
4141
.SelectMany(asm => asm.GetTypes())
4242
.Where(type => type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(InspectorDrawer))))
4343
RuntimeHelpers.RunClassConstructor(type.TypeHandle);
4444
int lastPriority = int.MinValue;
4545
Type drawerType = null;
4646
try {
47-
foreach (var kv in typedDrawers)
48-
if (kv.targetType.IsAssignableFrom(targetType) && kv.priority > lastPriority)
47+
foreach(var kv in typedDrawers)
48+
if(kv.targetType.IsAssignableFrom(targetType) && kv.priority > lastPriority)
4949
drawerType = kv.drawerType;
50-
if (drawerType != null)
50+
if(drawerType != null)
5151
return Activator.CreateInstance(drawerType, target, targetType, shown, showProps, showPrivateFields, showObsolete, showMethods) as InspectorDrawer;
52-
} catch (Exception ex) {
52+
} catch(Exception ex) {
5353
Debug.LogException(ex);
5454
Debug.LogWarning($"Failed to instaniate drawer {drawerType.Name}, will fall back to default drawer.");
5555
}
@@ -59,52 +59,52 @@ public static InspectorDrawer GetDrawer(object target, Type targetType, bool sho
5959
public InspectorDrawer(object target, Type targetType, bool shown, bool showProps, bool showPrivateFields, bool showObsolete, bool showMethods) {
6060
this.target = target;
6161
BindingFlags flag = BindingFlags.Static | BindingFlags.Public;
62-
if (target != null)
62+
if(target != null)
6363
flag |= BindingFlags.Instance;
64-
if (allowPrivate = showPrivateFields)
64+
if(allowPrivate = showPrivateFields)
6565
flag |= BindingFlags.NonPublic;
6666
this.targetType = targetType;
6767
var fields = targetType.GetFields(flag);
6868
var props = !showProps ? null : targetType.GetProperties(flag).Where(prop => prop.GetIndexParameters().Length == 0).ToArray();
6969
isInternalType = !targetType.IsSubclassOf(typeof(MonoBehaviour)) || Attribute.IsDefined(targetType, typeof(ExecuteInEditMode));
70-
foreach (var field in fields)
70+
foreach(var field in fields)
7171
try {
72-
if (!showObsolete && Attribute.IsDefined(field, typeof(ObsoleteAttribute)))
72+
if(!showObsolete && Attribute.IsDefined(field, typeof(ObsoleteAttribute)))
7373
continue;
7474
drawer.Add(new MethodPropertyDrawer(field, target, showPrivateFields, showObsolete) {
7575
AllowReferenceMode = false
7676
});
77-
} catch (Exception ex) {
77+
} catch(Exception ex) {
7878
Debug.LogException(ex);
7979
}
80-
if (showProps) {
80+
if(showProps) {
8181
HashSet<string> blacklistedType;
82-
if (!Helper.blackListedTypes.TryGetValue(targetType, out blacklistedType)) {
82+
if(!Helper.blackListedTypes.TryGetValue(targetType, out blacklistedType)) {
8383
Helper.blackListedTypes.Add(targetType, blacklistedType = new HashSet<string>());
84-
foreach (var kvp in Helper.blackListedTypes)
85-
if (kvp.Key.IsAssignableFrom(targetType))
84+
foreach(var kvp in Helper.blackListedTypes)
85+
if(kvp.Key.IsAssignableFrom(targetType))
8686
blacklistedType.UnionWith(kvp.Value);
8787
}
88-
foreach (var prop in props)
88+
foreach(var prop in props)
8989
try {
90-
if (blacklistedType != null && blacklistedType.Contains(prop.Name))
90+
if(blacklistedType != null && blacklistedType.Contains(prop.Name))
9191
continue;
92-
if (!showObsolete && Attribute.IsDefined(prop, typeof(ObsoleteAttribute)))
92+
if(!showObsolete && Attribute.IsDefined(prop, typeof(ObsoleteAttribute)))
9393
continue;
9494
drawer.Add(new MethodPropertyDrawer(prop, target, showPrivateFields, showObsolete, prop.CanRead && EditorApplication.isPlaying) {
9595
AllowReferenceMode = false,
9696
Updatable = isInternalType || Helper.GetState(prop, false),
9797
ShowUpdatable = !isInternalType
9898
});
99-
} catch (Exception ex) {
99+
} catch(Exception ex) {
100100
Debug.LogException(ex);
101101
}
102102
}
103-
if (allowMethods = showMethods)
103+
if(allowMethods = showMethods)
104104
AddMethodMenu();
105-
foreach (var d in drawer)
105+
foreach(var d in drawer)
106106
d.OnRequireRedraw += RequireRedraw;
107-
if (target != null)
107+
if(target != null)
108108
this.shown = Helper.GetState(target, shown);
109109
}
110110

@@ -118,11 +118,11 @@ private void AddMethodMenu() {
118118
}
119119

120120
public void Draw(bool drawHeader = true, bool readOnly = false) {
121-
if (drawHeader) {
121+
if(drawHeader) {
122122
shown = EditorGUILayout.InspectorTitlebar(shown, target as UnityObject);
123-
if (target != null)
123+
if(target != null)
124124
Helper.StoreState(target, shown);
125-
if (!shown)
125+
if(!shown)
126126
return;
127127
}
128128
EditorGUI.indentLevel++;
@@ -131,80 +131,81 @@ public void Draw(bool drawHeader = true, bool readOnly = false) {
131131
Draw(readOnly);
132132
EditorGUILayout.EndVertical();
133133
EditorGUI.indentLevel--;
134-
if (removingDrawers.Count > 0) {
135-
foreach (var drawer in removingDrawers)
136-
if (drawer is IDisposable disposable)
134+
if(removingDrawers.Count > 0) {
135+
foreach(var drawer in removingDrawers)
136+
if(drawer is IDisposable disposable)
137137
disposable.Dispose();
138138
drawer.RemoveAll(removingDrawers.Contains);
139139
removingDrawers.Clear();
140140
}
141141
}
142142

143143
protected virtual void Draw(bool readOnly) {
144-
foreach (var item in drawer) {
144+
foreach(var item in drawer) {
145145
var methodDrawer = item as ComponentMethodDrawer;
146146
var fieldDrawer = item as MethodPropertyDrawer;
147-
if (methodDrawer != null) {
147+
if(methodDrawer != null) {
148148
EditorGUI.indentLevel--;
149149
EditorGUILayout.BeginHorizontal();
150150
EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(EditorGUIUtility.singleLineHeight));
151151
EditorGUILayout.BeginVertical();
152+
methodDrawer.Filter = searchText;
152153
methodDrawer.Draw();
153154
EditorGUILayout.EndVertical();
154155
EditorGUILayout.EndHorizontal();
155156
EditorGUI.indentLevel++;
156-
} else if (item != null) {
157-
if (item.Info != null && !string.IsNullOrEmpty(searchText) && item.Info.Name.IndexOf(searchText, StringComparison.CurrentCultureIgnoreCase) < 0)
157+
} else if(item != null) {
158+
if(item.Info != null && !string.IsNullOrEmpty(searchText) && item.Info.Name.IndexOf(searchText, StringComparison.CurrentCultureIgnoreCase) < 0)
158159
continue;
159-
if (fieldDrawer != null)
160+
if(fieldDrawer != null)
160161
fieldDrawer.Draw(readOnly);
161162
else
162163
item.Draw();
163164
changed |= item.UpdateIfChanged();
164165
}
165166
}
166-
if (allowMethods) {
167+
if(allowMethods) {
167168
GUILayout.BeginHorizontal();
168169
GUILayout.FlexibleSpace();
169-
if (GUILayout.Button(new GUIContent("+", "Add Method / Index Properties Watcher"), EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
170+
if(GUILayout.Button(new GUIContent("+", "Add Method / Index Properties Watcher"), EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
170171
AddMethodMenu();
171172
GUILayout.EndHorizontal();
172173
}
173174
}
174175

175176
private void DrawRequestRefs() {
176177
MethodPropertyDrawer removal = null;
177-
foreach (var drawer in MethodPropertyDrawer.drawerRequestingReferences)
178-
if (drawer.requiredType.IsAssignableFrom(targetType) &&
178+
foreach(var drawer in MethodPropertyDrawer.drawerRequestingReferences)
179+
if(drawer.requiredType.IsAssignableFrom(targetType) &&
179180
GUILayout.Button($"Assign this object to {drawer.name}")) {
180181
drawer.Value = target;
181182
removal = drawer;
182183
}
183-
if (removal != null) MethodPropertyDrawer.drawerRequestingReferences.Remove(removal);
184+
if(removal != null) MethodPropertyDrawer.drawerRequestingReferences.Remove(removal);
184185
}
185186

186187
public void UpdateValues(bool updateProps) {
187-
if (target == null) return;
188-
foreach (var drawerItem in drawer) {
188+
if(target == null) return;
189+
foreach(var drawerItem in drawer) {
189190
var propDrawer = drawerItem as MethodPropertyDrawer;
190-
if (propDrawer == null)
191+
if(propDrawer == null)
191192
continue;
192193
var isPropInfo = propDrawer.Info is PropertyInfo;
193-
if (!isInternalType && (!updateProps || !propDrawer.Updatable) && isPropInfo)
194+
if(!isInternalType && (!updateProps || !propDrawer.Updatable) && isPropInfo)
194195
continue;
195196
propDrawer.UpdateValue();
196197
}
197198
}
198199

199200
public virtual void Dispose() {
200-
foreach (var d in drawer)
201-
if (d is IDisposable disposable)
201+
foreach(var d in drawer)
202+
if(d is IDisposable disposable)
202203
disposable.Dispose();
203204
drawer.Clear();
204205
}
205206

206207
protected void RequireRedraw() {
207-
if (target != null && OnRequireRedraw != null)
208+
if(target != null && OnRequireRedraw != null)
208209
OnRequireRedraw();
209210
}
210211
}

0 commit comments

Comments
 (0)