AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
CompoundButton.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 {
14  public class CompoundButton : Button
15  {
16  [Tooltip("The button's 'main' collider - not required, but useful for judging scale and enabling / disabling")]
17  [DropDownComponent]
18  public Collider MainCollider;
19 
20  [Tooltip("The button's 'main' renderer - not required, but useful for judging material properties")]
21  [DropDownComponent]
22  public MeshRenderer MainRenderer;
23 
24 #if UNITY_EDITOR
25  [UnityEditor.CustomEditor(typeof(CompoundButton))]
26  public class CustomEditor : MRTKEditor
27  {
32  protected override void DrawCustomFooter() {
33 
34  CompoundButton cb = (CompoundButton)target;
35 
36  // Don't perform this check at runtime
37  if (!Application.isPlaying) {
38  // First, check our colliders
39  // Get the components we need for the button to be visible
40  Rigidbody parentRigidBody = cb.GetComponent<Rigidbody>();
41  Collider parentCollider = cb.GetComponent<Collider>();
42  // Get all child colliders that AREN'T the parent collider
43  HashSet<Collider> childColliders = new HashSet<Collider>(cb.GetComponentsInChildren<Collider>());
44  childColliders.Remove(parentCollider);
45 
46  bool foundError = false;
47  UnityEditor.EditorGUILayout.BeginVertical(UnityEditor.EditorStyles.helpBox);
48  if (parentCollider == null) {
49  if (childColliders.Count == 0) {
50  foundError = true;
51  DrawError("Button must have at least 1 collider to be visible, preferably on the root transform.");
52  if (GUILayout.Button("Fix now")) {
53  cb.gameObject.AddComponent<BoxCollider>();
54  }
55  } else if (parentRigidBody == null) {
56  foundError = true;
57  DrawError("Button requires a Rigidbody if colliders are only present on child transforms.");
58  if (GUILayout.Button("Fix now")) {
59  Rigidbody rb = cb.gameObject.AddComponent<Rigidbody>();
60  rb.isKinematic = true;
61  }
62  } else if (!parentRigidBody.isKinematic) {
63  foundError = true;
64  GUI.color = warningColor;
65  DrawWarning("Warning: Button rigid body is not kinematic - this is not recommended.");
66  if (GUILayout.Button("Fix now")) {
67  parentRigidBody.isKinematic = true;
68  }
69  }
70  }
71 
72  if (!foundError) {
73  GUI.color = successColor;
74  UnityEditor.EditorGUILayout.LabelField("Button is good to go!", UnityEditor.EditorStyles.wordWrappedLabel);
75  }
76  UnityEditor.EditorGUILayout.EndVertical();
77  }
78  }
79  }
80 #endif
81  }
82 }
Concrete version of Button class used with other CompoundButton scripts (e.g., CompoundButtonMesh) Al...