23 #region Inspector & Properties
31 [Header(
"Slider Settings")]
36 [Tooltip(
"Manually specify slider limits even if the slider's parent has a RectTransform.")]
37 [
DisableIf(
"_parentHasRectTransform", isEqualTo:
false)]
39 [SerializeField, HideInInspector]
40 #pragma warning disable 0414
41 private bool _parentHasRectTransform =
false;
42 #pragma warning restore 0414
44 [Header(
"Horizontal Axis")]
47 [Tooltip(
"The minimum and maximum values that the slider reports on the horizontal axis.")]
48 [FormerlySerializedAs(
"horizontalValueRange")]
50 private Vector2 _horizontalValueRange =
new Vector2(0f, 1f);
53 return _horizontalValueRange.x;
56 if (value != _horizontalValueRange.x) {
57 _horizontalValueRange.x = value;
65 return _horizontalValueRange.y;
68 if (value != _horizontalValueRange.y) {
69 _horizontalValueRange.y = value;
75 [Tooltip(
"The minimum and maximum horizontal extents that the slider can slide to in world space.")]
79 [Tooltip(
"The number of discrete quantized notches **beyond the first** that this "
80 +
"slider can occupy on the horizontal axis. A value of zero indicates a "
81 +
"continuous (non-quantized) slider for this axis.")]
89 [FormerlySerializedAs(
"horizontalSlideEvent")]
92 [Header(
"Vertical Axis")]
95 [Tooltip(
"The minimum and maximum values that the slider reports on the horizontal axis.")]
96 [FormerlySerializedAs(
"verticalValueRange")]
98 private Vector2 _verticalValueRange =
new Vector2(0f, 1f);
101 return _verticalValueRange.x;
104 if (value != _verticalValueRange.x) {
105 _verticalValueRange.x = value;
113 return _verticalValueRange.y;
116 if (value != _verticalValueRange.y) {
117 _verticalValueRange.y = value;
124 [Tooltip(
"The minimum and maximum vertical extents that the slider can slide to in world space.")]
127 [Tooltip(
"The number of discrete quantized notches **beyond the first** that this "
128 +
"slider can occupy on the vertical axis. A value of zero indicates a "
129 +
"continuous (non-quantized) slider for this axis.")]
135 [FormerlySerializedAs(
"verticalSlideEvent")]
147 Debug.LogWarning(
"An object is attempting to access this slider's value before it has been initialized! Initializing now; this could yield unexpected behaviour...",
this);
164 Debug.LogWarning(
"An object is attempting to access this slider's value before it has been initialized! Initializing now; this could yield unpected behaviour...",
this);
195 private void calculateSliderValues() {
213 var newValue = Mathf.Clamp01(value);
226 var newValue = Mathf.Clamp01(value);
242 float range = _horizontalValueRange.y - _horizontalValueRange.x;
243 if (range == 0F)
return 0;
254 get {
return _wasSlid && _sawWasSlid; }
259 #region Internal State
265 private bool _started =
false;
267 private bool _sawWasSlid =
false;
268 private bool _wasSlid =
false;
277 if (this.
transform.parent !=
null &&
this.transform.parent.GetComponent<RectTransform>() !=
null) {
278 _parentHasRectTransform =
true;
281 _parentHasRectTransform =
false;
298 if (_started)
return;
302 calculateSliderLimits();
333 if (!Application.isPlaying) {
return; }
336 calculateSliderValues();
343 if (_wasSlid && !_sawWasSlid) {
346 else if (_sawWasSlid) {
357 calculateSliderLimits();
362 #region Internal Methods
364 private void calculateSliderLimits() {
371 if (
parent.rect.width < 0f ||
parent.rect.height < 0f) {
372 Debug.LogError(
"Parent Rectangle dimensions negative; can't set slider boundaries!",
parent.gameObject);
375 var
self =
transform.GetComponent<RectTransform>();
408 Vector3 unSnappedPosition =
433 base.OnDrawGizmosSelected();
442 Gizmos.color =
Color.blue;
443 Gizmos.DrawWireCube(originPosition +
451 var
self = GetComponent<RectTransform>();
456 var parentRectHorizontal =
new Vector2(
parent.rect.xMin - originPosition.x,
parent.rect.xMax - originPosition.x);
457 var parentRectVertical =
new Vector2(
parent.rect.yMin - originPosition.y,
parent.rect.yMax - originPosition.y);
459 Gizmos.DrawWireCube(originPosition +
460 new Vector3((parentRectHorizontal.x + parentRectHorizontal.y) * 0.5f,
461 (parentRectVertical.x + parentRectVertical.y) * 0.5f,
465 new Vector3(parentRectHorizontal.y - parentRectHorizontal.x, parentRectVertical.y - parentRectVertical.x, (
minMaxHeight.y -
minMaxHeight.x)));
468 Gizmos.color =
Color.cyan;
469 Gizmos.DrawWireCube(originPosition,
470 self.rect.width * Vector3.right
471 +
self.rect.height * Vector3.up);
Action OnContactStay
Called every frame during which one or more interaction controllers is colliding with this object.
Rigidbody rigidbody
The Rigidbody associated with this interaction object.
bool isGrasped
Gets whether this object is grasped by any interaction controller.
A physics-enabled slider. Sliding is triggered by physically pushing the slider to its compressed pos...
float HorizontalSliderPercent
bool wasSlid
Gets whether the slider was slide in the latest Update().
float VerticalSliderPercent
summary> This slider's horizontal slider value, mapped between the values in the HorizontalValueRange...
int verticalSteps
summary> Triggered while this slider is depressed.
override void OnDrawGizmosSelected()
Action< float > HorizontalSlideEvent
float defaultVerticalValue
Action< float > VerticalSlideEvent
float _horizontalSliderPercent
override void OnValidate()
Vector2 verticalSlideLimits
override Vector3 constrainDepressedLocalPosition(Vector3 desiredOffset)
Clamps the input local-space position to the bounds allowed by this UI element, without clamping alon...
float normalizedHorizontalValue
Vector2 horizontalSlideLimits
override void OnDisable()
float defaultHorizontalValue
float HorizontalSliderValue
summary> This slider's current vertical slider value, mapped between the values in the VerticalValueR...
bool dispatchSlideValueOnStart
int horizontalStepValue
Returns the number of horizontal steps past the minimum value of the slider, for sliders with a non-z...
float normalizedVerticalValue
float VerticalSliderValue
void RecalculateSliderLimits()
float _verticalSliderPercent