Skip to content

Commit 443138c

Browse files
committed
Add namespaces;
Fix compile errors in JSONChecker if PERFTEST is defined
1 parent 169edc8 commit 443138c

File tree

3 files changed

+1364
-1149
lines changed

3 files changed

+1364
-1149
lines changed

Editor/JSONChecker.cs

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
using UnityEngine.Networking;
77
#endif
88

9+
#if PERFTEST && UNITY_5_6_OR_NEWER
10+
using UnityEngine.Profiling;
11+
#endif
12+
913
/*
1014
Copyright (c) 2010-2019 Matt Schoen
1115
@@ -28,8 +32,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2832
THE SOFTWARE.
2933
*/
3034

31-
public class JSONChecker : EditorWindow {
32-
string JSON = @"{
35+
namespace Defective.JSON {
36+
public class JSONChecker : EditorWindow {
37+
string JSON = @"{
3338
""TestObject"": {
3439
""SomeText"": ""Blah"",
3540
""SomeObject"": {
@@ -43,70 +48,77 @@ public class JSONChecker : EditorWindow {
4348
""SomeEmptyArray"": [ ],
4449
""EmbeddedObject"": ""{\""field\"":\""Value with \\\""escaped quotes\\\""\""}""
4550
}
46-
}"; //dat string literal...
47-
string URL = "";
48-
JSONObject j;
49-
[MenuItem("Window/JSONChecker")]
50-
static void Init() {
51-
GetWindow(typeof(JSONChecker));
52-
}
53-
void OnGUI() {
54-
JSON = EditorGUILayout.TextArea(JSON);
55-
GUI.enabled = !string.IsNullOrEmpty(JSON);
56-
if(GUILayout.Button("Check JSON")) {
51+
}"; //dat string literal...
52+
53+
string URL = "";
54+
JSONObject j;
55+
56+
[MenuItem("Window/JSONChecker")]
57+
static void Init() {
58+
GetWindow(typeof(JSONChecker));
59+
}
60+
61+
void OnGUI() {
62+
JSON = EditorGUILayout.TextArea(JSON);
63+
GUI.enabled = !string.IsNullOrEmpty(JSON);
64+
if (GUILayout.Button("Check JSON")) {
5765
#if PERFTEST
58-
Profiler.BeginSample("JSONParse");
59-
j = JSONObject.Create(JSON);
60-
Profiler.EndSample();
61-
Profiler.BeginSample("JSONStringify");
62-
j.ToString(true);
63-
Profiler.EndSample();
66+
Profiler.BeginSample("JSONParse");
67+
j = JSONObject.Create(JSON);
68+
Profiler.EndSample();
69+
Profiler.BeginSample("JSONStringify");
70+
j.ToString(true);
71+
Profiler.EndSample();
6472
#else
65-
j = JSONObject.Create(JSON);
73+
j = JSONObject.Create(JSON);
6674
#endif
67-
Debug.Log(j.ToString(true));
68-
}
69-
EditorGUILayout.Separator();
70-
URL = EditorGUILayout.TextField("URL", URL);
71-
if (GUILayout.Button("Get JSON")) {
72-
Debug.Log(URL);
75+
Debug.Log(j.ToString(true));
76+
}
77+
78+
EditorGUILayout.Separator();
79+
URL = EditorGUILayout.TextField("URL", URL);
80+
if (GUILayout.Button("Get JSON")) {
81+
Debug.Log(URL);
7382
#if UNITY_2017_1_OR_NEWER
74-
var test = new UnityWebRequest(URL);
83+
var test = new UnityWebRequest(URL);
7584

7685
#if UNITY_2017_2_OR_NEWER
77-
test.SendWebRequest();
86+
test.SendWebRequest();
7887
#else
7988
test.Send();
8089
#endif
8190
#if UNITY_2020_1_OR_NEWER
8291
while (!test.isDone && test.result != UnityWebRequest.Result.ConnectionError) { }
8392
#else
84-
while (!test.isDone && !test.isNetworkError) {}
93+
while (!test.isDone && !test.isNetworkError) {
94+
}
8595
#endif
8696
#else
8797
var test = new WWW(URL);
8898
while (!test.isDone) ;
8999
#endif
90-
if (!string.IsNullOrEmpty(test.error)) {
91-
Debug.Log(test.error);
92-
} else {
100+
if (!string.IsNullOrEmpty(test.error)) {
101+
Debug.Log(test.error);
102+
} else {
93103
#if UNITY_2017_1_OR_NEWER
94-
var text = test.downloadHandler.text;
104+
var text = test.downloadHandler.text;
95105
#else
96106
var text = test.text;
97107
#endif
98-
Debug.Log(text);
99-
j = new JSONObject(text);
100-
Debug.Log(j.ToString(true));
108+
Debug.Log(text);
109+
j = new JSONObject(text);
110+
Debug.Log(j.ToString(true));
111+
}
101112
}
102-
}
103-
if(j) {
104-
//Debug.Log(System.GC.GetTotalMemory(false) + "");
105-
if(j.type == JSONObject.Type.NULL)
106-
GUILayout.Label("JSON fail:\n" + j.ToString(true));
107-
else
108-
GUILayout.Label("JSON success:\n" + j.ToString(true));
109113

114+
if (j) {
115+
//Debug.Log(System.GC.GetTotalMemory(false) + "");
116+
if (j.type == JSONObject.Type.NULL)
117+
GUILayout.Label("JSON fail:\n" + j.ToString(true));
118+
else
119+
GUILayout.Label("JSON success:\n" + j.ToString(true));
120+
121+
}
110122
}
111123
}
112-
}
124+
}

0 commit comments

Comments
 (0)