Skip to content

Commit a4f5ea2

Browse files
committed
Fix (bypass) first initialization bug when searching type
Add editorconfig for coding style control
1 parent 6bcd760 commit a4f5ea2

File tree

9 files changed

+356
-310
lines changed

9 files changed

+356
-310
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/Helpers.cs

Lines changed: 97 additions & 90 deletions
Large diffs are not rendered by default.

UInspectorPlus/HexEdit.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal class HexEdit {
1212

1313
public float Height {
1414
get {
15-
if (data == null) return 0;
15+
if(data == null) return 0;
1616
return (data.Length + columns) / columns * (EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing);
1717
}
1818
}
@@ -24,18 +24,18 @@ public void DrawGUI(bool hasLabel = false, params GUILayoutOption[] options) {
2424
public void Draw(Rect viewport) {
2525
float height = EditorGUIUtility.singleLineHeight;
2626
float padHeight = height + EditorGUIUtility.standardVerticalSpacing;
27-
if (data != null) {
27+
if(data != null) {
2828
temp.text = data.Length.ToString("X8");
2929
Vector2 labelSize = GUI.skin.label.CalcSize(temp);
3030
Rect contentRect = new Rect(0, 0, labelSize.x + (columns * 1.7F + 2) * height, Height);
3131
GUI.Box(viewport, GUIContent.none, GUI.skin.textArea);
3232
scrollPos = GUI.BeginScrollView(viewport, scrollPos, contentRect);
3333
bool changed = GUI.changed;
3434
GUI.changed = false;
35-
for (int start = Mathf.FloorToInt(scrollPos.y / padHeight) * columns,
35+
for(int start = Mathf.FloorToInt(scrollPos.y / padHeight) * columns,
3636
end = Math.Min(data.Length, start + Mathf.CeilToInt(viewport.height / padHeight) * columns),
3737
col = start; col < end; col++) {
38-
if (col % columns == 0) {
38+
if(col % columns == 0) {
3939
temp.text = col.ToString("X8");
4040
GUI.Label(new Rect(0, col / columns * padHeight, labelSize.x, labelSize.y), temp);
4141
}
@@ -48,11 +48,11 @@ public void Draw(Rect viewport) {
4848
data[col].ToString("X2"),
4949
2, GUI.skin.label
5050
);
51-
if (GUI.changed) {
51+
if(GUI.changed) {
5252
GUI.changed = false;
5353
changed = true;
5454
int val;
55-
if (int.TryParse(newValue, NumberStyles.HexNumber, null, out val))
55+
if(int.TryParse(newValue, NumberStyles.HexNumber, null, out val))
5656
data[col] = unchecked((byte)val);
5757
}
5858
string newStr = GUI.TextField(
@@ -64,7 +64,7 @@ public void Draw(Rect viewport) {
6464
Byte2String(data[col]),
6565
1, GUI.skin.label
6666
);
67-
if (GUI.changed) {
67+
if(GUI.changed) {
6868
GUI.changed = false;
6969
changed = true;
7070
data[col] = newStr.Length > 0 ? unchecked((byte)newStr[0]) : (byte)0;
@@ -76,8 +76,8 @@ public void Draw(Rect viewport) {
7676
}
7777

7878
private static string Byte2String(byte b) {
79-
if (b < 32) return ((char)(b | 0x2400)).ToString();
80-
if (b >= 127) return ".";
79+
if(b < 32) return ((char)(b | 0x2400)).ToString();
80+
if(b >= 127) return ".";
8181
return ((char)b).ToString();
8282
}
8383
}

UInspectorPlus/InspectorChildWindow.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public static void Open(object target, bool showProps, bool showPrivate, bool sh
1616
.InternalOpen(target, target.GetType(), showProps, showPrivate, showObsolete, showMethods, updateProps, parent);
1717
}
1818

19-
public static void OpenStatic(Type targetType, bool showProps, bool showPrivate, bool showObsolete, bool showMethods, bool updateProps, MethodPropertyDrawer parent)
20-
{
19+
public static void OpenStatic(Type targetType, bool showProps, bool showPrivate, bool showObsolete, bool showMethods, bool updateProps, MethodPropertyDrawer parent) {
2120
CreateInstance<InspectorChildWindow>()
2221
.InternalOpen(null, targetType, showProps, showPrivate, showObsolete, showMethods, updateProps, parent);
2322
}
@@ -38,7 +37,7 @@ private void OnGUI() {
3837
updateProps = GUILayout.Toggle(updateProps, "Update Props", EditorStyles.toolbarButton);
3938
GUILayout.Space(8);
4039
drawer.searchText = EditorGUILayout.TextField(drawer.searchText, Helper.GetGUIStyle("ToolbarSeachTextField"));
41-
if (GUILayout.Button(
40+
if(GUILayout.Button(
4241
GUIContent.none,
4342
Helper.GetGUIStyle(
4443
string.IsNullOrEmpty(drawer.searchText) ?
@@ -54,13 +53,13 @@ private void OnGUI() {
5453
scrollPos = GUILayout.BeginScrollView(scrollPos);
5554
EditorGUILayout.Space();
5655
drawer.Draw(false, isReadOnly);
57-
if (drawer.changed) {
56+
if(drawer.changed) {
5857
drawer.changed = false;
59-
if (parent != null && !parent.IsReadOnly &&
58+
if(parent != null && !parent.IsReadOnly &&
6059
((parent.requiredType != null && parent.requiredType.IsValueType) || parent.Value != drawer.target))
61-
if (!Helper.AssignValue(parent.Info, parent.Target, drawer.target)) {
60+
if(!Helper.AssignValue(parent.Info, parent.Target, drawer.target)) {
6261
object reverted;
63-
if (Helper.FetchValue(parent.Info, parent.Target, out reverted))
62+
if(Helper.FetchValue(parent.Info, parent.Target, out reverted))
6463
drawer.target = reverted;
6564
}
6665
}
@@ -69,7 +68,7 @@ private void OnGUI() {
6968
}
7069

7170
private void OnInspectorUpdate() {
72-
if (EditorGUIUtility.editingTextField)
71+
if(EditorGUIUtility.editingTextField)
7372
return;
7473
UpdateValues();
7574
}
@@ -78,9 +77,8 @@ private void UpdateValues() {
7877
drawer.UpdateValues(updateProps);
7978
}
8079

81-
private void IterateDrawers<T>(Action<T> each) where T : IReflectorDrawer
82-
{
83-
foreach (var methodDrawer in drawer.drawer.OfType<T>())
80+
private void IterateDrawers<T>(Action<T> each) where T : IReflectorDrawer {
81+
foreach(var methodDrawer in drawer.drawer.OfType<T>())
8482
each(methodDrawer);
8583
}
8684
}

UInspectorPlus/InspectorDrawer.cs

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,53 +32,53 @@ public InspectorDrawer(object target, Type targetType, bool shown, bool showProp
3232
drawer = new List<IReflectorDrawer>();
3333
removingDrawers = new HashSet<IReflectorDrawer>();
3434
BindingFlags flag = BindingFlags.Static | BindingFlags.Public;
35-
if (target != null)
35+
if(target != null)
3636
flag |= BindingFlags.Instance;
37-
if (allowPrivate = showPrivateFields)
37+
if(allowPrivate = showPrivateFields)
3838
flag |= BindingFlags.NonPublic;
3939
this.targetType = targetType;
4040
elementType = Helper.GetGenericListType(targetType);
4141
var fields = targetType.GetFields(flag);
4242
var props = !showProps ? null : targetType.GetProperties(flag).Where(prop => prop.GetIndexParameters().Length == 0).ToArray();
4343
isInternalType = !targetType.IsSubclassOf(typeof(MonoBehaviour)) || Attribute.IsDefined(targetType, typeof(ExecuteInEditMode));
44-
foreach (var field in fields)
44+
foreach(var field in fields)
4545
try {
46-
if (!showObsolete && Attribute.IsDefined(field, typeof(ObsoleteAttribute)))
46+
if(!showObsolete && Attribute.IsDefined(field, typeof(ObsoleteAttribute)))
4747
continue;
4848
drawer.Add(new MethodPropertyDrawer(field, target, showPrivateFields, showObsolete) {
4949
AllowReferenceMode = false
5050
});
51-
} catch (Exception ex) {
51+
} catch(Exception ex) {
5252
Debug.LogException(ex);
5353
}
54-
if (showProps) {
54+
if(showProps) {
5555
HashSet<string> blacklistedType;
56-
if (!Helper.blackListedTypes.TryGetValue(targetType, out blacklistedType)) {
56+
if(!Helper.blackListedTypes.TryGetValue(targetType, out blacklistedType)) {
5757
Helper.blackListedTypes.Add(targetType, blacklistedType = new HashSet<string>());
58-
foreach (var kvp in Helper.blackListedTypes)
59-
if (kvp.Key.IsAssignableFrom(targetType))
58+
foreach(var kvp in Helper.blackListedTypes)
59+
if(kvp.Key.IsAssignableFrom(targetType))
6060
blacklistedType.UnionWith(kvp.Value);
6161
}
62-
foreach (var prop in props)
62+
foreach(var prop in props)
6363
try {
64-
if (blacklistedType != null && blacklistedType.Contains(prop.Name))
64+
if(blacklistedType != null && blacklistedType.Contains(prop.Name))
6565
continue;
66-
if (!showObsolete && Attribute.IsDefined(prop, typeof(ObsoleteAttribute)))
66+
if(!showObsolete && Attribute.IsDefined(prop, typeof(ObsoleteAttribute)))
6767
continue;
6868
drawer.Add(new MethodPropertyDrawer(prop, target, showPrivateFields, showObsolete, prop.CanRead && EditorApplication.isPlaying) {
6969
AllowReferenceMode = false,
7070
Updatable = isInternalType || Helper.GetState(prop, false),
7171
ShowUpdatable = !isInternalType
7272
});
73-
} catch (Exception ex) {
73+
} catch(Exception ex) {
7474
Debug.LogException(ex);
7575
}
7676
}
77-
if (allowMethods = showMethods)
77+
if(allowMethods = showMethods)
7878
AddMethodMenu();
79-
foreach (var d in drawer)
79+
foreach(var d in drawer)
8080
d.OnRequireRedraw += RequireRedraw;
81-
if (target != null)
81+
if(target != null)
8282
this.shown = Helper.GetState(target, shown);
8383
}
8484

@@ -92,29 +92,29 @@ private void AddMethodMenu() {
9292
}
9393

9494
public void Draw(bool drawHeader = true, bool readOnly = false) {
95-
if (drawHeader) {
95+
if(drawHeader) {
9696
shown = EditorGUILayout.InspectorTitlebar(shown, target as UnityObject);
97-
if (target != null)
97+
if(target != null)
9898
Helper.StoreState(target, shown);
99-
if (!shown)
99+
if(!shown)
100100
return;
101101
}
102102
EditorGUI.indentLevel++;
103103
EditorGUILayout.BeginVertical();
104-
if (target is Type && GUILayout.Button(string.Format("Inspect Static Members of {0}...", target)))
104+
if(target is Type && GUILayout.Button(string.Format("Inspect Static Members of {0}...", target)))
105105
InspectorChildWindow.OpenStatic(target as Type, true, allowPrivate, false, true, false, null);
106-
else if (target != null && elementType != null) {
107-
if (targetType == typeof(byte[])) {
108-
if (hexEdit == null)
106+
else if(target != null && elementType != null) {
107+
if(targetType == typeof(byte[])) {
108+
if(hexEdit == null)
109109
hexEdit = new HexEdit();
110110
hexEdit.data = target as byte[];
111-
if (hexEdit.data != null)
111+
if(hexEdit.data != null)
112112
hexEdit.DrawGUI(false, GUILayout.MinHeight(EditorGUIUtility.singleLineHeight * 3), GUILayout.ExpandHeight(true));
113-
} else if (showListEdit = EditorGUILayout.Foldout(showListEdit, string.Format("Edit List [{0} Items]", (target as IList).Count))) {
114-
if (arrayHandler == null) {
115-
if (arrayContentDrawer == null) {
113+
} else if(showListEdit = EditorGUILayout.Foldout(showListEdit, string.Format("Edit List [{0} Items]", (target as IList).Count))) {
114+
if(arrayHandler == null) {
115+
if(arrayContentDrawer == null) {
116116
arrayContentDrawer = new List<MethodPropertyDrawer>();
117-
for (int i = 0; i < (target as IList).Count; i++)
117+
for(int i = 0; i < (target as IList).Count; i++)
118118
ListAddItem();
119119
}
120120
arrayHandler = new ReorderableList(target as IList, elementType) {
@@ -123,7 +123,7 @@ public void Draw(bool drawHeader = true, bool readOnly = false) {
123123
drawElementCallback = (r, i, c, d) => {
124124
arrayContentDrawer[i].Value = (target as IList)[i];
125125
arrayContentDrawer[i].Draw(false, Helper.ScaleRect(r, offsetHeight: -2));
126-
if (arrayContentDrawer[i].Changed)
126+
if(arrayContentDrawer[i].Changed)
127127
(target as IList)[i] = arrayContentDrawer[i].Value;
128128
},
129129
drawHeaderCallback = r => GUI.Label(r, target.ToString(), EditorStyles.miniBoldLabel),
@@ -142,14 +142,14 @@ public void Draw(bool drawHeader = true, bool readOnly = false) {
142142
arrayHandler.DoLayoutList();
143143
}
144144
}
145-
if (removingDrawers.Count > 0) {
145+
if(removingDrawers.Count > 0) {
146146
drawer.RemoveAll(removingDrawers.Contains);
147147
removingDrawers.Clear();
148148
}
149-
foreach (var item in drawer) {
149+
foreach(var item in drawer) {
150150
var methodDrawer = item as ComponentMethodDrawer;
151151
var fieldDrawer = item as MethodPropertyDrawer;
152-
if (methodDrawer != null) {
152+
if(methodDrawer != null) {
153153
EditorGUI.indentLevel--;
154154
EditorGUILayout.BeginHorizontal();
155155
EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(EditorGUIUtility.singleLineHeight));
@@ -158,20 +158,20 @@ public void Draw(bool drawHeader = true, bool readOnly = false) {
158158
EditorGUILayout.EndVertical();
159159
EditorGUILayout.EndHorizontal();
160160
EditorGUI.indentLevel++;
161-
} else if (item != null) {
162-
if (item.Info != null && !string.IsNullOrEmpty(searchText) && item.Info.Name.IndexOf(searchText, StringComparison.CurrentCultureIgnoreCase) < 0)
161+
} else if(item != null) {
162+
if(item.Info != null && !string.IsNullOrEmpty(searchText) && item.Info.Name.IndexOf(searchText, StringComparison.CurrentCultureIgnoreCase) < 0)
163163
continue;
164-
if (fieldDrawer != null)
164+
if(fieldDrawer != null)
165165
fieldDrawer.Draw(readOnly);
166166
else
167167
item.Draw();
168168
changed |= item.UpdateIfChanged();
169169
}
170170
}
171-
if (allowMethods) {
171+
if(allowMethods) {
172172
GUILayout.BeginHorizontal();
173173
GUILayout.FlexibleSpace();
174-
if (GUILayout.Button(new GUIContent("+", "Add Method / Index Properties Watcher"), EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
174+
if(GUILayout.Button(new GUIContent("+", "Add Method / Index Properties Watcher"), EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
175175
AddMethodMenu();
176176
GUILayout.EndHorizontal();
177177
}
@@ -186,20 +186,20 @@ private void ListAddItem(object value = null) {
186186
}
187187

188188
public void UpdateValues(bool updateProps) {
189-
if (target == null) return;
190-
foreach (var drawerItem in drawer) {
189+
if(target == null) return;
190+
foreach(var drawerItem in drawer) {
191191
var propDrawer = drawerItem as MethodPropertyDrawer;
192-
if (propDrawer == null)
192+
if(propDrawer == null)
193193
continue;
194194
var isPropInfo = propDrawer.Info is PropertyInfo;
195-
if (!isInternalType && (!updateProps || !propDrawer.Updatable) && isPropInfo)
195+
if(!isInternalType && (!updateProps || !propDrawer.Updatable) && isPropInfo)
196196
continue;
197197
propDrawer.UpdateValue();
198198
}
199199
}
200200

201201
private void RequireRedraw() {
202-
if (target != null && OnRequireRedraw != null)
202+
if(target != null && OnRequireRedraw != null)
203203
OnRequireRedraw();
204204
}
205205
}

0 commit comments

Comments
 (0)