AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ButtonTextProfile.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 System;
6 using UnityEngine;
7 
8 namespace HoloToolkit.Unity.Buttons
9 {
11  {
12  [Header("Text Mesh Settings")]
13  public TextAlignment Alignment = TextAlignment.Center;
14  public TextAnchor Anchor = TextAnchor.MiddleCenter;
15  public FontStyle Style = FontStyle.Normal;
16  public int Size = 72;
17  public Color Color = Color.white;
18  public Font Font;
19 
20  // Used to reposition the text mesh object in addition to setting its anchor
21  // This is useful when button text position will change dramatically based on the presence of other elements
22  // e.g., bottom anchor will move the text out of the way of an icon
23  [Header("Anchor Settings")]
25  public Vector3 AnchorLowerCenterOffset = Vector3.zero;
27  public Vector3 AnchorLowerLeftOffset = Vector3.zero;
29  public Vector3 AnchorLowerRightOffset = Vector3.zero;
31  public Vector3 AnchorMiddleCenterOffset = Vector3.zero;
33  public Vector3 AnchorMiddleLeftOffset = Vector3.zero;
35  public Vector3 AnchorMiddleRightOffset = Vector3.zero;
37  public Vector3 AnchorUpperCenterOffset = Vector3.zero;
39  public Vector3 AnchorUpperLeftOffset = Vector3.zero;
41  public Vector3 AnchorUpperRightOffset = Vector3.zero;
42 
48  public Vector3 GetOffset (TextAnchor anchor)
49  {
50  Vector3 offset;
51 
52  switch (anchor)
53  {
54  case TextAnchor.LowerCenter:
55  offset = AnchorLowerCenterOffset;
56  break;
57 
58  case TextAnchor.LowerLeft:
59  offset = AnchorLowerLeftOffset;
60  break;
61 
62  case TextAnchor.LowerRight:
63  offset = AnchorLowerRightOffset;
64  break;
65 
66  case TextAnchor.MiddleCenter:
67  offset = AnchorMiddleCenterOffset;
68  break;
69 
70  case TextAnchor.MiddleLeft:
71  offset = AnchorMiddleLeftOffset;
72  break;
73 
74  case TextAnchor.MiddleRight:
75  offset = AnchorMiddleRightOffset;
76  break;
77 
78  case TextAnchor.UpperCenter:
79  offset = AnchorUpperCenterOffset;
80  break;
81 
82  case TextAnchor.UpperLeft:
83  offset = AnchorUpperLeftOffset;
84  break;
85 
86  case TextAnchor.UpperRight:
87  offset = AnchorUpperRightOffset;
88  break;
89 
90  default:
91  throw new ArgumentOutOfRangeException("anchor", anchor, null);
92  }
93 
94  return offset;
95  }
96 
97 #if UNITY_EDITOR
98  [UnityEditor.CustomEditor(typeof(ButtonTextProfile))]
99  public class CustomEditor : ProfileInspector {
100  protected override void DrawCustomFooter() {
101  ButtonTextProfile textProfile = (ButtonTextProfile)target;
102  CompoundButtonText textButton = (CompoundButtonText)targetComponent;
103 
104  if (textButton == null || !textButton.OverrideOffset) {
105  switch (textProfile.Anchor) {
106  case TextAnchor.LowerCenter:
107  textProfile.AnchorLowerCenterOffset = UnityEditor.EditorGUILayout.Vector3Field("Anchor (" + textProfile.Anchor.ToString() + ")", textProfile.AnchorLowerCenterOffset);
108  break;
109 
110  case TextAnchor.LowerLeft:
111  textProfile.AnchorLowerLeftOffset = UnityEditor.EditorGUILayout.Vector3Field("Anchor (" + textProfile.Anchor.ToString() + ")", textProfile.AnchorLowerLeftOffset);
112  break;
113 
114  case TextAnchor.LowerRight:
115  textProfile.AnchorLowerRightOffset = UnityEditor.EditorGUILayout.Vector3Field("Anchor (" + textProfile.Anchor.ToString() + ")", textProfile.AnchorLowerRightOffset);
116  break;
117 
118  case TextAnchor.MiddleCenter:
119  textProfile.AnchorMiddleCenterOffset = UnityEditor.EditorGUILayout.Vector3Field("Anchor (" + textProfile.Anchor.ToString() + ")", textProfile.AnchorMiddleCenterOffset);
120  break;
121 
122  case TextAnchor.MiddleLeft:
123  textProfile.AnchorMiddleLeftOffset = UnityEditor.EditorGUILayout.Vector3Field("Anchor (" + textProfile.Anchor.ToString() + ")", textProfile.AnchorMiddleLeftOffset);
124  break;
125 
126  case TextAnchor.MiddleRight:
127  textProfile.AnchorMiddleRightOffset = UnityEditor.EditorGUILayout.Vector3Field("Anchor (" + textProfile.Anchor.ToString() + ")", textProfile.AnchorMiddleRightOffset);
128  break;
129 
130  case TextAnchor.UpperCenter:
131  textProfile.AnchorUpperCenterOffset = UnityEditor.EditorGUILayout.Vector3Field("Anchor (" + textProfile.Anchor.ToString() + ")", textProfile.AnchorUpperCenterOffset);
132  break;
133 
134  case TextAnchor.UpperLeft:
135  textProfile.AnchorUpperLeftOffset = UnityEditor.EditorGUILayout.Vector3Field("Anchor (" + textProfile.Anchor.ToString() + ")", textProfile.AnchorUpperLeftOffset);
136  break;
137 
138  case TextAnchor.UpperRight:
139  textProfile.AnchorUpperRightOffset = UnityEditor.EditorGUILayout.Vector3Field("Anchor (" + textProfile.Anchor.ToString() + ")", textProfile.AnchorUpperRightOffset);
140  break;
141  }
142  }
143  }
144  }
145 #endif
146  }
147 }
The base class for all button profiles Inherit from this to create new button profile types ...
Vector3 GetOffset(TextAnchor anchor)
Convenience function for getting the offset from an anchor setting