forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymbolDisableHighlight.cs
More file actions
83 lines (70 loc) · 2.14 KB
/
SymbolDisableHighlight.cs
File metadata and controls
83 lines (70 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
using UnityEngine;
using UnityEngine.UI;
namespace HoloToolkit.UI.Keyboard
{
public class SymbolDisableHighlight : MonoBehaviour
{
/// <summary>
/// The text field to update.
/// </summary>
[SerializeField]
private Text m_TextField;
/// <summary>
/// The text field to update.
/// </summary>
[SerializeField]
private Image m_ImageField;
/// <summary>
/// The color to switch to when the button is disabled.
/// </summary>
[SerializeField]
private Color m_DisabledColor = Color.grey;
/// <summary>
/// The color the text field starts as.
/// </summary>
private Color m_StartingColor;
/// <summary>
/// The button to check for disabled/enabled.
/// </summary>
private Button m_Button;
/// <summary>
/// Standard Unity start.
/// </summary>
private void Start()
{
if (m_TextField != null)
{
m_StartingColor = m_TextField.color;
}
if (m_ImageField != null)
{
m_StartingColor = m_ImageField.color;
}
m_Button = GetComponentInParent<Button>();
UpdateState();
}
/// <summary>
/// Standard Unity update.
/// </summary>
private void Update()
{
UpdateState();
}
/// <summary>
/// Updates the visual state of the text based on the buttons state.
/// </summary>
private void UpdateState()
{
if (m_TextField != null && m_Button != null)
{
m_TextField.color = m_Button.interactable ? m_StartingColor : m_DisabledColor;
}
if (m_ImageField != null && m_Button != null)
{
m_ImageField.color = m_Button.interactable ? m_StartingColor : m_DisabledColor;
}
}
}
}