// JSONValidator using UnityEngine; using UnityEditor; using System.Text; using Leguar.TotalJSON; namespace Leguar.TotalJSON.Internal { public class JSONValidator : EditorWindow { private string editorAreaText="Write or copy & paste JSON object or JSON array to this text area. Example JSON:\n\n{\"name\":\"Player\",\"lastLogin\":123456789012,\"achievements\":[42,1337,1703],\"imageUrl\":null,\"have_bought\":true,\"levels\":[{\"passed\":true,\"score\":12345},{\"passed\":false}]}\n\nExtra texts like this before or after JSON object will be removed when clicking button below."; private string message = ""; private string tightJSON = ""; private string escapedJSON = ""; private Vector2 scrollPos; private readonly float lineHeight=EditorGUIUtility.singleLineHeight; [MenuItem("Window/Total JSON/JSON Validator")] static void Init() { JSONValidator window=(JSONValidator)(GetWindow(typeof(JSONValidator))); #if UNITY_5 || UNITY_2017 window.titleContent = new GUIContent("JSON Validator"); #else window.titleContent = new GUIContent("JSON Validator",loadWindowIcon()); #endif } #if !(UNITY_5 || UNITY_2017) internal static Texture2D loadWindowIcon() { string dirPath = AssetDatabase.GUIDToAssetPath("9f2fdab21a6aeaf41956a4d04ddf4dd2"); // "Assets/TotalJSON/Internal/Editor" string iconPath = dirPath+"/window-icon.png"; Texture2D icon = (Texture2D)(AssetDatabase.LoadAssetAtPath(iconPath, typeof(Texture2D))); return icon; } #endif void OnGUI() { GUILayout.Space(20); scrollPos = EditorGUILayout.BeginScrollView(scrollPos); EditorGUI.BeginChangeCheck(); editorAreaText = EditorGUILayout.TextArea(editorAreaText,GUILayout.ExpandHeight(true)); bool changes = EditorGUI.EndChangeCheck(); EditorGUILayout.EndScrollView(); if (changes) { message = ""; tightJSON = ""; escapedJSON = ""; } GUILayout.Space(10); if (GUILayout.Button("Trim, validate and prettify above JSON object or array")) { string trimmedEditorText=editorAreaText.Trim(); if (trimmedEditorText.Length=0 && (jArrayStartIndex