Skip to content

Commit 4be1fbb

Browse files
committed
Update project version to Unity 5.3.4
- Teared off windows while inspecting the objects are non-selectable - Removed Script Tester as the method calling functions can be obtain from Inspector+ - Force serialize everything as plain text (Git Friendly) - Code reformatted.
1 parent 0b23db6 commit 4be1fbb

25 files changed

+1306
-1300
lines changed

Assets/Script Tester/Editor/ComponentMethodDrawer.cs

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

Assets/Script Tester/Editor/Helpers.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,5 @@ internal static GUIStyle GetGUIStyle(string styleName) {
453453
public static void ShowInspectorPlus() {
454454
EditorWindow.GetWindow(typeof(InspectorPlus));
455455
}
456-
457-
[MenuItem("Window/Script Tester/Method Caller")]
458-
public static void ShowMethodCaller() {
459-
EditorWindow.GetWindow(typeof(TestingScript));
460-
}
461456
}
462457
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
4+
namespace ScriptTester {
5+
class InspectorChildWindow: EditorWindow {
6+
InspectorDrawer drawer;
7+
Vector2 scrollPos;
8+
bool updateProps;
9+
10+
public static void Open(object target, bool showProps, bool showPrivate, bool showObsolete, bool showMethods, bool updateProps) {
11+
CreateInstance<InspectorChildWindow>().InternalOpen(target, showProps, showPrivate, showObsolete, showMethods, updateProps);
12+
}
13+
14+
void InternalOpen(object target, bool showProps, bool showPrivate, bool showObsolete, bool showMethods, bool updateProps) {
15+
#if UNITY_4
16+
title = string.Format("{0} - Inspector+", target);
17+
#else
18+
titleContent = new GUIContent(string.Format("{0} - Inspector+", target));
19+
#endif
20+
drawer = new InspectorDrawer(target, true, showProps, showPrivate, showObsolete, showMethods);
21+
drawer.OnRequireRedraw += Repaint;
22+
this.updateProps = updateProps;
23+
ShowUtility();
24+
UpdateValues();
25+
}
26+
27+
void OnGUI() {
28+
GUILayout.BeginHorizontal(EditorStyles.toolbar);
29+
updateProps = GUILayout.Toggle(updateProps, "Update Props", EditorStyles.toolbarButton);
30+
GUILayout.Space(8);
31+
drawer.searchText = EditorGUILayout.TextField(drawer.searchText, Helper.GetGUIStyle("ToolbarSeachTextField"));
32+
if(GUILayout.Button(GUIContent.none, Helper.GetGUIStyle(string.IsNullOrEmpty(drawer.searchText) ? "ToolbarSeachCancelButtonEmpty" : "ToolbarSeachCancelButton"))) {
33+
drawer.searchText = string.Empty;
34+
GUI.FocusControl(null);
35+
}
36+
GUILayout.FlexibleSpace();
37+
GUILayout.EndHorizontal();
38+
scrollPos = GUILayout.BeginScrollView(scrollPos);
39+
EditorGUILayout.Space();
40+
drawer.Draw(false);
41+
GUILayout.FlexibleSpace();
42+
GUILayout.EndScrollView();
43+
}
44+
45+
void OnInspectorUpdate() {
46+
if(EditorGUIUtility.editingTextField)
47+
return;
48+
UpdateValues();
49+
}
50+
51+
void UpdateValues() {
52+
drawer.UpdateValues(updateProps);
53+
}
54+
}
55+
}

Assets/Script Tester/Editor/TestingScript.cs.meta renamed to Assets/Script Tester/Editor/InspectorChildWindow.cs.meta

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Script Tester/Editor/InspectorDrawer.cs

Lines changed: 124 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -7,127 +7,128 @@
77
using UnityObject = UnityEngine.Object;
88

99
namespace ScriptTester {
10-
class InspectorDrawer {
11-
public object target;
12-
public List<IReflectorDrawer> drawer;
13-
public bool shown;
14-
public bool isInternalType;
15-
public string searchText;
16-
public event Action OnRequireRedraw;
17-
Type targetType;
18-
19-
public InspectorDrawer(object target, bool shown, bool showProps, bool showPrivateFields, bool showObsolete, bool showMethods) {
20-
this.target = target;
21-
this.drawer = new List<IReflectorDrawer>();
22-
BindingFlags flag = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
23-
if(showPrivateFields)
24-
flag |= BindingFlags.NonPublic;
25-
targetType = target.GetType();
26-
var fields = targetType.GetFields(flag);
27-
var props = !showProps ? null : targetType.GetProperties(flag).Where(prop => prop.GetIndexParameters().Length == 0).ToArray();
28-
isInternalType = !(target is MonoBehaviour) || Attribute.IsDefined(target.GetType(), typeof(ExecuteInEditMode));
29-
foreach(var field in fields)
30-
try {
31-
if(!showObsolete && Attribute.IsDefined(field, typeof(ObsoleteAttribute)))
32-
continue;
33-
drawer.Add(new MethodPropertyDrawer(field.FieldType, Helper.GetMemberName(field, true), field.GetValue(target), showPrivateFields, showObsolete) {
34-
AllowReferenceMode = false,
35-
Info = field
36-
});
37-
} catch(Exception ex) {
38-
Debug.LogException(ex);
39-
}
40-
if(showProps)
41-
foreach(var prop in props)
42-
try {
43-
if(!showObsolete && Attribute.IsDefined(prop, typeof(ObsoleteAttribute)))
44-
continue;
45-
drawer.Add(new MethodPropertyDrawer(prop.PropertyType, Helper.GetMemberName(prop, true), prop.CanRead && EditorApplication.isPlaying ? prop.GetValue(target, null) : null, showPrivateFields, showObsolete) {
46-
AllowReferenceMode = false,
47-
Info = prop,
48-
Updatable = isInternalType || Helper.GetState<bool>(prop, true),
49-
ShowUpdatable = !isInternalType
50-
});
51-
} catch(Exception ex) {
52-
Debug.LogException(ex);
53-
}
54-
if(showMethods)
55-
drawer.Add(new ComponentMethodDrawer(target) { AllowPrivateFields = showPrivateFields });
56-
foreach(var d in drawer)
57-
d.OnRequireRedraw += RequireRedraw;
58-
this.shown = Helper.GetState<bool>(target, shown);
59-
}
60-
61-
public void Draw(bool drawHeader = true, bool readOnly = false) {
62-
if(drawHeader) {
63-
shown = EditorGUILayout.InspectorTitlebar(shown, target as UnityObject);
64-
Helper.StoreState(target, shown);
65-
if(!shown)
66-
return;
67-
}
68-
EditorGUI.indentLevel++;
69-
EditorGUILayout.BeginVertical();
70-
foreach(var item in drawer) {
71-
var methodDrawer = item as ComponentMethodDrawer;
72-
var fieldDrawer = item as MethodPropertyDrawer;
73-
if(methodDrawer != null) {
74-
EditorGUI.indentLevel--;
75-
EditorGUILayout.BeginHorizontal();
76-
EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(EditorGUIUtility.singleLineHeight));
77-
EditorGUILayout.BeginVertical();
78-
methodDrawer.Draw();
79-
if(methodDrawer.Info != null && GUILayout.Button("Execute " + methodDrawer.Info.Name))
80-
methodDrawer.Call();
81-
EditorGUILayout.EndVertical();
82-
EditorGUILayout.EndHorizontal();
83-
EditorGUI.indentLevel++;
84-
} else if(item != null) {
85-
if(item.Info != null && !string.IsNullOrEmpty(searchText) && item.Info.Name.IndexOf(searchText, StringComparison.CurrentCultureIgnoreCase) < 0)
86-
continue;
87-
if(fieldDrawer != null)
88-
fieldDrawer.Draw(readOnly);
89-
else
90-
item.Draw();
91-
if(item.Changed) {
92-
if(!Helper.AssignValue(item.Info, target, item.Value)) {
93-
object value;
94-
var propDrawer = item as MethodPropertyDrawer;
95-
if(propDrawer != null) {
96-
var success = Helper.FetchValue(propDrawer.Info, target, out value);
97-
if(success) {
98-
propDrawer.Value = value;
99-
propDrawer.GetException = null;
100-
} else
101-
propDrawer.GetException = value as Exception;
102-
}
103-
}
104-
}
105-
}
106-
}
107-
EditorGUILayout.EndVertical();
108-
EditorGUI.indentLevel--;
109-
}
110-
111-
public void UpdateValues(bool updateProps) {
112-
foreach(var drawerItem in drawer) {
113-
var propDrawer = drawerItem as MethodPropertyDrawer;
114-
if(propDrawer == null)
115-
continue;
116-
var isPropInfo = propDrawer.Info is PropertyInfo;
117-
if(!isInternalType && (!updateProps || !propDrawer.Updatable) && isPropInfo)
118-
continue;
119-
object value;
120-
if(Helper.FetchValue(propDrawer.Info, target, out value)) {
121-
propDrawer.Value = value;
122-
propDrawer.GetException = null;
123-
} else
124-
propDrawer.GetException = value as Exception;
125-
}
126-
}
127-
128-
void RequireRedraw() {
129-
if(OnRequireRedraw != null)
130-
OnRequireRedraw();
131-
}
132-
}
10+
class InspectorDrawer {
11+
public object target;
12+
public List<IReflectorDrawer> drawer;
13+
public bool shown;
14+
public bool isInternalType;
15+
public string searchText;
16+
public event Action OnRequireRedraw;
17+
Type targetType;
18+
19+
public InspectorDrawer(object target, bool shown, bool showProps, bool showPrivateFields, bool showObsolete, bool showMethods) {
20+
this.target = target;
21+
this.drawer = new List<IReflectorDrawer>();
22+
BindingFlags flag = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
23+
if(showPrivateFields)
24+
flag |= BindingFlags.NonPublic;
25+
targetType = target.GetType();
26+
var fields = targetType.GetFields(flag);
27+
var props = !showProps ? null : targetType.GetProperties(flag).Where(prop => prop.GetIndexParameters().Length == 0).ToArray();
28+
isInternalType = !(target is MonoBehaviour) || Attribute.IsDefined(target.GetType(), typeof(ExecuteInEditMode));
29+
foreach(var field in fields)
30+
try {
31+
if(!showObsolete && Attribute.IsDefined(field, typeof(ObsoleteAttribute)))
32+
continue;
33+
drawer.Add(new MethodPropertyDrawer(field.FieldType, Helper.GetMemberName(field, true), field.GetValue(target), showPrivateFields, showObsolete) {
34+
AllowReferenceMode = false,
35+
Info = field
36+
});
37+
} catch(Exception ex) {
38+
Debug.LogException(ex);
39+
}
40+
if(showProps)
41+
foreach(var prop in props)
42+
try {
43+
if(!showObsolete && Attribute.IsDefined(prop, typeof(ObsoleteAttribute)))
44+
continue;
45+
drawer.Add(new MethodPropertyDrawer(prop.PropertyType, Helper.GetMemberName(prop, true), prop.CanRead && EditorApplication.isPlaying ? prop.GetValue(target, null) : null, showPrivateFields, showObsolete) {
46+
AllowReferenceMode = false,
47+
Info = prop,
48+
Updatable = isInternalType || Helper.GetState<bool>(prop, true),
49+
ShowUpdatable = !isInternalType
50+
});
51+
} catch(Exception ex) {
52+
Debug.LogException(ex);
53+
}
54+
if(showMethods)
55+
drawer.Add(new ComponentMethodDrawer(target) { AllowPrivateFields = showPrivateFields });
56+
foreach(var d in drawer)
57+
d.OnRequireRedraw += RequireRedraw;
58+
this.shown = Helper.GetState<bool>(target, shown);
59+
}
60+
61+
public void Draw(bool drawHeader = true, bool readOnly = false) {
62+
if(drawHeader) {
63+
shown = EditorGUILayout.InspectorTitlebar(shown, target as UnityObject);
64+
Helper.StoreState(target, shown);
65+
if(!shown)
66+
return;
67+
}
68+
EditorGUI.indentLevel++;
69+
EditorGUILayout.BeginVertical();
70+
foreach(var item in drawer) {
71+
var methodDrawer = item as ComponentMethodDrawer;
72+
var fieldDrawer = item as MethodPropertyDrawer;
73+
if(methodDrawer != null) {
74+
EditorGUILayout.Space();
75+
EditorGUI.indentLevel--;
76+
EditorGUILayout.BeginHorizontal();
77+
EditorGUILayout.LabelField(GUIContent.none, GUILayout.Width(EditorGUIUtility.singleLineHeight));
78+
EditorGUILayout.BeginVertical();
79+
methodDrawer.Draw();
80+
if(methodDrawer.Info != null && GUILayout.Button("Execute " + methodDrawer.Info.Name))
81+
methodDrawer.Call();
82+
EditorGUILayout.EndVertical();
83+
EditorGUILayout.EndHorizontal();
84+
EditorGUI.indentLevel++;
85+
} else if(item != null) {
86+
if(item.Info != null && !string.IsNullOrEmpty(searchText) && item.Info.Name.IndexOf(searchText, StringComparison.CurrentCultureIgnoreCase) < 0)
87+
continue;
88+
if(fieldDrawer != null)
89+
fieldDrawer.Draw(readOnly);
90+
else
91+
item.Draw();
92+
if(item.Changed) {
93+
if(!Helper.AssignValue(item.Info, target, item.Value)) {
94+
object value;
95+
var propDrawer = item as MethodPropertyDrawer;
96+
if(propDrawer != null) {
97+
var success = Helper.FetchValue(propDrawer.Info, target, out value);
98+
if(success) {
99+
propDrawer.Value = value;
100+
propDrawer.GetException = null;
101+
} else
102+
propDrawer.GetException = value as Exception;
103+
}
104+
}
105+
}
106+
}
107+
}
108+
EditorGUILayout.EndVertical();
109+
EditorGUI.indentLevel--;
110+
}
111+
112+
public void UpdateValues(bool updateProps) {
113+
foreach(var drawerItem in drawer) {
114+
var propDrawer = drawerItem as MethodPropertyDrawer;
115+
if(propDrawer == null)
116+
continue;
117+
var isPropInfo = propDrawer.Info is PropertyInfo;
118+
if(!isInternalType && (!updateProps || !propDrawer.Updatable) && isPropInfo)
119+
continue;
120+
object value;
121+
if(Helper.FetchValue(propDrawer.Info, target, out value)) {
122+
propDrawer.Value = value;
123+
propDrawer.GetException = null;
124+
} else
125+
propDrawer.GetException = value as Exception;
126+
}
127+
}
128+
129+
void RequireRedraw() {
130+
if(OnRequireRedraw != null)
131+
OnRequireRedraw();
132+
}
133+
}
133134
}

0 commit comments

Comments
 (0)