1
This commit is contained in:
@@ -29,7 +29,7 @@ public class UITestPage : ModuleUIPage {
|
||||
dropdown.SetValue(list);
|
||||
dropdown.ValueChanged += (value) => Debug.Log(value);
|
||||
|
||||
scrollView = new UIScrollView(ScrollView, root, UIDirection.FromTopToBottom);
|
||||
scrollView = new UIScrollView(ScrollView, root, UIDirection.Vertical, UIDirection.FromLeftToRight, UIDirection.FromTopToBottom);
|
||||
}
|
||||
private void Update() {
|
||||
dropdown.Update();
|
||||
|
||||
@@ -692,6 +692,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: a3ee54ac782eb1d4a9c8b92a859c3d38, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
document: {fileID: 1327183335}
|
||||
--- !u!1 &1334378334
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<ui:Instance template="Toggle" name="Toggle" style="width: 200px;" />
|
||||
<ui:Instance template="Toggle" name="Toggle" style="width: 200px;" />
|
||||
<ui:VisualElement name="ScrollView" class="scrollview" style="width: 350px; height: 450px;">
|
||||
<ui:VisualElement name="Viewport" class="scrollview-viewport" style="margin-right: 30px; margin-bottom: 0;">
|
||||
<ui:VisualElement name="Container" class="scrollview-container" style="width: 100%; height: 1000px;">
|
||||
<ui:VisualElement name="Viewport" class="scrollview-viewport" style="margin-right: 30px; margin-bottom: 0; flex-direction: column;">
|
||||
<ui:VisualElement name="Container" class="scrollview-container" style="width: 100%; height: auto;">
|
||||
<ui:Label tabindex="-1" text="Label" parse-escape-sequences="true" display-tooltip-when-elided="true" />
|
||||
<ui:Button text="Button" parse-escape-sequences="true" display-tooltip-when-elided="true" />
|
||||
<ui:Toggle label="Toggle" />
|
||||
@@ -15,12 +15,17 @@
|
||||
<ui:DropdownField label="Dropdown" />
|
||||
<ui:TextField picking-mode="Ignore" label="Text Field" value="filler text" />
|
||||
<ui:FloatField label="Float Field" value="42.2" />
|
||||
<ui:FloatField label="Float Field" value="42.2" />
|
||||
<ui:FloatField label="Float Field" value="42.2" />
|
||||
<ui:FloatField label="Float Field" value="42.2" />
|
||||
<ui:FloatField label="Float Field" value="42.2" />
|
||||
<ui:FloatField label="Float Field" value="42.2" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="ScrollerHorizontal" class="scroller-horizontal scrollview-horizontal-scroller" style="right: 0; display: none;">
|
||||
<ui:VisualElement name="Dragger" class="scroller-horizontal-dragger scrollview-horizontal-scroller-dragger" />
|
||||
</ui:VisualElement>
|
||||
<ui:VisualElement name="ScrollerVertical" class="scroller-vertical scrollview-vertical-scroller">
|
||||
<ui:VisualElement name="ScrollerVertical" class="scroller-vertical scrollview-vertical-scroller" style="flex-direction: column;">
|
||||
<ui:VisualElement name="Dragger" class="scroller-vertical-dragger scrollview-vertical-scroller-dragger" />
|
||||
</ui:VisualElement>
|
||||
</ui:VisualElement>
|
||||
|
||||
@@ -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