10using System.Collections;
11using System.Collections.Generic;
17 [CanEditMultipleObjects]
18 [CustomEditor(typeof(InteractionHand), editorForChildClasses:
true)]
21 private Texture _handTex;
22 private Rect _handTexRect;
27 _handTex = EditorResources.Load<Texture2D>(
"HandTex");
35 private void drawProvider(SerializedProperty p) {
36 EditorGUILayout.PropertyField(serializedObject.FindProperty(
"_leapProvider"));
39 private void drawPrimaryHoverFingertipsEditor(SerializedProperty property) {
41 EditorGUILayout.BeginHorizontal();
43 EditorGUILayout.PrefixLabel(
44 new GUIContent(
"Primary Hover Fingertips",
45 "Check which fingertips should be used "
46 +
"as primary hover points for this interaction controller. Fewer "
47 +
"points is cheaper. Proximity to one of these points determines "
48 +
"which interaction object is chosen as the primary hover for this "
49 +
"interaction controller at any given time. Generally speaking, "
50 +
"choose the fingertips you'd like users to be able to use to "
51 +
"choose and push a button."));
53 Rect controlRect = EditorGUILayout.GetControlRect(GUILayout.Height(102));
54 drawHandEditor(controlRect);
56 EditorGUILayout.EndHorizontal();
59 private void drawHandEditor(Rect controlRect) {
61 var isTargetPrefab = Utils.IsObjectPartOfPrefabAsset(
target.gameObject);
64 Rect imageContainerRect = controlRect;
65 EditorGUI.DrawRect(imageContainerRect,
new Color(0.2F, 0.2F, 0.2F));
66 imageContainerRect.x += 1; imageContainerRect.y += 1; imageContainerRect.width -= 2; imageContainerRect.height -= 2;
67 EditorGUI.DrawRect(imageContainerRect,
new Color(0.6F, 0.6F, 0.6F));
68 imageContainerRect.x += 1; imageContainerRect.y += 1; imageContainerRect.width -= 2; imageContainerRect.height -= 2;
69 EditorGUI.DrawRect(imageContainerRect,
new Color(0.2F, 0.2F, 0.2F));
72 _handTexRect =
new Rect(0F, 0F, (controlRect.height - 2) * (_handTex.width / (
float)_handTex.height), controlRect.height - 2);
73 _handTexRect.center += imageContainerRect.center - _handTexRect.center;
74 EditorGUI.DrawTextureTransparent(_handTexRect, _handTex);
77 EditorGUI.BeginDisabledGroup(isTargetPrefab);
79 makeFingertipToggle(0,
new Vector2(-0.390F, 0.110F));
80 makeFingertipToggle(1,
new Vector2(-0.080F, -0.380F));
81 makeFingertipToggle(2,
new Vector2(0.090F, -0.420F));
82 makeFingertipToggle(3,
new Vector2(0.245F, -0.380F));
83 makeFingertipToggle(4,
new Vector2(0.410F, -0.210F));
86 private void makeFingertipToggle(
int fingerIndex, Vector2 offCenterPosImgSpace) {
87 InteractionHand targetHand =
target.intHand;
88 InteractionHand[] targetHands =
targets.Query().Cast<InteractionHand>().ToArray();
90 if (EditorGUI.Toggle(makeToggleRect(_handTexRect.center
91 +
new Vector2(offCenterPosImgSpace.x * _handTexRect.width,
92 offCenterPosImgSpace.y * _handTexRect.height)),
94 targetHand.enabledPrimaryHoverFingertips[fingerIndex])) {
95 foreach (var singleTarget
in targetHands) {
96 serializedObject.FindProperty(
"enabledPrimaryHoverFingertips").GetArrayElementAtIndex(fingerIndex).boolValue =
true;
100 foreach (var singleTarget
in targetHands) {
101 serializedObject.FindProperty(
"enabledPrimaryHoverFingertips").GetArrayElementAtIndex(fingerIndex).boolValue =
false;
106 private const float TOGGLE_SIZE = 15.0F;
107 private Rect makeToggleRect(Vector2 centerPos) {
108 return new Rect(centerPos.x - TOGGLE_SIZE / 2F, centerPos.y - TOGGLE_SIZE / 2F, TOGGLE_SIZE, TOGGLE_SIZE);
void hideField(string propertyName)
void specifyCustomDrawer(string propertyName, Action< SerializedProperty > propertyDrawer)
Specify a callback to be used to draw a specific named property. Should be called in OnEnable.
void specifyCustomDecorator(string propertyName, Action< SerializedProperty > decoratorDrawer)
Specify a callback to be used to draw a decorator for a specific named property. Should be called in ...