1
This commit is contained in:
@@ -4,6 +4,9 @@
|
|||||||
@import url("/Assets/MuHua/UITool/UIFloatingWindow/FloatingWindow.uss");
|
@import url("/Assets/MuHua/UITool/UIFloatingWindow/FloatingWindow.uss");
|
||||||
@import url("/Assets/MuHua/UITool/UIScroller/Scroller.uss");
|
@import url("/Assets/MuHua/UITool/UIScroller/Scroller.uss");
|
||||||
@import url("/Assets/MuHua/UITool/UIScrollView/ScrollView.uss");
|
@import url("/Assets/MuHua/UITool/UIScrollView/ScrollView.uss");
|
||||||
|
@import url("/Assets/MuHua/UITool/UISlider/Slider.uss");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
.unity-text-element {
|
.unity-text-element {
|
||||||
-unity-font-definition: url("project://database/Assets/MuHua/UITool/FontLibrary/SourceHanSansCN-Medium%20SDF.asset?fileID=11400000&guid=500f473f880266d43aaf04a728879085&type=2#SourceHanSansCN-Medium SDF");
|
-unity-font: url("project://database/Assets/MuHua/UITool/FontLibrary/SourceHanSansCN-Medium.otf?fileID=12800000&guid=3ceb88ff2ced01a439c5b2d1b63c86a5&type=3#SourceHanSansCN-Medium");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||||
<Style src="project://database/Assets/FontLibrary/UIToolkit/Fonts.uss?fileID=7433441132597879392&guid=52d41516f77d64346b5cd0ac76ba5b95&type=3#Fonts" />
|
<Style src="project://database/Assets/MuHua/UITool/FontLibrary/Fonts.uss?fileID=7433441132597879392&guid=52d41516f77d64346b5cd0ac76ba5b95&type=3#Fonts" />
|
||||||
<ui:Label tabindex="-1" text="Label" parse-escape-sequences="true" display-tooltip-when-elided="true" style="-unity-font-style: normal;" />
|
<ui:Label tabindex="-1" text="哈哈" parse-escape-sequences="true" display-tooltip-when-elided="true" style="-unity-font-style: normal;" />
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,120 @@
|
|||||||
|
.slider-horizontal {
|
||||||
|
height: 30px;
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-right: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
padding-left: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-horizontal-container {
|
||||||
|
height: 10px;
|
||||||
|
background-color: rgb(128, 128, 128);
|
||||||
|
border-top-left-radius: 3px;
|
||||||
|
border-top-right-radius: 3px;
|
||||||
|
border-bottom-right-radius: 3px;
|
||||||
|
border-bottom-left-radius: 3px;
|
||||||
|
border-top-width: 1px;
|
||||||
|
border-right-width: 1px;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
border-left-width: 1px;
|
||||||
|
border-left-color: rgb(51, 51, 51);
|
||||||
|
border-right-color: rgb(51, 51, 51);
|
||||||
|
border-top-color: rgb(51, 51, 51);
|
||||||
|
border-bottom-color: rgb(51, 51, 51);
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-horizontal-tracker {
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
border-top-left-radius: 2px;
|
||||||
|
border-top-right-radius: 2px;
|
||||||
|
border-bottom-right-radius: 2px;
|
||||||
|
border-bottom-left-radius: 2px;
|
||||||
|
width: 50%;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-horizontal-dragger {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
flex-shrink: 0;
|
||||||
|
border-top-width: 1px;
|
||||||
|
border-right-width: 1px;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
border-left-width: 1px;
|
||||||
|
border-left-color: rgb(51, 51, 51);
|
||||||
|
border-right-color: rgb(51, 51, 51);
|
||||||
|
border-top-color: rgb(51, 51, 51);
|
||||||
|
border-bottom-color: rgb(51, 51, 51);
|
||||||
|
border-top-left-radius: 10px;
|
||||||
|
border-top-right-radius: 10px;
|
||||||
|
border-bottom-right-radius: 10px;
|
||||||
|
border-bottom-left-radius: 10px;
|
||||||
|
translate: 8px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-vertical {
|
||||||
|
height: auto;
|
||||||
|
padding-top: 10px;
|
||||||
|
padding-right: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
padding-left: 10px;
|
||||||
|
width: 30px;
|
||||||
|
flex-grow: 1;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-vertical-container {
|
||||||
|
height: auto;
|
||||||
|
background-color: rgb(128, 128, 128);
|
||||||
|
border-top-left-radius: 3px;
|
||||||
|
border-top-right-radius: 3px;
|
||||||
|
border-bottom-right-radius: 3px;
|
||||||
|
border-bottom-left-radius: 3px;
|
||||||
|
border-top-width: 1px;
|
||||||
|
border-right-width: 1px;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
border-left-width: 1px;
|
||||||
|
border-left-color: rgb(51, 51, 51);
|
||||||
|
border-right-color: rgb(51, 51, 51);
|
||||||
|
border-top-color: rgb(51, 51, 51);
|
||||||
|
border-bottom-color: rgb(51, 51, 51);
|
||||||
|
flex-direction: column;
|
||||||
|
width: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-vertical-tracker {
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
border-top-left-radius: 2px;
|
||||||
|
border-top-right-radius: 2px;
|
||||||
|
border-bottom-right-radius: 2px;
|
||||||
|
border-bottom-left-radius: 2px;
|
||||||
|
width: auto;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-end;
|
||||||
|
height: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.slider-vertical-dragger {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
background-color: rgb(255, 255, 255);
|
||||||
|
flex-shrink: 0;
|
||||||
|
border-top-width: 1px;
|
||||||
|
border-right-width: 1px;
|
||||||
|
border-bottom-width: 1px;
|
||||||
|
border-left-width: 1px;
|
||||||
|
border-left-color: rgb(51, 51, 51);
|
||||||
|
border-right-color: rgb(51, 51, 51);
|
||||||
|
border-top-color: rgb(51, 51, 51);
|
||||||
|
border-bottom-color: rgb(51, 51, 51);
|
||||||
|
border-top-left-radius: 10px;
|
||||||
|
border-top-right-radius: 10px;
|
||||||
|
border-bottom-right-radius: 10px;
|
||||||
|
border-bottom-left-radius: 10px;
|
||||||
|
translate: 0 8px;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
|
||||||
|
<Style src="project://database/Assets/MuHua/UITool/UISlider/UISlider.uss?fileID=7433441132597879392&guid=ca2fb5adc90c9af4cb0426c459d7e9e5&type=3#UISlider" />
|
||||||
|
<ui:VisualElement name="SliderHorizontal1" class="slider-horizontal">
|
||||||
|
<ui:VisualElement name="Container" class="slider-horizontal-container">
|
||||||
|
<ui:VisualElement name="Tracker" class="slider-horizontal-tracker">
|
||||||
|
<ui:VisualElement name="Dragger" class="slider-horizontal-dragger" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
<ui:VisualElement name="SliderHorizontal2" class="slider-horizontal">
|
||||||
|
<ui:VisualElement name="Container" class="slider-horizontal-container" style="flex-direction: row-reverse;">
|
||||||
|
<ui:VisualElement name="Tracker" class="slider-horizontal-tracker" style="flex-direction: row-reverse;">
|
||||||
|
<ui:VisualElement name="Dragger" class="slider-horizontal-dragger" style="translate: -8px 0;" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
<ui:VisualElement style="flex-grow: 1; flex-direction: row; justify-content: space-around;">
|
||||||
|
<ui:VisualElement name="SliderVertical1" class="slider-vertical">
|
||||||
|
<ui:VisualElement name="Container" class="slider-vertical-container">
|
||||||
|
<ui:VisualElement name="Tracker" class="slider-vertical-tracker">
|
||||||
|
<ui:VisualElement name="Dragger" class="slider-vertical-dragger" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
<ui:VisualElement name="SliderVertical2" class="slider-vertical">
|
||||||
|
<ui:VisualElement name="Container" class="slider-vertical-container" style="flex-direction: column-reverse;">
|
||||||
|
<ui:VisualElement name="Tracker" class="slider-vertical-tracker" style="flex-direction: column-reverse;">
|
||||||
|
<ui:VisualElement name="Dragger" class="slider-vertical-dragger" style="translate: 0 -8px;" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:UXML>
|
||||||
@@ -1 +0,0 @@
|
|||||||
VisualElement {}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<engine:UXML
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xmlns:engine="UnityEngine.UIElements"
|
|
||||||
xmlns:editor="UnityEditor.UIElements"
|
|
||||||
xsi:noNamespaceSchemaLocation="../../../../UIElementsSchema/UIElements.xsd"
|
|
||||||
>
|
|
||||||
|
|
||||||
</engine:UXML>
|
|
||||||
@@ -13,6 +13,12 @@ public class TestUI : MonoBehaviour {
|
|||||||
private UIScrollView scrollView;
|
private UIScrollView scrollView;
|
||||||
private UIScrollView scrollViewHorizontal;
|
private UIScrollView scrollViewHorizontal;
|
||||||
private UIScrollView scrollViewVertical;
|
private UIScrollView scrollViewVertical;
|
||||||
|
|
||||||
|
private UISlider slider1;
|
||||||
|
private UISlider slider2;
|
||||||
|
private UISlider slider3;
|
||||||
|
private UISlider slider4;
|
||||||
|
|
||||||
private void Awake() {
|
private void Awake() {
|
||||||
VisualElement ScrollView = root.Q<VisualElement>("ScrollView");
|
VisualElement ScrollView = root.Q<VisualElement>("ScrollView");
|
||||||
scrollView = new UIScrollView(ScrollView, root, UIDirection.HorizontalAndVertical);
|
scrollView = new UIScrollView(ScrollView, root, UIDirection.HorizontalAndVertical);
|
||||||
@@ -22,10 +28,29 @@ public class TestUI : MonoBehaviour {
|
|||||||
|
|
||||||
VisualElement ScrollViewVertical = root.Q<VisualElement>("ScrollViewVertical");
|
VisualElement ScrollViewVertical = root.Q<VisualElement>("ScrollViewVertical");
|
||||||
scrollViewVertical = new UIScrollView(ScrollViewVertical, root, UIDirection.Vertical);
|
scrollViewVertical = new UIScrollView(ScrollViewVertical, root, UIDirection.Vertical);
|
||||||
|
|
||||||
|
VisualElement Slider1 = root.Q<VisualElement>("SliderHorizontal1");
|
||||||
|
slider1 = new UISlider(Slider1, root, UIDirection.FromLeftToRight);
|
||||||
|
|
||||||
|
VisualElement Slider2 = root.Q<VisualElement>("SliderHorizontal2");
|
||||||
|
slider2 = new UISlider(Slider2, root, UIDirection.FromRightToLeft);
|
||||||
|
|
||||||
|
VisualElement Slider3 = root.Q<VisualElement>("SliderVertical1");
|
||||||
|
slider3 = new UISlider(Slider3, root, UIDirection.FromTopToBottom);
|
||||||
|
|
||||||
|
VisualElement Slider4 = root.Q<VisualElement>("SliderVertical2");
|
||||||
|
slider4 = new UISlider(Slider4, root, UIDirection.FromBottomToTop);
|
||||||
|
|
||||||
|
slider4.ValueChanged += (obj) => { Debug.Log(obj); };
|
||||||
}
|
}
|
||||||
private void Update() {
|
private void Update() {
|
||||||
scrollView.Update();
|
scrollView.Update();
|
||||||
scrollViewHorizontal.Update();
|
scrollViewHorizontal.Update();
|
||||||
scrollViewVertical.Update();
|
scrollViewVertical.Update();
|
||||||
|
|
||||||
|
slider1.Update();
|
||||||
|
slider2.Update();
|
||||||
|
slider3.Update();
|
||||||
|
slider4.Update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,11 @@
|
|||||||
<ui:Template name="ScrollView" src="project://database/Assets/MuHua/UITool/UIScrollView/ScrollView.uxml?fileID=9197481963319205126&guid=e95fad6397f22504eb724a8ea0c8d926&type=3#ScrollView" />
|
<ui:Template name="ScrollView" src="project://database/Assets/MuHua/UITool/UIScrollView/ScrollView.uxml?fileID=9197481963319205126&guid=e95fad6397f22504eb724a8ea0c8d926&type=3#ScrollView" />
|
||||||
<ui:Template name="ScrollViewHorizontal" src="project://database/Assets/MuHua/UITool/UIScrollView/ScrollViewHorizontal.uxml?fileID=9197481963319205126&guid=ac460a2d93de869499c04a4295795595&type=3#ScrollViewHorizontal" />
|
<ui:Template name="ScrollViewHorizontal" src="project://database/Assets/MuHua/UITool/UIScrollView/ScrollViewHorizontal.uxml?fileID=9197481963319205126&guid=ac460a2d93de869499c04a4295795595&type=3#ScrollViewHorizontal" />
|
||||||
<ui:Template name="ScrollViewVertical" src="project://database/Assets/MuHua/UITool/UIScrollView/ScrollViewVertical.uxml?fileID=9197481963319205126&guid=df824968495905e4db8daa1a4a942d6f&type=3#ScrollViewVertical" />
|
<ui:Template name="ScrollViewVertical" src="project://database/Assets/MuHua/UITool/UIScrollView/ScrollViewVertical.uxml?fileID=9197481963319205126&guid=df824968495905e4db8daa1a4a942d6f&type=3#ScrollViewVertical" />
|
||||||
|
<ui:Template name="UISlider" src="project://database/Assets/MuHua/UITool/UISlider/UISlider.uxml?fileID=9197481963319205126&guid=7360aa427d614894eab01f938a59da18&type=3#UISlider" />
|
||||||
<ui:VisualElement style="flex-grow: 1; flex-direction: row;">
|
<ui:VisualElement style="flex-grow: 1; flex-direction: row;">
|
||||||
<ui:Instance template="ScrollView" name="ScrollView" />
|
<ui:Instance template="ScrollView" name="ScrollView" />
|
||||||
<ui:Instance template="ScrollViewHorizontal" name="ScrollViewHorizontal" />
|
<ui:Instance template="ScrollViewHorizontal" name="ScrollViewHorizontal" />
|
||||||
<ui:Instance template="ScrollViewVertical" name="ScrollViewVertical" />
|
<ui:Instance template="ScrollViewVertical" name="ScrollViewVertical" />
|
||||||
|
<ui:Instance template="UISlider" name="UISlider" style="width: 300px;" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"type": "tool",
|
"type": "tool",
|
||||||
"samples": [
|
"samples": [
|
||||||
{
|
{
|
||||||
"displayName": "Label Follow Example",
|
"displayName": "Example",
|
||||||
"description": "An example showing how to use the Label Follow system.",
|
"description": "An example showing how to use the Label Follow system.",
|
||||||
"path": "Samples"
|
"path": "Samples"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,19 +23,24 @@ namespace MuHua {
|
|||||||
public Vector3 originalPosition;
|
public Vector3 originalPosition;
|
||||||
public Vector3 pointerPosition;
|
public Vector3 pointerPosition;
|
||||||
|
|
||||||
private UIScroller horizontal;
|
public readonly UIScroller horizontal;
|
||||||
private UIScroller vertical;
|
public readonly UIScroller vertical;
|
||||||
|
|
||||||
public VisualElement Viewport => element.Q<VisualElement>("Viewport");
|
public readonly VisualElement Viewport;
|
||||||
public VisualElement Container => element.Q<VisualElement>("Container");
|
public readonly VisualElement Container;
|
||||||
public VisualElement ScrollerHorizontal => element.Q<VisualElement>("ScrollerHorizontal");
|
public readonly VisualElement ScrollerHorizontal;
|
||||||
public VisualElement ScrollerVertical => element.Q<VisualElement>("ScrollerVertical");
|
public readonly VisualElement ScrollerVertical;
|
||||||
|
|
||||||
public UIScrollView(VisualElement element, VisualElement canvas, UIDirection direction = UIDirection.HorizontalAndVertical, UIDirection sh = UIDirection.FromLeftToRight, UIDirection sv = UIDirection.FromTopToBottom) {
|
public UIScrollView(VisualElement element, VisualElement canvas, UIDirection direction = UIDirection.HorizontalAndVertical, UIDirection sh = UIDirection.FromLeftToRight, UIDirection sv = UIDirection.FromTopToBottom) {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
|
|
||||||
|
Viewport = element.Q<VisualElement>("Viewport");
|
||||||
|
Container = element.Q<VisualElement>("Container");
|
||||||
|
ScrollerHorizontal = element.Q<VisualElement>("ScrollerHorizontal");
|
||||||
|
ScrollerVertical = element.Q<VisualElement>("ScrollerVertical");
|
||||||
|
|
||||||
element.generateVisualContent += ElementGenerateVisualContent;
|
element.generateVisualContent += ElementGenerateVisualContent;
|
||||||
|
|
||||||
if (sh == UIDirection.FromLeftToRight) { horizontal = new UIScroller(ScrollerHorizontal, canvas, sh); }
|
if (sh == UIDirection.FromLeftToRight) { horizontal = new UIScroller(ScrollerHorizontal, canvas, sh); }
|
||||||
@@ -60,8 +65,8 @@ namespace MuHua {
|
|||||||
float width = Mathf.Clamp01(Viewport.resolvedStyle.width / Container.resolvedStyle.width);
|
float width = Mathf.Clamp01(Viewport.resolvedStyle.width / Container.resolvedStyle.width);
|
||||||
float height = Mathf.Clamp01(Viewport.resolvedStyle.height / Container.resolvedStyle.height);
|
float height = Mathf.Clamp01(Viewport.resolvedStyle.height / Container.resolvedStyle.height);
|
||||||
|
|
||||||
horizontal.dragger.style.width = Length.Percent(width * 100);
|
horizontal.Dragger.style.width = Length.Percent(width * 100);
|
||||||
vertical.dragger.style.height = Length.Percent(height * 100);
|
vertical.Dragger.style.height = Length.Percent(height * 100);
|
||||||
}
|
}
|
||||||
/// <summary> 视图滚轮滑动 </summary>
|
/// <summary> 视图滚轮滑动 </summary>
|
||||||
private void ViewportWheel(WheelEvent evt) {
|
private void ViewportWheel(WheelEvent evt) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ using UnityEngine.UIElements;
|
|||||||
|
|
||||||
namespace MuHua {
|
namespace MuHua {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 滑块
|
/// 滚动条
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UIScroller {
|
public class UIScroller {
|
||||||
/// <summary> 绑定的元素 </summary>
|
/// <summary> 绑定的元素 </summary>
|
||||||
@@ -23,34 +23,36 @@ namespace MuHua {
|
|||||||
public float originalPosition;
|
public float originalPosition;
|
||||||
public float pointerPosition;
|
public float pointerPosition;
|
||||||
|
|
||||||
private UIScrollerFunc scrollerFunc;
|
public readonly UIScrollerFunc scrollerFunc;
|
||||||
|
|
||||||
public VisualElement dragger => element.Q<VisualElement>("Dragger");
|
public readonly VisualElement Dragger;
|
||||||
|
|
||||||
public UIScroller(VisualElement element, VisualElement canvas, UIDirection direction = UIDirection.FromLeftToRight) {
|
public UIScroller(VisualElement element, VisualElement canvas, UIDirection direction = UIDirection.FromLeftToRight) {
|
||||||
this.element = element;
|
this.element = element;
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
this.direction = direction;
|
this.direction = direction;
|
||||||
|
|
||||||
|
Dragger = element.Q<VisualElement>("Dragger");
|
||||||
|
|
||||||
if (direction == UIDirection.FromLeftToRight) { scrollerFunc = new FromLeftToRight(this); }
|
if (direction == UIDirection.FromLeftToRight) { scrollerFunc = new FromLeftToRight(this); }
|
||||||
if (direction == UIDirection.FromRightToLeft) { scrollerFunc = new FromRightToLeft(this); }
|
if (direction == UIDirection.FromRightToLeft) { scrollerFunc = new FromRightToLeft(this); }
|
||||||
if (direction == UIDirection.FromTopToBottom) { scrollerFunc = new FromTopToBottom(this); }
|
if (direction == UIDirection.FromTopToBottom) { scrollerFunc = new FromTopToBottom(this); }
|
||||||
if (direction == UIDirection.FromBottomToTop) { scrollerFunc = new FromBottomToTop(this); }
|
if (direction == UIDirection.FromBottomToTop) { scrollerFunc = new FromBottomToTop(this); }
|
||||||
|
|
||||||
//设置事件
|
//设置事件
|
||||||
dragger.RegisterCallback<PointerDownEvent>(DraggerDown);
|
Dragger.RegisterCallback<PointerDownEvent>(DraggerDown);
|
||||||
element.RegisterCallback<PointerDownEvent>(ElementDown);
|
element.RegisterCallback<PointerDownEvent>(ElementDown);
|
||||||
|
|
||||||
canvas.RegisterCallback<PointerUpEvent>((evt) => isDragger = false);
|
canvas.RegisterCallback<PointerUpEvent>((evt) => isDragger = false);
|
||||||
canvas.RegisterCallback<PointerLeaveEvent>((evt) => isDragger = false);
|
canvas.RegisterCallback<PointerLeaveEvent>((evt) => isDragger = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void DraggerDown(PointerDownEvent evt) => scrollerFunc.DraggerDown(evt);
|
private void DraggerDown(PointerDownEvent evt) => scrollerFunc.DraggerDown(evt);
|
||||||
public virtual void ElementDown(PointerDownEvent evt) => scrollerFunc.ElementDown(evt);
|
private void ElementDown(PointerDownEvent evt) => scrollerFunc.ElementDown(evt);
|
||||||
/// <summary> 更新状态 </summary>
|
/// <summary> 更新状态 </summary>
|
||||||
public virtual void Update() => scrollerFunc.Update();
|
public void Update() => scrollerFunc.Update();
|
||||||
/// <summary> 更新值(0-1) </summary>
|
/// <summary> 更新值(0-1) </summary>
|
||||||
public virtual void UpdateValue(float value, bool send = true) => scrollerFunc.UpdateValue(value, send);
|
public void UpdateValue(float value, bool send = true) => scrollerFunc.UpdateValue(value, send);
|
||||||
|
|
||||||
public abstract class UIScrollerFunc {
|
public abstract class UIScrollerFunc {
|
||||||
public readonly UIScroller scroller;
|
public readonly UIScroller scroller;
|
||||||
@@ -68,12 +70,12 @@ namespace MuHua {
|
|||||||
public FromLeftToRight(UIScroller scroller) : base(scroller) { }
|
public FromLeftToRight(UIScroller scroller) : base(scroller) { }
|
||||||
public override void DraggerDown(PointerDownEvent evt) {
|
public override void DraggerDown(PointerDownEvent evt) {
|
||||||
scroller.isDragger = true;
|
scroller.isDragger = true;
|
||||||
scroller.originalPosition = scroller.dragger.transform.position.x;
|
scroller.originalPosition = scroller.Dragger.transform.position.x;
|
||||||
scroller.pointerPosition = UITool.GetMousePosition().x;
|
scroller.pointerPosition = UITool.GetMousePosition().x;
|
||||||
}
|
}
|
||||||
public override void ElementDown(PointerDownEvent evt) {
|
public override void ElementDown(PointerDownEvent evt) {
|
||||||
float offset = evt.localPosition.x - scroller.dragger.resolvedStyle.width * 0.5f;
|
float offset = evt.localPosition.x - scroller.Dragger.resolvedStyle.width * 0.5f;
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.dragger.resolvedStyle.width;
|
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
||||||
float value = Mathf.InverseLerp(0, max, offset);
|
float value = Mathf.InverseLerp(0, max, offset);
|
||||||
UpdateValue(value);
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
@@ -81,16 +83,16 @@ namespace MuHua {
|
|||||||
if (!scroller.isDragger) { return; }
|
if (!scroller.isDragger) { return; }
|
||||||
float differ = UITool.GetMousePosition().x - scroller.pointerPosition;
|
float differ = UITool.GetMousePosition().x - scroller.pointerPosition;
|
||||||
float offset = differ + scroller.originalPosition;
|
float offset = differ + scroller.originalPosition;
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.dragger.resolvedStyle.width;
|
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
||||||
float value = Mathf.InverseLerp(0, max, offset);
|
float value = Mathf.InverseLerp(0, max, offset);
|
||||||
UpdateValue(value);
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
public override void UpdateValue(float value, bool send = true) {
|
public override void UpdateValue(float value, bool send = true) {
|
||||||
scroller.value = value;
|
scroller.value = value;
|
||||||
if (send) { scroller.ValueChanged?.Invoke(value); }
|
if (send) { scroller.ValueChanged?.Invoke(value); }
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.dragger.resolvedStyle.width;
|
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
||||||
float x = Mathf.Lerp(0, max, value);
|
float x = Mathf.Lerp(0, max, value);
|
||||||
scroller.dragger.transform.position = new Vector3(x, 0);
|
scroller.Dragger.transform.position = new Vector3(x, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,12 +100,12 @@ namespace MuHua {
|
|||||||
public FromRightToLeft(UIScroller scroller) : base(scroller) { }
|
public FromRightToLeft(UIScroller scroller) : base(scroller) { }
|
||||||
public override void DraggerDown(PointerDownEvent evt) {
|
public override void DraggerDown(PointerDownEvent evt) {
|
||||||
scroller.isDragger = true;
|
scroller.isDragger = true;
|
||||||
scroller.originalPosition = scroller.dragger.transform.position.x;
|
scroller.originalPosition = scroller.Dragger.transform.position.x;
|
||||||
scroller.pointerPosition = UITool.GetMousePosition().x;
|
scroller.pointerPosition = UITool.GetMousePosition().x;
|
||||||
}
|
}
|
||||||
public override void ElementDown(PointerDownEvent evt) {
|
public override void ElementDown(PointerDownEvent evt) {
|
||||||
float offset = evt.localPosition.x - scroller.dragger.resolvedStyle.width * 0.5f;
|
float offset = evt.localPosition.x - scroller.Dragger.resolvedStyle.width * 0.5f;
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.dragger.resolvedStyle.width;
|
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
||||||
float value = Mathf.InverseLerp(max, 0, offset);
|
float value = Mathf.InverseLerp(max, 0, offset);
|
||||||
UpdateValue(value);
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
@@ -111,16 +113,16 @@ namespace MuHua {
|
|||||||
if (!scroller.isDragger) { return; }
|
if (!scroller.isDragger) { return; }
|
||||||
float differ = UITool.GetMousePosition().x - scroller.pointerPosition;
|
float differ = UITool.GetMousePosition().x - scroller.pointerPosition;
|
||||||
float offset = differ + scroller.originalPosition;
|
float offset = differ + scroller.originalPosition;
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.dragger.resolvedStyle.width;
|
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
||||||
float value = Mathf.InverseLerp(max, 0, offset);
|
float value = Mathf.InverseLerp(max, 0, offset);
|
||||||
UpdateValue(value);
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
public override void UpdateValue(float value, bool send = true) {
|
public override void UpdateValue(float value, bool send = true) {
|
||||||
scroller.value = value;
|
scroller.value = value;
|
||||||
if (send) { scroller.ValueChanged?.Invoke(value); }
|
if (send) { scroller.ValueChanged?.Invoke(value); }
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.dragger.resolvedStyle.width;
|
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
||||||
float x = Mathf.Lerp(max, 0, value);
|
float x = Mathf.Lerp(max, 0, value);
|
||||||
scroller.dragger.transform.position = new Vector3(x, 0);
|
scroller.Dragger.transform.position = new Vector3(x, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,12 +130,12 @@ namespace MuHua {
|
|||||||
public FromTopToBottom(UIScroller scroller) : base(scroller) { }
|
public FromTopToBottom(UIScroller scroller) : base(scroller) { }
|
||||||
public override void DraggerDown(PointerDownEvent evt) {
|
public override void DraggerDown(PointerDownEvent evt) {
|
||||||
scroller.isDragger = true;
|
scroller.isDragger = true;
|
||||||
scroller.originalPosition = scroller.dragger.transform.position.y;
|
scroller.originalPosition = scroller.Dragger.transform.position.y;
|
||||||
scroller.pointerPosition = Screen.height - UITool.GetMousePosition().y;
|
scroller.pointerPosition = Screen.height - UITool.GetMousePosition().y;
|
||||||
}
|
}
|
||||||
public override void ElementDown(PointerDownEvent evt) {
|
public override void ElementDown(PointerDownEvent evt) {
|
||||||
float offset = evt.localPosition.y - scroller.dragger.resolvedStyle.height * 0.5f;
|
float offset = evt.localPosition.y - scroller.Dragger.resolvedStyle.height * 0.5f;
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.dragger.resolvedStyle.height;
|
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
||||||
float value = Mathf.InverseLerp(0, max, offset);
|
float value = Mathf.InverseLerp(0, max, offset);
|
||||||
UpdateValue(value);
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
@@ -141,16 +143,16 @@ namespace MuHua {
|
|||||||
if (!scroller.isDragger) { return; }
|
if (!scroller.isDragger) { return; }
|
||||||
float differ = Screen.height - UITool.GetMousePosition().y - scroller.pointerPosition;
|
float differ = Screen.height - UITool.GetMousePosition().y - scroller.pointerPosition;
|
||||||
float offset = differ + scroller.originalPosition;
|
float offset = differ + scroller.originalPosition;
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.dragger.resolvedStyle.height;
|
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
||||||
float value = Mathf.InverseLerp(0, max, offset);
|
float value = Mathf.InverseLerp(0, max, offset);
|
||||||
UpdateValue(value);
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
public override void UpdateValue(float value, bool send = true) {
|
public override void UpdateValue(float value, bool send = true) {
|
||||||
scroller.value = value;
|
scroller.value = value;
|
||||||
if (send) { scroller.ValueChanged?.Invoke(value); }
|
if (send) { scroller.ValueChanged?.Invoke(value); }
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.dragger.resolvedStyle.height;
|
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
||||||
float y = Mathf.Lerp(0, max, value);
|
float y = Mathf.Lerp(0, max, value);
|
||||||
scroller.dragger.transform.position = new Vector3(0, y);
|
scroller.Dragger.transform.position = new Vector3(0, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,12 +160,12 @@ namespace MuHua {
|
|||||||
public FromBottomToTop(UIScroller scroller) : base(scroller) { }
|
public FromBottomToTop(UIScroller scroller) : base(scroller) { }
|
||||||
public override void DraggerDown(PointerDownEvent evt) {
|
public override void DraggerDown(PointerDownEvent evt) {
|
||||||
scroller.isDragger = true;
|
scroller.isDragger = true;
|
||||||
scroller.originalPosition = scroller.dragger.transform.position.y;
|
scroller.originalPosition = scroller.Dragger.transform.position.y;
|
||||||
scroller.pointerPosition = Screen.height - UITool.GetMousePosition().y;
|
scroller.pointerPosition = Screen.height - UITool.GetMousePosition().y;
|
||||||
}
|
}
|
||||||
public override void ElementDown(PointerDownEvent evt) {
|
public override void ElementDown(PointerDownEvent evt) {
|
||||||
float offset = evt.localPosition.y - scroller.dragger.resolvedStyle.height * 0.5f;
|
float offset = evt.localPosition.y - scroller.Dragger.resolvedStyle.height * 0.5f;
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.dragger.resolvedStyle.height;
|
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
||||||
float value = Mathf.InverseLerp(max, 0, offset);
|
float value = Mathf.InverseLerp(max, 0, offset);
|
||||||
UpdateValue(value);
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
@@ -171,16 +173,16 @@ namespace MuHua {
|
|||||||
if (!scroller.isDragger) { return; }
|
if (!scroller.isDragger) { return; }
|
||||||
float differ = Screen.height - UITool.GetMousePosition().y - scroller.pointerPosition;
|
float differ = Screen.height - UITool.GetMousePosition().y - scroller.pointerPosition;
|
||||||
float offset = differ + scroller.originalPosition;
|
float offset = differ + scroller.originalPosition;
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.dragger.resolvedStyle.height;
|
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
||||||
float value = Mathf.InverseLerp(max, 0, offset);
|
float value = Mathf.InverseLerp(max, 0, offset);
|
||||||
UpdateValue(value);
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
public override void UpdateValue(float value, bool send = true) {
|
public override void UpdateValue(float value, bool send = true) {
|
||||||
scroller.value = value;
|
scroller.value = value;
|
||||||
if (send) { scroller.ValueChanged?.Invoke(value); }
|
if (send) { scroller.ValueChanged?.Invoke(value); }
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.dragger.resolvedStyle.height;
|
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
||||||
float y = Mathf.Lerp(max, 0, value);
|
float y = Mathf.Lerp(max, 0, value);
|
||||||
scroller.dragger.transform.position = new Vector3(0, y);
|
scroller.Dragger.transform.position = new Vector3(0, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,185 @@
|
|||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
public class UISlider : MonoBehaviour
|
namespace MuHua {
|
||||||
{
|
/// <summary>
|
||||||
// Start is called before the first frame update
|
/// 滑块
|
||||||
void Start()
|
/// </summary>
|
||||||
{
|
public class UISlider {
|
||||||
|
/// <summary> 绑定的元素 </summary>
|
||||||
}
|
public readonly VisualElement element;
|
||||||
|
/// <summary> 绑定的画布 </summary>
|
||||||
|
public readonly VisualElement canvas;
|
||||||
|
/// <summary> 元素方向 </summary>
|
||||||
|
public readonly UIDirection direction;
|
||||||
|
/// <summary> 值改变时 </summary>
|
||||||
|
public event Action<float> ValueChanged;
|
||||||
|
|
||||||
// Update is called once per frame
|
public float value;
|
||||||
void Update()
|
public bool isDragger;
|
||||||
{
|
public float originalPosition;
|
||||||
|
public float pointerPosition;
|
||||||
}
|
|
||||||
|
public readonly UISliderFunc sliderFunc;
|
||||||
|
|
||||||
|
public readonly VisualElement Container;
|
||||||
|
public readonly VisualElement Tracker;
|
||||||
|
public readonly VisualElement Dragger;
|
||||||
|
|
||||||
|
public UISlider(VisualElement element, VisualElement canvas, UIDirection direction = UIDirection.FromLeftToRight) {
|
||||||
|
this.element = element;
|
||||||
|
this.canvas = canvas;
|
||||||
|
this.direction = direction;
|
||||||
|
|
||||||
|
Container = element.Q<VisualElement>("Container");
|
||||||
|
Tracker = element.Q<VisualElement>("Tracker");
|
||||||
|
Dragger = element.Q<VisualElement>("Dragger");
|
||||||
|
|
||||||
|
if (direction == UIDirection.FromLeftToRight) { sliderFunc = new FromLeftToRight(this); }
|
||||||
|
if (direction == UIDirection.FromRightToLeft) { sliderFunc = new FromRightToLeft(this); }
|
||||||
|
if (direction == UIDirection.FromTopToBottom) { sliderFunc = new FromTopToBottom(this); }
|
||||||
|
if (direction == UIDirection.FromBottomToTop) { sliderFunc = new FromBottomToTop(this); }
|
||||||
|
|
||||||
|
//设置事件
|
||||||
|
Dragger.RegisterCallback<PointerDownEvent>(DraggerDown);
|
||||||
|
Container.RegisterCallback<PointerDownEvent>(ElementDown);
|
||||||
|
|
||||||
|
canvas.RegisterCallback<PointerUpEvent>((evt) => isDragger = false);
|
||||||
|
canvas.RegisterCallback<PointerLeaveEvent>((evt) => isDragger = false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DraggerDown(PointerDownEvent evt) => sliderFunc.DraggerDown(evt);
|
||||||
|
private void ElementDown(PointerDownEvent evt) => sliderFunc.ElementDown(evt);
|
||||||
|
/// <summary> 更新状态 </summary>
|
||||||
|
public void Update() => sliderFunc.Update();
|
||||||
|
/// <summary> 更新值(0-1) </summary>
|
||||||
|
public void UpdateValue(float value, bool send = true) => sliderFunc.UpdateValue(value, send);
|
||||||
|
|
||||||
|
public abstract class UISliderFunc {
|
||||||
|
public readonly UISlider slider;
|
||||||
|
public UISliderFunc(UISlider slider) => this.slider = slider;
|
||||||
|
|
||||||
|
public abstract void DraggerDown(PointerDownEvent evt);
|
||||||
|
public abstract void ElementDown(PointerDownEvent evt);
|
||||||
|
/// <summary> 更新状态 </summary>
|
||||||
|
public abstract void Update();
|
||||||
|
/// <summary> 更新值(0-1) </summary>
|
||||||
|
public abstract void UpdateValue(float value, bool send = true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FromLeftToRight : UISliderFunc {
|
||||||
|
public FromLeftToRight(UISlider slider) : base(slider) { }
|
||||||
|
public override void DraggerDown(PointerDownEvent evt) {
|
||||||
|
slider.isDragger = true;
|
||||||
|
slider.originalPosition = slider.Tracker.resolvedStyle.width;
|
||||||
|
slider.pointerPosition = UITool.GetMousePosition().x;
|
||||||
|
}
|
||||||
|
public override void ElementDown(PointerDownEvent evt) {
|
||||||
|
float offset = evt.localPosition.x;
|
||||||
|
float max = slider.Container.resolvedStyle.width;
|
||||||
|
float value = Mathf.InverseLerp(0, max, offset);
|
||||||
|
UpdateValue(value);
|
||||||
|
}
|
||||||
|
public override void Update() {
|
||||||
|
if (!slider.isDragger) { return; }
|
||||||
|
float differ = UITool.GetMousePosition().x - slider.pointerPosition;
|
||||||
|
float offset = differ + slider.originalPosition;
|
||||||
|
float max = slider.Container.resolvedStyle.width;
|
||||||
|
float value = Mathf.InverseLerp(0, max, offset);
|
||||||
|
UpdateValue(value);
|
||||||
|
}
|
||||||
|
public override void UpdateValue(float value, bool send = true) {
|
||||||
|
slider.value = value;
|
||||||
|
if (send) { slider.ValueChanged?.Invoke(value); }
|
||||||
|
slider.Tracker.style.width = Length.Percent(value * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FromRightToLeft : UISliderFunc {
|
||||||
|
public FromRightToLeft(UISlider slider) : base(slider) { }
|
||||||
|
public override void DraggerDown(PointerDownEvent evt) {
|
||||||
|
slider.isDragger = true;
|
||||||
|
slider.originalPosition = slider.Container.resolvedStyle.width - slider.Tracker.resolvedStyle.width;
|
||||||
|
slider.pointerPosition = UITool.GetMousePosition().x;
|
||||||
|
}
|
||||||
|
public override void ElementDown(PointerDownEvent evt) {
|
||||||
|
float offset = evt.localPosition.x;
|
||||||
|
float max = slider.Container.resolvedStyle.width;
|
||||||
|
float value = Mathf.InverseLerp(max, 0, offset);
|
||||||
|
UpdateValue(value);
|
||||||
|
}
|
||||||
|
public override void Update() {
|
||||||
|
if (!slider.isDragger) { return; }
|
||||||
|
float differ = UITool.GetMousePosition().x - slider.pointerPosition;
|
||||||
|
float offset = differ + slider.originalPosition;
|
||||||
|
float max = slider.Container.resolvedStyle.width;
|
||||||
|
float value = Mathf.InverseLerp(max, 0, offset);
|
||||||
|
UpdateValue(value);
|
||||||
|
}
|
||||||
|
public override void UpdateValue(float value, bool send = true) {
|
||||||
|
slider.value = value;
|
||||||
|
if (send) { slider.ValueChanged?.Invoke(value); }
|
||||||
|
slider.Tracker.style.width = Length.Percent(value * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FromTopToBottom : UISliderFunc {
|
||||||
|
public FromTopToBottom(UISlider slider) : base(slider) { }
|
||||||
|
public override void DraggerDown(PointerDownEvent evt) {
|
||||||
|
slider.isDragger = true;
|
||||||
|
slider.originalPosition = slider.Tracker.resolvedStyle.height;
|
||||||
|
slider.pointerPosition = Screen.height - UITool.GetMousePosition().y;
|
||||||
|
}
|
||||||
|
public override void ElementDown(PointerDownEvent evt) {
|
||||||
|
float offset = evt.localPosition.y;
|
||||||
|
float max = slider.Container.resolvedStyle.height;
|
||||||
|
float value = Mathf.InverseLerp(0, max, offset);
|
||||||
|
UpdateValue(value);
|
||||||
|
}
|
||||||
|
public override void Update() {
|
||||||
|
if (!slider.isDragger) { return; }
|
||||||
|
float differ = Screen.height - UITool.GetMousePosition().y - slider.pointerPosition;
|
||||||
|
float offset = differ + slider.originalPosition;
|
||||||
|
float max = slider.Container.resolvedStyle.height;
|
||||||
|
float value = Mathf.InverseLerp(0, max, offset);
|
||||||
|
UpdateValue(value);
|
||||||
|
}
|
||||||
|
public override void UpdateValue(float value, bool send = true) {
|
||||||
|
slider.value = value;
|
||||||
|
if (send) { slider.ValueChanged?.Invoke(value); }
|
||||||
|
slider.Tracker.style.height = Length.Percent(value * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FromBottomToTop : UISliderFunc {
|
||||||
|
public FromBottomToTop(UISlider slider) : base(slider) { }
|
||||||
|
public override void DraggerDown(PointerDownEvent evt) {
|
||||||
|
slider.isDragger = true;
|
||||||
|
slider.originalPosition = slider.Container.resolvedStyle.height - slider.Tracker.resolvedStyle.height;
|
||||||
|
slider.pointerPosition = Screen.height - UITool.GetMousePosition().y;
|
||||||
|
}
|
||||||
|
public override void ElementDown(PointerDownEvent evt) {
|
||||||
|
float offset = evt.localPosition.y;
|
||||||
|
float max = slider.Container.resolvedStyle.height;
|
||||||
|
float value = Mathf.InverseLerp(max, 0, offset);
|
||||||
|
UpdateValue(value);
|
||||||
|
}
|
||||||
|
public override void Update() {
|
||||||
|
if (!slider.isDragger) { return; }
|
||||||
|
float differ = Screen.height - UITool.GetMousePosition().y - slider.pointerPosition;
|
||||||
|
float offset = differ + slider.originalPosition;
|
||||||
|
float max = slider.Container.resolvedStyle.height;
|
||||||
|
float value = Mathf.InverseLerp(max, 0, offset);
|
||||||
|
UpdateValue(value);
|
||||||
|
}
|
||||||
|
public override void UpdateValue(float value, bool send = true) {
|
||||||
|
slider.value = value;
|
||||||
|
if (send) { slider.ValueChanged?.Invoke(value); }
|
||||||
|
slider.Tracker.style.height = Length.Percent(value * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -1,8 +1,7 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 500f473f880266d43aaf04a728879085
|
guid: f76a1c2d2c424dd4a9bbb9ddf5f95eb9
|
||||||
NativeFormatImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
mainObjectFileID: 11400000
|
|
||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
assetBundleVariant:
|
assetBundleVariant:
|
||||||
@@ -7,5 +7,12 @@
|
|||||||
"name": "MuHua",
|
"name": "MuHua",
|
||||||
"email": "muhua233@qq.com"
|
"email": "muhua233@qq.com"
|
||||||
},
|
},
|
||||||
"type": "tool"
|
"type": "tool",
|
||||||
|
"samples": [
|
||||||
|
{
|
||||||
|
"displayName": "Example",
|
||||||
|
"description": "An example showing how to use the UITool.",
|
||||||
|
"path": "Samples"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user