Files
Dec2017-Script-Dump/UnityEngine/Experimental/UIElements/Slider.cs
T
2026-06-04 11:42:34 +02:00

289 lines
9.9 KiB
C#

using System;
using System.Diagnostics;
using UnityEngine.Experimental.UIElements.StyleSheets;
namespace UnityEngine.Experimental.UIElements
{
// Token: 0x02000347 RID: 839
public class Slider : VisualContainer
{
// Token: 0x060033D0 RID: 13264 RVA: 0x00051D80 File Offset: 0x0004FF80
public Slider(float start, float end, Action<float> valueChanged, Slider.Direction direction = Slider.Direction.Horizontal, float pageSize = 10f)
{
this.valueChanged = valueChanged;
this.direction = direction;
this.pageSize = pageSize;
this.lowValue = start;
this.highValue = end;
base.AddChild(new VisualElement
{
name = "TrackElement"
});
this.m_Value = this.lowValue;
this.dragElement = new VisualElement
{
name = "DragElement"
};
base.AddChild(this.dragElement);
this.clampedDragger = new ClampedDragger(this, new Action(this.SetSliderValueFromClick), new Action(this.SetSliderValueFromDrag));
base.AddManipulator(this.clampedDragger);
}
// Token: 0x17000BCB RID: 3019
// (get) Token: 0x060033D1 RID: 13265 RVA: 0x00051E34 File Offset: 0x00050034
// (set) Token: 0x060033D2 RID: 13266 RVA: 0x00051E50 File Offset: 0x00050050
public VisualElement dragElement { get; private set; }
// Token: 0x17000BCC RID: 3020
// (get) Token: 0x060033D3 RID: 13267 RVA: 0x00051E5C File Offset: 0x0005005C
// (set) Token: 0x060033D4 RID: 13268 RVA: 0x00051E78 File Offset: 0x00050078
public float lowValue { get; set; }
// Token: 0x17000BCD RID: 3021
// (get) Token: 0x060033D5 RID: 13269 RVA: 0x00051E84 File Offset: 0x00050084
// (set) Token: 0x060033D6 RID: 13270 RVA: 0x00051EA0 File Offset: 0x000500A0
public float highValue { get; set; }
// Token: 0x17000BCE RID: 3022
// (get) Token: 0x060033D7 RID: 13271 RVA: 0x00051EAC File Offset: 0x000500AC
public float range
{
get
{
return this.highValue - this.lowValue;
}
}
// Token: 0x17000BCF RID: 3023
// (get) Token: 0x060033D8 RID: 13272 RVA: 0x00051ED0 File Offset: 0x000500D0
// (set) Token: 0x060033D9 RID: 13273 RVA: 0x00051EEC File Offset: 0x000500EC
public float pageSize { get; set; }
// Token: 0x14000028 RID: 40
// (add) Token: 0x060033DA RID: 13274 RVA: 0x00051EF8 File Offset: 0x000500F8
// (remove) Token: 0x060033DB RID: 13275 RVA: 0x00051F30 File Offset: 0x00050130
[field: DebuggerBrowsable(DebuggerBrowsableState.Never)]
public event Action<float> valueChanged;
// Token: 0x17000BD0 RID: 3024
// (get) Token: 0x060033DC RID: 13276 RVA: 0x00051F68 File Offset: 0x00050168
// (set) Token: 0x060033DD RID: 13277 RVA: 0x00051F84 File Offset: 0x00050184
internal ClampedDragger clampedDragger { get; private set; }
// Token: 0x17000BD1 RID: 3025
// (get) Token: 0x060033DE RID: 13278 RVA: 0x00051F90 File Offset: 0x00050190
// (set) Token: 0x060033DF RID: 13279 RVA: 0x00051FAC File Offset: 0x000501AC
public float value
{
get
{
return this.m_Value;
}
set
{
float num = Mathf.Clamp(value, this.lowValue, this.highValue);
if (!Mathf.Approximately(this.m_Value, num))
{
this.m_Value = num;
this.UpdateDragElementPosition();
if (this.valueChanged != null)
{
this.valueChanged(this.m_Value);
}
base.Dirty(ChangeType.Repaint);
}
}
}
// Token: 0x17000BD2 RID: 3026
// (get) Token: 0x060033E0 RID: 13280 RVA: 0x00052014 File Offset: 0x00050214
// (set) Token: 0x060033E1 RID: 13281 RVA: 0x00052030 File Offset: 0x00050230
public Slider.Direction direction
{
get
{
return this.m_Direction;
}
set
{
this.m_Direction = value;
if (this.m_Direction == Slider.Direction.Horizontal)
{
base.RemoveFromClassList("vertical");
base.AddToClassList("horizontal");
}
else
{
base.RemoveFromClassList("horizontal");
base.AddToClassList("vertical");
}
}
}
// Token: 0x060033E2 RID: 13282 RVA: 0x00052088 File Offset: 0x00050288
private void SetSliderValueFromDrag()
{
if (this.clampedDragger.dragDirection == ClampedDragger.DragDirection.Free)
{
Vector2 delta = this.clampedDragger.delta;
if (this.direction == Slider.Direction.Horizontal)
{
this.ComputeValueAndDirectionFromDrag(base.position.width, this.dragElement.position.width, this.m_DragElementStartPos.x + delta.x);
}
else
{
this.ComputeValueAndDirectionFromDrag(base.position.height, this.dragElement.position.height, this.m_DragElementStartPos.y + delta.y);
}
}
}
// Token: 0x060033E3 RID: 13283 RVA: 0x00052140 File Offset: 0x00050340
private void ComputeValueAndDirectionFromDrag(float sliderLength, float dragElementLength, float dragElementPos)
{
float num = sliderLength - dragElementLength;
if (Mathf.Abs(num) >= Mathf.Epsilon)
{
this.value = Mathf.Max(0f, Mathf.Min(dragElementPos, num)) / num * this.range + this.lowValue;
}
}
// Token: 0x060033E4 RID: 13284 RVA: 0x00052190 File Offset: 0x00050390
private void SetSliderValueFromClick()
{
if (this.clampedDragger.dragDirection != ClampedDragger.DragDirection.Free)
{
if (this.clampedDragger.dragDirection == ClampedDragger.DragDirection.None)
{
if (this.pageSize == 0f)
{
float num = ((this.direction != Slider.Direction.Horizontal) ? this.dragElement.position.x : (this.clampedDragger.startMousePosition.x - this.dragElement.position.width / 2f));
float num2 = ((this.direction != Slider.Direction.Horizontal) ? (this.clampedDragger.startMousePosition.y - this.dragElement.position.height / 2f) : this.dragElement.position.y);
Rect rect = new Rect(num, num2, this.dragElement.position.width, this.dragElement.position.height);
this.dragElement.position = rect;
this.m_DragElementStartPos = rect;
this.clampedDragger.dragDirection = ClampedDragger.DragDirection.Free;
if (this.direction == Slider.Direction.Horizontal)
{
this.ComputeValueAndDirectionFromDrag(base.position.width, this.dragElement.position.width, this.m_DragElementStartPos.x);
}
else
{
this.ComputeValueAndDirectionFromDrag(base.position.height, this.dragElement.position.height, this.m_DragElementStartPos.y);
}
return;
}
this.m_DragElementStartPos = this.dragElement.position;
}
if (this.direction == Slider.Direction.Horizontal)
{
this.ComputeValueAndDirectionFromClick(base.position.width, this.dragElement.position.width, this.dragElement.position.x, this.clampedDragger.lastMousePosition.x);
}
else
{
this.ComputeValueAndDirectionFromClick(base.position.height, this.dragElement.position.height, this.dragElement.position.y, this.clampedDragger.lastMousePosition.y);
}
}
}
// Token: 0x060033E5 RID: 13285 RVA: 0x00052410 File Offset: 0x00050610
private void ComputeValueAndDirectionFromClick(float sliderLength, float dragElementLength, float dragElementPos, float dragElementLastPos)
{
float num = sliderLength - dragElementLength;
if (Mathf.Abs(num) >= Mathf.Epsilon)
{
if (dragElementLastPos < dragElementPos && this.clampedDragger.dragDirection != ClampedDragger.DragDirection.LowToHigh)
{
this.clampedDragger.dragDirection = ClampedDragger.DragDirection.HighToLow;
this.value = Mathf.Max(0f, Mathf.Min(dragElementPos - this.pageSize, num)) / num * this.range + this.lowValue;
}
else if (dragElementLastPos > dragElementPos + dragElementLength && this.clampedDragger.dragDirection != ClampedDragger.DragDirection.HighToLow)
{
this.clampedDragger.dragDirection = ClampedDragger.DragDirection.LowToHigh;
this.value = Mathf.Max(0f, Mathf.Min(dragElementPos + this.pageSize, num)) / num * this.range + this.lowValue;
}
}
}
// Token: 0x060033E6 RID: 13286 RVA: 0x000524E8 File Offset: 0x000506E8
public void AdjustDragElement(float factor)
{
Rect position;
if (factor >= 1f)
{
if (this.direction == Slider.Direction.Horizontal)
{
position = new Rect(this.dragElement.position.x, this.dragElement.position.y, 0f, this.dragElement.height);
}
else
{
position = new Rect(this.dragElement.position.x, this.dragElement.position.y, this.dragElement.width, 0f);
}
}
else
{
VisualElementStyles styles = this.dragElement.styles;
position = this.dragElement.position;
if (this.direction == Slider.Direction.Horizontal)
{
float specifiedValueOrDefault = styles.minWidth.GetSpecifiedValueOrDefault(0f);
position.width = Mathf.Max(base.position.width * factor, specifiedValueOrDefault);
}
else
{
float specifiedValueOrDefault2 = styles.minHeight.GetSpecifiedValueOrDefault(0f);
position.height = Mathf.Max(base.position.height * factor, specifiedValueOrDefault2);
}
}
this.dragElement.position = position;
}
// Token: 0x060033E7 RID: 13287 RVA: 0x00052634 File Offset: 0x00050834
private void UpdateDragElementPosition()
{
if (base.panel != null)
{
float num = this.m_Value - this.lowValue;
float width = this.dragElement.position.width;
float height = this.dragElement.position.height;
if (this.direction == Slider.Direction.Horizontal)
{
float num2 = base.position.width - width;
this.dragElement.position = new Rect(num / this.range * num2, this.dragElement.position.y, width, height);
}
else
{
float num3 = base.position.height - height;
this.dragElement.position = new Rect(this.dragElement.position.x, num / this.range * num3, width, height);
}
}
}
// Token: 0x060033E8 RID: 13288 RVA: 0x00052728 File Offset: 0x00050928
protected internal override void OnPostLayout(bool hasNewLayout)
{
if (hasNewLayout)
{
this.UpdateDragElementPosition();
}
}
// Token: 0x04000AC5 RID: 2757
private Rect m_DragElementStartPos;
// Token: 0x04000AC6 RID: 2758
private float m_Value;
// Token: 0x04000AC7 RID: 2759
private Slider.Direction m_Direction;
// Token: 0x02000348 RID: 840
public enum Direction
{
// Token: 0x04000AC9 RID: 2761
Horizontal,
// Token: 0x04000ACA RID: 2762
Vertical
}
}
}