AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ButtonMeshProfile.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.Collections.Generic;
6 using UnityEngine;
7 
8 namespace HoloToolkit.Unity.Buttons
9 {
11  {
12  [Tooltip("Name of the shader color property that will be modified (default '_Color')")]
13  public string ColorPropertyName = "_Color";
14 
15  [Tooltip("Name of the shader float property that will be modified.")]
16  public string ValuePropertyName = string.Empty;
17 
18  [Tooltip("If true, button properties are lerped instead of instantaneous.")]
19  public bool SmoothStateChanges = false;
20 
21  [Tooltip("Whether to hold pressed events for a short period.")]
22  public bool StickyPressedEvents = false;
23 
24  [Tooltip("How long to hold sticky pressed events.")]
25  public float StickyPressedTime = 0.15f;
26 
27  [Range(0.01f, 1f)]
28  [Tooltip("How quickly to animate scale, offset, color and value properties")]
29  public float AnimationSpeed = 1f;
30 
35 
36 #if UNITY_EDITOR
37  [UnityEditor.CustomEditor(typeof(ButtonMeshProfile))]
38  public class CustomEditor : ProfileInspector
39  {
43  protected override void DrawCustomFooter() {
44 
45  ButtonMeshProfile meshProfile = (ButtonMeshProfile)target;
46  CompoundButtonMesh meshButton = null;
47  if (targetComponent is CompoundButtonMesh)
48  meshButton = targetComponent as CompoundButtonMesh;
49 
50  // Validate our button states - ensure there's one for each button state enum value
51  ButtonStateEnum[] buttonStates = (ButtonStateEnum[])System.Enum.GetValues(typeof(ButtonStateEnum));
52  List<CompoundButtonMesh.MeshButtonDatum> missingStates = new List<CompoundButtonMesh.MeshButtonDatum>();
53  foreach (ButtonStateEnum buttonState in buttonStates) {
54  bool foundState = false;
55  foreach (CompoundButtonMesh.MeshButtonDatum datum in meshProfile.ButtonStates) {
56  if (datum.ActiveState == buttonState) {
57  foundState = true;
58  break;
59  }
60  }
61 
62  if (!foundState) {
64  missingState.Name = buttonState.ToString();
65  missingStates.Add(missingState);
66  }
67  }
68 
69  // If any were missing, add them to our button states
70  // They may be out of order but we don't care
71  if (missingStates.Count > 0) {
72  missingStates.AddRange(meshProfile.ButtonStates);
73  meshProfile.ButtonStates = missingStates.ToArray();
74  }
75 
76  foreach (CompoundButtonMesh.MeshButtonDatum datum in meshProfile.ButtonStates) {
77  UnityEditor.EditorGUILayout.Space();
78  UnityEditor.EditorGUILayout.LabelField(datum.ActiveState.ToString(), UnityEditor.EditorStyles.boldLabel);
79  UnityEditor.EditorGUI.indentLevel++;
80  if (meshButton != null && meshButton.TargetTransform == null) {
81  UnityEditor.EditorGUILayout.LabelField("(No target transform specified for scale / offset)", UnityEditor.EditorStyles.miniLabel);
82  } else {
83  datum.Offset = UnityEditor.EditorGUILayout.Vector3Field("Offset", datum.Offset);
84  datum.Scale = UnityEditor.EditorGUILayout.Vector3Field("Scale", datum.Scale);
85 
86  if (datum.Scale == Vector3.zero) {
87  GUI.color = warningColor;
88  if (GUILayout.Button("Warning: Button state scale is zero. Click here to fix.", UnityEditor.EditorStyles.miniButton)) {
89  datum.Scale = Vector3.one;
90  }
91  }
92  }
93 
94  GUI.color = defaultColor;
95  if (meshButton != null && meshButton.Renderer == null) {
96  UnityEditor.EditorGUILayout.LabelField("(No target renderer specified for color / value material properties)", UnityEditor.EditorStyles.miniLabel);
97  } else {
98  if (!string.IsNullOrEmpty(meshProfile.ColorPropertyName)) {
99  datum.StateColor = UnityEditor.EditorGUILayout.ColorField(meshProfile.ColorPropertyName + " value", datum.StateColor);
100  }
101  if (!string.IsNullOrEmpty(meshProfile.ValuePropertyName)) {
102  datum.StateValue = UnityEditor.EditorGUILayout.FloatField(meshProfile.ValuePropertyName + " value", datum.StateValue);
103  }
104 
105  }
106  UnityEditor.EditorGUI.indentLevel--;
107  }
108  }
109  }
110 #endif
111  }
112 }
ButtonStateEnum
State enum for buttons.
Mesh button is a mesh renderer interactable with state data for button state
The base class for all button profiles Inherit from this to create new button profile types ...