// JSONValidator using UnityEngine; using UnityEditor; using System; 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 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 Texture2D icon = (Texture2D)(AssetDatabase.LoadAssetAtPath("Assets/TotalJSON/Internal/Editor/window-icon.png", typeof(Texture2D))); window.titleContent = new GUIContent("JSON Validator",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