5 using System.Collections.Generic;
16 [Tooltip(
"The button's 'main' collider - not required, but useful for judging scale and enabling / disabling")]
20 [Tooltip(
"The button's 'main' renderer - not required, but useful for judging material properties")]
26 public class CustomEditor : MRTKEditor
32 protected override void DrawCustomFooter() {
37 if (!Application.isPlaying) {
40 Rigidbody parentRigidBody = cb.GetComponent<Rigidbody>();
41 Collider parentCollider = cb.GetComponent<Collider>();
43 HashSet<Collider> childColliders =
new HashSet<Collider>(cb.GetComponentsInChildren<Collider>());
44 childColliders.Remove(parentCollider);
46 bool foundError =
false;
48 if (parentCollider == null) {
49 if (childColliders.Count == 0) {
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>();
55 }
else if (parentRigidBody == null) {
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;
62 }
else if (!parentRigidBody.isKinematic) {
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;
73 GUI.color = successColor;
74 UnityEditor.EditorGUILayout.LabelField(
"Button is good to go!",
UnityEditor.EditorStyles.wordWrappedLabel);