| | 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 | |
|
| | 7 | | using System; |
| | 8 | | using UnityEngine.UIElements; |
| | 9 | |
|
| | 10 | | namespace GDX.Developer |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Thread-safe developer watch system. |
| | 14 | | /// </summary> |
| | 15 | | public class BooleanWatch : WatchBase |
| | 16 | | { |
| | 17 | | const string k_FalseText = "False"; |
| | 18 | | const string k_TrueText = "True"; |
| | 19 | |
|
| | 20 | | readonly Func<bool> m_GetValue; |
| | 21 | | bool m_CachedHash; |
| | 22 | |
|
| | 23 | | readonly Label m_DisplayNameLabel; |
| | 24 | | readonly Label m_ValueLabel; |
| | 25 | |
|
| | 26 | | public BooleanWatch(string uniqueIdentifier, string displayName, Func<bool> getValue, bool enabled = true, int m |
| 0 | 27 | | : base(uniqueIdentifier, displayName, enabled, minWidth, minHeight) |
| 0 | 28 | | { |
| 0 | 29 | | m_GetValue = getValue; |
| | 30 | |
|
| 0 | 31 | | m_DisplayNameLabel = new Label() { text = displayName }; |
| 0 | 32 | | m_DisplayNameLabel.AddToClassList("gdx-watch-left"); |
| | 33 | |
|
| 0 | 34 | | m_ValueLabel = new Label(); |
| 0 | 35 | | m_ValueLabel.AddToClassList("gdx-watch-right"); |
| | 36 | |
|
| 0 | 37 | | ContainerElement.Add(m_DisplayNameLabel); |
| 0 | 38 | | ContainerElement.Add(m_ValueLabel); |
| 0 | 39 | | } |
| | 40 | |
|
| | 41 | | public override void Poll() |
| 0 | 42 | | { |
| | 43 | | // Poll for our new value |
| 0 | 44 | | bool getValue = m_GetValue(); |
| | 45 | |
|
| | 46 | | // Only change if legit change |
| 0 | 47 | | if (m_CachedHash != getValue) |
| 0 | 48 | | { |
| 0 | 49 | | m_ValueLabel.text = getValue ? k_TrueText : k_FalseText; |
| 0 | 50 | | m_CachedHash = getValue; |
| 0 | 51 | | } |
| 0 | 52 | | } |
| | 53 | | } |
| | 54 | | } |
| | 55 | |
|
| | 56 | | #endif // UNITY_2022_2_OR_NEWER |