1
This commit is contained in:
@@ -13,6 +13,10 @@ namespace MuHua {
|
||||
public readonly VisualElement canvas;
|
||||
/// <summary> 元素方向 </summary>
|
||||
public readonly UIDirection direction;
|
||||
/// <summary> 水平滑动方向 </summary>
|
||||
public readonly UIDirection sh;
|
||||
/// <summary> 垂直滑动方向 </summary>
|
||||
public readonly UIDirection sv;
|
||||
/// <summary> 值改变时 </summary>
|
||||
public event Action<Vector2> ValueChanged;
|
||||
|
||||
@@ -35,6 +39,8 @@ namespace MuHua {
|
||||
UIDirection sv = UIDirection.FromTopToBottom) : base(element) {
|
||||
this.canvas = canvas;
|
||||
this.direction = direction;
|
||||
this.sh = sh;
|
||||
this.sv = sv;
|
||||
|
||||
element.generateVisualContent += ElementGenerateVisualContent;
|
||||
|
||||
@@ -44,6 +50,7 @@ namespace MuHua {
|
||||
if (sv == UIDirection.FromTopToBottom) { vertical = new UIScroller(ScrollerVertical, canvas, sv); }
|
||||
if (sv == UIDirection.FromBottomToTop) { vertical = new UIScroller(ScrollerVertical, canvas, sv); }
|
||||
|
||||
|
||||
//设置事件
|
||||
horizontal.ValueChanged += (x) => { UpdateValue(new Vector2(x, value.y)); };
|
||||
vertical.ValueChanged += (y) => { UpdateValue(new Vector2(value.x, y)); };
|
||||
@@ -116,6 +123,8 @@ namespace MuHua {
|
||||
float maxHeight = Viewport.resolvedStyle.height - Container.resolvedStyle.height;
|
||||
float xPos = maxWidth * value.x;
|
||||
float yPos = maxHeight * value.y;
|
||||
xPos *= sh == UIDirection.FromLeftToRight ? 1 : -1;
|
||||
yPos *= sv == UIDirection.FromTopToBottom ? 1 : -1;
|
||||
Container.transform.position = new Vector3(xPos, yPos);
|
||||
|
||||
if (horizontal.value != value.x) { horizontal.UpdateValue(value.x, false); }
|
||||
|
||||
@@ -175,8 +175,8 @@ namespace MuHua {
|
||||
public override void UpdateValue(float value, bool send = true) {
|
||||
scroller.value = value;
|
||||
if (send) { scroller.ValueChanged?.Invoke(value); }
|
||||
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
||||
float y = Mathf.Lerp(max, 0, value);
|
||||
float max = scroller.Dragger.resolvedStyle.height - scroller.element.resolvedStyle.height;
|
||||
float y = Mathf.Lerp(0, max, value);
|
||||
scroller.Dragger.transform.position = new Vector3(0, y);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user