Tanoda
InteractionSliderEditor.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 UnityEditor;
11using UnityEngine;
12
13namespace Leap.Unity.Interaction {
14
15 [CanEditMultipleObjects]
16 [CustomEditor(typeof(InteractionSlider), editorForChildClasses: true)]
18
19 protected override void OnEnable() {
20 base.OnEnable();
21
22 // specifyConditionalDrawing(() => noRectTransformParent, "horizontalSlideLimits", "verticalSlideLimits");
23
24 specifyCustomDecorator("horizontalSlideLimits", decorateHorizontalSlideLimits);
25 specifyCustomDecorator("verticalSlideLimits", decorateVerticalSlideLimits);
26 specifyCustomDecorator("horizontalSteps", decorateHorizontalSteps);
27
28 // Only display vertical properties if relevant
29 InteractionSlider[] sliders = targets.Query().Cast<InteractionSlider>().ToArray();
31 return sliders.Query().Any(slider => slider.sliderType == InteractionSlider.SliderType.Vertical
32 || slider.sliderType == InteractionSlider.SliderType.TwoDimensional);
33 },
34 "defaultVerticalValue",
35 "_verticalValueRange",
36 "verticalSlideLimits",
37 "verticalSteps",
38 "_verticalSlideEvent");
40 return sliders.Query().Any(slider => slider.sliderType == InteractionSlider.SliderType.Horizontal
41 || slider.sliderType == InteractionSlider.SliderType.TwoDimensional);
42 },
43 "defaultHorizontalValue",
44 "_horizontalValueRange",
45 "horizontalSlideLimits",
46 "horizontalSteps",
47 "_horizontalSlideEvent");
48 }
49
50 public override void OnInspectorGUI() {
51 bool noRectTransformParent = !(target.transform.parent != null && target.transform.parent.GetComponent<RectTransform>() != null && !(target as InteractionSlider).overrideRectLimits);
52 if (!noRectTransformParent) {
53 EditorGUILayout.HelpBox("This slider's limits are being controlled by the rect transform in its parent.", MessageType.Info);
54 }
55
56 if (!Application.isPlaying) {
57 (target as InteractionSlider).RecalculateSliderLimits();
58 }
59
60 base.OnInspectorGUI();
61 }
62
63 public override bool RequiresConstantRepaint() {
64 return true;
65 }
66
67 private void decorateHorizontalSlideLimits(SerializedProperty property) {
68 EditorGUI.BeginDisabledGroup(target.transform.parent != null && target.transform.parent.GetComponent<RectTransform>() != null && !(target as InteractionSlider).overrideRectLimits);
69 }
70
71 private void decorateVerticalSlideLimits(SerializedProperty property) {
72 EditorGUI.EndDisabledGroup();
73 EditorGUI.BeginDisabledGroup(target.transform.parent != null && target.transform.parent.GetComponent<RectTransform>() != null && !(target as InteractionSlider).overrideRectLimits);
74 }
75
76 private void decorateHorizontalSteps(SerializedProperty property) {
77 EditorGUI.EndDisabledGroup();
78 }
79
80 }
81}
void specifyConditionalDrawing(string conditionalName, params string[] dependantProperties)
Specify a list of properties that should only be displayed if the conditional property has a value of...
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 ...
A physics-enabled slider. Sliding is triggered by physically pushing the slider to its compressed pos...