Пример #1
0
        internal static JSONRuntimeDebugContainer getDebugContainer()
        {
            GameObject jsonDebugObject = GameObject.Find("TotalJSON_DebugObject");

            if (jsonDebugObject == null)
            {
                jsonDebugObject           = new GameObject("TotalJSON_DebugObject");
                jsonDebugObject.hideFlags = HideFlags.HideInHierarchy;
                GameObject.DontDestroyOnLoad(jsonDebugObject);
            }
            JSONRuntimeDebugContainer jsonRuntimeDebugContainer = jsonDebugObject.GetComponent <JSONRuntimeDebugContainer>();

            if (jsonRuntimeDebugContainer == null)
            {
                jsonRuntimeDebugContainer = jsonDebugObject.AddComponent <JSONRuntimeDebugContainer>();
            }
            return(jsonRuntimeDebugContainer);
        }
Пример #2
0
        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 <JSONRuntimeDebugContainer>();
            }
            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 <DebugObject>();
            }

            Dictionary <string, JValue> 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();
        }