AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
CompoundButtonText.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using HoloToolkit.Unity;
5 using UnityEngine;
6 
7 namespace HoloToolkit.Unity.Buttons
8 {
9  [RequireComponent(typeof(CompoundButton))]
10  public class CompoundButtonText : ProfileButtonBase<ButtonTextProfile>
11  {
12  [DropDownComponent]
13  public TextMesh TextMesh;
14 
18  [EditableProp]
19  public bool DisableText {
20  get {
21  return disableText;
22  }
23  set {
24  if (disableText != value) {
25  disableText = value;
26  UpdateStyle();
27  }
28  }
29  }
30 
31  [ShowIfBoolValue("DisableText", false)]
32  [TextAreaProp(30)]
33  public string Text {
34  get {
35  if (TextMesh == null) {
36  return string.Empty;
37  }
38  return TextMesh.text;
39  }
40  set {
41  TextMesh.text = value;
42  }
43  }
44 
45  [ShowIfBoolValue("DisableText", false)]
46  [RangeProp(0f, 1f)]
47  public float Alpha {
48  get {
49  return alpha;
50  }
51  set {
52  if (value != alpha) {
53  alpha = value;
54  UpdateStyle();
55  }
56  }
57  }
58 
59  [ShowIfBoolValue("DisableText", false)]
60  [Tooltip("Disregard the text style in the profile")]
61  public bool OverrideFontStyle = false;
62 
63  [ShowIfBoolValue("OverrideFontStyle")]
64  [ShowIfBoolValue("DisableText", false)]
65  [Tooltip("Style to use for override.")]
66  public FontStyle Style;
67 
68  [ShowIfBoolValue("DisableText", false)]
69  [Tooltip("Disregard the anchor in the profile.")]
70  public bool OverrideAnchor = false;
71 
72  [ShowIfBoolValue("OverrideAnchor")]
73  [ShowIfBoolValue("DisableText", false)]
74  [Tooltip("Anchor to use for override.")]
75  public TextAnchor Anchor;
76 
77  [ShowIfBoolValue("DisableText", false)]
78  [Tooltip("Disregard the size in the profile.")]
79  public bool OverrideSize = false;
80 
81  [ShowIfBoolValue("OverrideSize")]
82  [ShowIfBoolValue("DisableText", false)]
83  [Tooltip("Size to use for override.")]
84  public int Size = 72;
85 
86  [ShowIfBoolValue("DisableText", false)]
87  [Tooltip("When true, no offset is applied to the text object.")]
88  public bool OverrideOffset = false;
89 
90  [SerializeField]
92  private float alpha = 1f;
93 
94  [SerializeField]
96  private bool disableText = false;
97 
98  private void OnEnable()
99  {
100  UpdateStyle();
101  }
102 
103  private void UpdateStyle()
104  {
105  if (TextMesh == null)
106  {
107  Debug.LogWarning("Text mesh was null in CompoundButtonText " + name);
108  return;
109  }
110 
111  if (DisableText)
112  {
113  TextMesh.gameObject.SetActive(false);
114  }
115  else
116  {
117  // Update text based on profile
118  if (Profile != null)
119  {
120  TextMesh.font = Profile.Font;
121  TextMesh.fontStyle = Profile.Style;
122  TextMesh.fontSize = OverrideSize ? Size : Profile.Size;
123  TextMesh.fontStyle = OverrideFontStyle ? Style : Profile.Style;
124  TextMesh.anchor = OverrideAnchor ? Anchor : Profile.Anchor;
125  TextMesh.alignment = Profile.Alignment;
126  Color c = Profile.Color;
127  c.a = alpha;
128  TextMesh.color = c;
129 
130  // Apply offset
131  if (!OverrideOffset)
132  {
133  TextMesh.transform.localPosition = Profile.GetOffset(TextMesh.anchor);
134  }
135 
136  TextMesh.gameObject.SetActive(true);
137  }
138  }
139  }
140 
141  private void OnDrawGizmos ()
142  {
143  UpdateStyle();
144  }
145 
146 #if UNITY_EDITOR
147  [UnityEditor.CustomEditor(typeof(CompoundButtonText))]
148  public class CustomEditor : MRTKEditor { }
149 #endif
150  }
151 }
Ensures a consistent profile field in compound buttons scripts which use a profile ...