// JSONRuntimeDebug using UnityEngine; using UnityEditor; using System.Collections.Generic; namespace Leguar.TotalJSON.Internal { public class JSONRuntimeDebug : EditorWindow { private static int selected = 0; private static List latestObjects; private static bool previousWasPlaying = false; private static bool coloredOutput = true; private static GUIStyle coloredTextareaStyle; [MenuItem("Window/Total JSON/JSON Runtime Debug")] static void Init() { JSONRuntimeDebug window=(JSONRuntimeDebug)(GetWindow(typeof(JSONRuntimeDebug))); #if UNITY_5 || UNITY_2017 window.titleContent = new GUIContent("JSON Runtime Debug"); #else window.titleContent = new GUIContent("JSON Runtime Debug",JSONValidator.loadWindowIcon()); #endif } void OnGUI() { GUILayout.Space(15); if (!Application.isPlaying) { if (latestObjects==null) { GUILayout.Label("Application is not running. This debug is available only when application is running and some JSON/JArray object is added to debug.", EditorStyles.wordWrappedLabel); } else { GUILayout.Label("Application is not running. Below is last state of JSON/JArray objects from previous run.", EditorStyles.wordWrappedLabel); if (previousWasPlaying) { foreach (DebugObject latestObject in latestObjects) { latestObject.refresh(); } } outputLatestContent(); } previousWasPlaying=false; return; } else { previousWasPlaying=true; } JSONRuntimeDebugContainer jsonRuntimeDebugContainer=null; GameObject jsonDebugObject=GameObject.Find("TotalJSON_DebugObject"); if (jsonDebugObject!=null) { jsonRuntimeDebugContainer=jsonDebugObject.GetComponent(); } if (jsonRuntimeDebugContainer==null) { GUILayout.Label("Application is running but no JSON objects are added to debug.", EditorStyles.wordWrappedLabel); latestObjects=null; return; } GUILayout.Label("Choose object below to show:", EditorStyles.wordWrappedLabel); if (latestObjects==null) { latestObjects=new List(); } Dictionary currentContent=jsonRuntimeDebugContainer.getContent(); foreach (string key in currentContent.Keys) { int listIndex=getDebugObjectIndex(key); if (listIndex>=0) { if (latestObjects[listIndex].getValue()!=currentContent[key]) { latestObjects[listIndex].replace(currentContent[key]); } } else { latestObjects.Add(new DebugObject(key,currentContent[key])); } } outputLatestContent(); } private int getDebugObjectIndex(string key) { for (int n=0; n