Tanoda
InteractionVRControllerEditor.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;
11using System.Collections;
12using System.Collections.Generic;
13using UnityEditor;
14using UnityEngine;
15
16namespace Leap.Unity.Interaction {
17
18 [CanEditMultipleObjects]
19 [CustomEditor(typeof(InteractionXRController), true)]
21
22 private List<InteractionXRController> _vrControllers;
23
24 bool _pluralPossibleControllers = false;
25
26 protected override void OnEnable() {
27 base.OnEnable();
28
29 //_vrController = (target as InteractionVRController);
30 _vrControllers = targets.Query()
31 .Where(c => c is InteractionXRController)
33 .ToList();
34 _pluralPossibleControllers = _vrControllers.Count > 1;
35
36 specifyCustomPostDecorator("graspButtonAxis", drawGraspButtonAxisDecorator);
37 }
38
39 private void drawGraspButtonAxisDecorator(SerializedProperty property) {
40 // Whether the axis is overriden.
41 int numGraspAxisOverrides = _vrControllers.Query()
42 .Where(c => c.graspAxisOverride != null)
43 .Count();
44 bool anyGraspAxisOverrides = numGraspAxisOverrides > 0;
45
46 if (anyGraspAxisOverrides) {
47 string graspAxisOverrideMessage;
48 if (_pluralPossibleControllers) {
49 graspAxisOverrideMessage = "One or more currently selected interaction VR "
50 + "controllers has their grasping axis overridden, "
51 + "so their graspButtonAxis settings will be ignored.";
52 }
53 else {
54 graspAxisOverrideMessage = "This interaction VR controller has its grasping "
55 + "axis overridden, so the graspButtonAxis setting "
56 + "will be ignored.";
57 }
58 EditorGUILayout.HelpBox(graspAxisOverrideMessage, MessageType.Info);
59 }
60
61 // Whether the axis is valid.
62 bool anyInvalidGraspAxes = _vrControllers.Query()
63 .Select(c => isGraspAxisConfigured(c))
64 .Where(b => b == false)
65 .Any();
66
67 if (anyInvalidGraspAxes) {
68 string graspAxisInvalidMessage;
69 if (_pluralPossibleControllers) {
70 graspAxisInvalidMessage = "One or more currently selected interaction VR "
71 + "controllers is configured with a grasping axis name "
72 + "that is not set up in Unity's Input settings.";
73 }
74 else {
75 graspAxisInvalidMessage = "This interaction VR controller is configured with a "
76 + "grasping axis name that is not set up in Unity's "
77 + "Input settings.";
78 }
79 graspAxisInvalidMessage += " Check your input settings via Edit -> Project "
80 + "Settings -> Input. Otherwise, this interaction "
81 + "controller will be unable to grasp objects.";
82
83 EditorGUILayout.HelpBox(graspAxisInvalidMessage, MessageType.Warning);
84 }
85 }
86
87 private bool isGraspAxisConfigured(InteractionXRController controller) {
88 try {
89 Input.GetAxis(controller.graspButtonAxis);
90 return true;
91 }
92 catch (ArgumentException) {
93 return false;
94 }
95 }
96
97 }
98
99}
void specifyCustomPostDecorator(string propertyName, Action< SerializedProperty > decoratorDrawer)
Specify a callback to be used to draw a decorator AFTER a specific named property.