< Summary

Class:GDX.Developer.FloatRangeWatch
Assembly:GDX
File(s):./Packages/com.dotbunny.gdx/GDX/Developer/Watches/FloatRangeWatch.cs
Covered lines:0
Uncovered lines:27
Coverable lines:27
Total lines:59
Line coverage:0% (0 of 27)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:2
Method coverage:0% (0 of 2)

Coverage History

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FloatRangeWatch(...)0%2100%
Poll()0%12300%

File(s)

./Packages/com.dotbunny.gdx/GDX/Developer/Watches/FloatRangeWatch.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
 6
 7using System;
 8using Unity.Mathematics;
 9using UnityEngine.UIElements;
 10
 11namespace GDX.Developer
 12{
 13    public class FloatRangeWatch : WatchBase
 14    {
 15        readonly Func<float> m_GetValue;
 16        readonly Func<float, Sentiment> m_GetSentiment;
 17
 18        Sentiment m_CachedSentiment;
 019        float m_CachedValue = float.MinValue;
 20
 21        readonly Label m_ValueLabel;
 22
 23        public FloatRangeWatch(string uniqueIdentifier, string displayName, Func<float> getValue, Func<float, Sentiment>
 024            : base(uniqueIdentifier, displayName, enabled, minWidth, minHeight)
 025        {
 026            m_GetValue = getValue;
 027            m_GetSentiment = getSentiment;
 28
 029            Label displayNameLabel = new Label() { text = displayName };
 030            displayNameLabel.AddToClassList("gdx-watch-left");
 31
 032            m_ValueLabel = new Label();
 033            m_ValueLabel.AddToClassList("gdx-watch-right");
 034            m_ValueLabel.AddToClassList("default");
 35
 036            ContainerElement.Add(displayNameLabel);
 037            ContainerElement.Add(m_ValueLabel);
 038        }
 39
 40        public override void Poll()
 041        {
 042            float getValue = m_GetValue();
 043            if (math.lengthsq(getValue - m_CachedValue) != Platform.FloatTolerance)
 044            {
 045                m_ValueLabel.text = getValue.ToString();
 046                Sentiment sentiment = m_GetSentiment(getValue);
 047                if (sentiment != m_CachedSentiment)
 048                {
 49                    // Add colors
 050                    AddSentimentToElement(m_ValueLabel, sentiment);
 051                    m_CachedSentiment = sentiment;
 052                    m_CachedValue = getValue;
 053                }
 054            }
 055        }
 56    }
 57}
 58
 59#endif // UNITY_2022_2_OR_NEWER