// 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; [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 Texture2D icon = (Texture2D)(AssetDatabase.LoadAssetAtPath("Assets/TotalJSON/Internal/Editor/window-icon.png", typeof(Texture2D))); window.titleContent = new GUIContent("JSON Runtime Debug",icon); #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."); } else { GUILayout.Label("Application is not running. Below is last state of JSON/Jarray objects from previous run."); 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."); latestObjects=null; return; } GUILayout.Label("Application is running, choose object below to show."); 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