Tanoda
InteractionControllerEditor.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using Leap.Unity.Query;
10using System.Collections;
11using System.Collections.Generic;
12using UnityEditor;
13using UnityEngine;
14
15namespace Leap.Unity.Interaction {
16
17 [CanEditMultipleObjects]
18 [CustomEditor(typeof(InteractionController), true)]
19 public class InteractionControllerEditor : CustomEditorBase<InteractionController> {
20
21 public override void OnInspectorGUI() {
22 checkParentedToManager();
23 checkWithinHandModelManager();
24 checkPrimaryHoverPoints();
25
26 base.OnInspectorGUI();
27 }
28
29 private void checkPrimaryHoverPoints() {
30 bool anyPrimaryHoverPoints = false;
31 bool anyWithNoPrimaryHoverPoints = false;
32 foreach (var singleTarget in targets) {
33 anyPrimaryHoverPoints = false;
34 foreach (var primaryHoverPoint in singleTarget.primaryHoverPoints) {
35 if (primaryHoverPoint != null) {
36 anyPrimaryHoverPoints = true;
37 break;
38 }
39 }
40
41 if (singleTarget.intHand != null) {
42 for (int i = 0; i < singleTarget.intHand.enabledPrimaryHoverFingertips.Length; i++) {
43 if (singleTarget.intHand.enabledPrimaryHoverFingertips[i]) {
44 anyPrimaryHoverPoints = true;
45 break;
46 }
47 }
48 }
49
50 if (!anyPrimaryHoverPoints) {
51 anyWithNoPrimaryHoverPoints = true;
52 break;
53 }
54 }
55
56 if (anyWithNoPrimaryHoverPoints) {
57 string message = "No primary hover points found for this interaction controller. "
58 + "This controller will never trigger primary hover for an object. "
59 + "UI elements such as InteractionButton and InteractionSlider "
60 + "will not be able to interact with this interaction controller.";
61 EditorGUILayout.HelpBox(message, MessageType.Warning);
62 }
63 }
64
65 private void checkParentedToManager() {
66 bool plural = targets.Length > 1;
67 bool anyNotParentedToInteractionManager;
68
69 anyNotParentedToInteractionManager = targets.Query()
70 .Any(c => c.GetComponentInParent<InteractionManager>() == null);
71
72 if (anyNotParentedToInteractionManager) {
73 string message = "";
74 if (plural) {
75 message += "One of more currently selected controllers ";
76 }
77 else {
78 message += "The currently selected controller ";
79 }
80
81 message += "is not the child of an Interaction Manager. Interaction Controllers "
82 + "must be childed to an Interaction Manager in order to function.";
83
84 EditorGUILayout.HelpBox(message, MessageType.Warning);
85 }
86 }
87
88 private void checkWithinHandModelManager() {
89 bool plural = targets.Length > 1;
90 bool anyWithinHandPool;
91
92 HandModelManager handModelManager = FindObjectOfType<HandModelManager>();
93 if (handModelManager == null) return;
94
95 anyWithinHandPool = targets.Query()
96 .Any(c => c.transform.parent == handModelManager.transform);
97
98 if (anyWithinHandPool) {
99 string message = "";
100 if (plural) {
101 message += "One or more of the currently selected controllers ";
102 }
103 else {
104 message += "The currently selected controller ";
105 }
106
107 message += "is inside a HandModelManager. Interaction controllers, such "
108 + "as InteractionHands, are not HandModels and are not spawned by the "
109 + "HandModelManager. InteractionHands and all Interaction controllers "
110 + "should be childed to the Interaction Manager.";
111
112 EditorGUILayout.HelpBox(message, MessageType.Error);
113 }
114 }
115
116 }
117
118}