< Summary

Class:GDX.Developer.RuntimeWatchController
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/RuntimeWatchController.cs
Covered lines:0
Uncovered lines:64
Coverable lines:64
Total lines:117
Line coverage:0% (0 of 64)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:10
Method coverage:0% (0 of 10)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RuntimeWatchController(...)0%2100%
RuntimeWatchController()0%2100%
UpdateFontSize(...)0%2100%
UpdatePosition(...)0%2100%
UpdateShow(...)0%6200%
Tick()0%72800%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/RuntimeWatchController.cs

#LineLine coverage
 1// Copyright (c) 2020-2024 dotBunny Inc.
 2// dotBunny licenses this file to you under the BSL-1.0 license.
 3// See the LICENSE file in the project root for more information.
 4
 5#if UNITY_2022_2_OR_NEWER
 6using System.Net.Mail;
 7using GDX.Developer.ConsoleVariables;
 8using GDX.RuntimeContent;
 9using UnityEngine;
 10using UnityEngine.UIElements;
 11#endif
 12
 13namespace GDX.Developer
 14{
 15#if UNITY_2022_2_OR_NEWER
 16    public class RuntimeWatchController
 17    {
 18        const string k_GameObjectName = "GDX_Watches";
 19
 020        public UIDocument Document { get; private set; }
 021        public GameObject WatchesGameObject { get; private set; }
 22
 023        int m_FontSize = 14;
 24        ushort m_LastVersion;
 25        readonly VisualElement m_RootElement;
 026        bool m_ShouldShow = false;
 27
 028        static readonly BooleanConsoleVariable k_WatchesEnabled =
 29            new BooleanConsoleVariable("watches.enabled", "Watches Enabled", true,
 30                ConsoleVariableBase.ConsoleVariableFlags.Setting);
 31
 032        public RuntimeWatchController(GameObject parentGameObject, int initialFontSize, int position, bool visible)
 033        {
 34            // UIDocuments do not allow multiple components per Game Object so we have to make a child object.
 035            WatchesGameObject = new GameObject(k_GameObjectName);
 036            WatchesGameObject.transform.SetParent(parentGameObject.transform, false);
 37
 38            // Create isolated UI document  (thanks Damian, boy do I feel stupid.)
 039            Document = WatchesGameObject.AddComponent<UIDocument>();
 040            Document.sortingOrder = float.MaxValue; // Above all
 041            Document.visualTreeAsset = ResourceProvider.GetUIElements().Watches;
 42
 043            m_RootElement = Document.rootVisualElement.Q<VisualElement>("gdx-watches");
 44
 045            k_WatchesEnabled.OnValueChanged += UpdateShow;
 46
 047            UpdateFontSize(initialFontSize);
 048            UpdatePosition(position);
 049            UpdateShow(visible);
 050        }
 51
 52        public void UpdateFontSize(int fontSize)
 053        {
 054            m_FontSize = fontSize;
 055        }
 56
 57        public void UpdatePosition(int position)
 058        {
 059            m_RootElement.ApplyAlignment((VisualElementStyles.Alignment)position);
 060        }
 61
 62        public void UpdateShow(bool show)
 063        {
 064            WatchProvider.SetGlobalState(show);
 065            if (show)
 066            {
 067                m_RootElement.Show();
 068                m_ShouldShow = true;
 069            }
 70            else
 071            {
 072                m_RootElement.Hide();
 073                m_ShouldShow = false;
 074            }
 075        }
 76
 77        public void Tick()
 078        {
 079            m_ShouldShow = WatchProvider.HasActiveWatches();
 080            if (m_ShouldShow && !m_RootElement.IsVisible())
 081            {
 082                m_RootElement.Show();
 083            }
 084            else if(!m_ShouldShow && m_RootElement.IsVisible())
 085            {
 086                m_RootElement.Hide();
 087            }
 88
 089            if (m_ShouldShow)
 090            {
 091                WatchProvider.Poll();
 92
 093                if (WatchProvider.Version != m_LastVersion)
 094                {
 95                    // We need to check that all of our elements are accounted for
 096                    VisualElement[] elements = WatchProvider.GetActiveElements();
 097                    int elementCount = elements.Length;
 98
 99                    // Clear from root
 0100                    m_RootElement.Clear();
 0101                    for (int i = 0; i < elementCount; i++)
 0102                    {
 0103                        m_RootElement.Add(elements[i]);
 0104                    }
 105
 0106                    m_LastVersion = WatchProvider.Version;
 0107                }
 0108            }
 109            else
 0110            {
 111
 0112            }
 113
 0114        }
 115    }
 116#endif // UNITY_2022_2_OR_NEWER
 117}