增加更新接口
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class UIBannerTip : MonoBehaviour
|
||||||
|
{
|
||||||
|
// Start is called before the first frame update
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update is called once per frame
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: b0bf333809175ae4ebc4469feab46cc7
|
guid: 7279e9c7234eb6645b7b1e172b70919d
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -132,15 +132,13 @@ GameObject:
|
|||||||
m_Component:
|
m_Component:
|
||||||
- component: {fileID: 670296964}
|
- component: {fileID: 670296964}
|
||||||
- component: {fileID: 670296963}
|
- component: {fileID: 670296963}
|
||||||
- component: {fileID: 670296965}
|
|
||||||
- component: {fileID: 670296966}
|
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: "----\u754C\u9762\u6587\u6863----"
|
m_Name: "----\u754C\u9762\u6587\u6863----"
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
m_Icon: {fileID: 0}
|
m_Icon: {fileID: 0}
|
||||||
m_NavMeshLayer: 0
|
m_NavMeshLayer: 0
|
||||||
m_StaticEditorFlags: 0
|
m_StaticEditorFlags: 0
|
||||||
m_IsActive: 0
|
m_IsActive: 1
|
||||||
--- !u!114 &670296963
|
--- !u!114 &670296963
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -155,7 +153,7 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
m_PanelSettings: {fileID: 11400000, guid: 782028a3ae72af7429ad2ecdce684390, type: 2}
|
m_PanelSettings: {fileID: 11400000, guid: 782028a3ae72af7429ad2ecdce684390, type: 2}
|
||||||
m_ParentUI: {fileID: 0}
|
m_ParentUI: {fileID: 0}
|
||||||
sourceAsset: {fileID: 9197481963319205126, guid: 31e24fa07355f6e42841c8f1d0e77e54, type: 3}
|
sourceAsset: {fileID: 9197481963319205126, guid: e4a01fc5cb705fe4c9bedf1d0c5df107, type: 3}
|
||||||
m_SortingOrder: 0
|
m_SortingOrder: 0
|
||||||
--- !u!4 &670296964
|
--- !u!4 &670296964
|
||||||
Transform:
|
Transform:
|
||||||
@@ -173,31 +171,6 @@ Transform:
|
|||||||
- {fileID: 1621578791}
|
- {fileID: 1621578791}
|
||||||
m_Father: {fileID: 0}
|
m_Father: {fileID: 0}
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||||
--- !u!114 &670296965
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 670296962}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: ea89ac05041b5d74582ee9d0add233ac, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
document: {fileID: 670296963}
|
|
||||||
--- !u!114 &670296966
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 670296962}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 3d99eda4d1308724c8374c9e305743bc, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
--- !u!1 &705507993
|
--- !u!1 &705507993
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -426,7 +399,7 @@ MonoBehaviour:
|
|||||||
m_PrefabInstance: {fileID: 0}
|
m_PrefabInstance: {fileID: 0}
|
||||||
m_PrefabAsset: {fileID: 0}
|
m_PrefabAsset: {fileID: 0}
|
||||||
m_GameObject: {fileID: 1439912282}
|
m_GameObject: {fileID: 1439912282}
|
||||||
m_Enabled: 1
|
m_Enabled: 0
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 3ce4cafcd40fff3428928289fa060de4, type: 3}
|
m_Script: {fileID: 11500000, guid: 3ce4cafcd40fff3428928289fa060de4, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
@@ -545,72 +518,9 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
document: {fileID: 670296963}
|
document: {fileID: 670296963}
|
||||||
SlideButtonTemplate: {fileID: 9197481963319205126, guid: 9452bd34d4b5bff4084d975753638b86, type: 3}
|
SlideButtonTemplate: {fileID: 9197481963319205126, guid: 9452bd34d4b5bff4084d975753638b86, type: 3}
|
||||||
--- !u!1 &1769112986
|
|
||||||
GameObject:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
serializedVersion: 6
|
|
||||||
m_Component:
|
|
||||||
- component: {fileID: 1769112988}
|
|
||||||
- component: {fileID: 1769112987}
|
|
||||||
- component: {fileID: 1769112989}
|
|
||||||
m_Layer: 5
|
|
||||||
m_Name: UIDocument
|
|
||||||
m_TagString: Untagged
|
|
||||||
m_Icon: {fileID: 0}
|
|
||||||
m_NavMeshLayer: 0
|
|
||||||
m_StaticEditorFlags: 0
|
|
||||||
m_IsActive: 0
|
|
||||||
--- !u!114 &1769112987
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1769112986}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
m_PanelSettings: {fileID: 11400000, guid: 782028a3ae72af7429ad2ecdce684390, type: 2}
|
|
||||||
m_ParentUI: {fileID: 0}
|
|
||||||
sourceAsset: {fileID: 9197481963319205126, guid: 5b53b711220b25a4e9a9896bd5dfad93, type: 3}
|
|
||||||
m_SortingOrder: 0
|
|
||||||
--- !u!4 &1769112988
|
|
||||||
Transform:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1769112986}
|
|
||||||
serializedVersion: 2
|
|
||||||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
|
|
||||||
m_LocalPosition: {x: 0, y: 0, z: 0}
|
|
||||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
|
||||||
m_ConstrainProportionsScale: 0
|
|
||||||
m_Children: []
|
|
||||||
m_Father: {fileID: 0}
|
|
||||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
|
||||||
--- !u!114 &1769112989
|
|
||||||
MonoBehaviour:
|
|
||||||
m_ObjectHideFlags: 0
|
|
||||||
m_CorrespondingSourceObject: {fileID: 0}
|
|
||||||
m_PrefabInstance: {fileID: 0}
|
|
||||||
m_PrefabAsset: {fileID: 0}
|
|
||||||
m_GameObject: {fileID: 1769112986}
|
|
||||||
m_Enabled: 1
|
|
||||||
m_EditorHideFlags: 0
|
|
||||||
m_Script: {fileID: 11500000, guid: 13b55fb0978ba0740b207fa9fc1c91bf, type: 3}
|
|
||||||
m_Name:
|
|
||||||
m_EditorClassIdentifier:
|
|
||||||
document: {fileID: 1769112987}
|
|
||||||
--- !u!1660057539 &9223372036854775807
|
--- !u!1660057539 &9223372036854775807
|
||||||
SceneRoots:
|
SceneRoots:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
m_Roots:
|
m_Roots:
|
||||||
- {fileID: 1439912283}
|
- {fileID: 1439912283}
|
||||||
- {fileID: 670296964}
|
- {fileID: 670296964}
|
||||||
- {fileID: 1769112988}
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
<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">
|
||||||
<ui:Template name="LoginPage" src="project://database/Assets/UI%20Toolkit/GamePage/LoginPage/LoginPage.uxml?fileID=9197481963319205126&guid=7ebceaef0e3991040bf96648c85589a4&type=3#LoginPage" />
|
<ui:Template name="LoginPage" src="project://database/Assets/UI%20Toolkit/GamePage/LoginPage/LoginPage.uxml?fileID=9197481963319205126&guid=7ebceaef0e3991040bf96648c85589a4&type=3#LoginPage" />
|
||||||
|
<ui:Template name="BannerTip" src="project://database/Assets/UI%20Toolkit/GamePopup/BannerTip/BannerTip.uxml?fileID=9197481963319205126&guid=e4a01fc5cb705fe4c9bedf1d0c5df107&type=3#BannerTip" />
|
||||||
<Style src="project://database/Assets/UI%20Toolkit/Document/Document.uss?fileID=7433441132597879392&guid=9205939af30a4394f8f2e34232b27890&type=3#Document" />
|
<Style src="project://database/Assets/UI%20Toolkit/Document/Document.uss?fileID=7433441132597879392&guid=9205939af30a4394f8f2e34232b27890&type=3#Document" />
|
||||||
<ui:Instance template="LoginPage" name="LoginPage" class="document-page" />
|
<ui:Instance template="LoginPage" name="LoginPage" class="document-page document-page-hide" />
|
||||||
|
<ui:VisualElement name="Window" picking-mode="Ignore" class="document-page" style="flex-grow: 1;" />
|
||||||
|
<ui:VisualElement name="Popup" picking-mode="Ignore" class="document-page" style="flex-grow: 1;">
|
||||||
|
<ui:Instance template="BannerTip" name="BannerTip" class="document-page document-page-hide" />
|
||||||
|
</ui:VisualElement>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 59a1ea9b07342d04f9b0d4fc62fd24fc
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
.banner {
|
||||||
|
height: 300px;
|
||||||
|
background-color: rgb(40, 137, 255);
|
||||||
|
transition-duration: 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-d {
|
||||||
|
scale: 1 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-label {
|
||||||
|
flex-grow: 1;
|
||||||
|
color: rgb(255, 255, 255);
|
||||||
|
-unity-text-align: middle-center;
|
||||||
|
margin-top: 0;
|
||||||
|
margin-right: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
|
margin-left: 0;
|
||||||
|
padding-top: 0;
|
||||||
|
padding-right: 0;
|
||||||
|
padding-bottom: 0;
|
||||||
|
padding-left: 0;
|
||||||
|
font-size: 60px;
|
||||||
|
transition-duration: 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.banner-label-d {
|
||||||
|
scale: 0 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 75986de11cb02ce479624ef7b29e3193
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
disableValidation: 0
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
<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/UI%20Toolkit/GamePopup/BannerTip/BannerTip.uss?fileID=7433441132597879392&guid=75986de11cb02ce479624ef7b29e3193&type=3#BannerTip" />
|
||||||
|
<ui:VisualElement name="Background" style="flex-grow: 1; align-items: stretch; justify-content: space-around; background-color: rgba(0, 0, 0, 0.3);">
|
||||||
|
<ui:VisualElement name="Banner" class="banner">
|
||||||
|
<ui:Label tabindex="-1" text="LabelLabelLabelLabelLabelLabel" parse-escape-sequences="true" display-tooltip-when-elided="true" class="banner-label" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:UXML>
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: e4a01fc5cb705fe4c9bedf1d0c5df107
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
@@ -75,7 +75,7 @@
|
|||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
padding-bottom: 0;
|
padding-bottom: 0;
|
||||||
padding-left: 0;
|
padding-left: 0;
|
||||||
background-image: url("project://database/Assets/UI%20Toolkit/Assets/Icon/Close.png?fileID=2800000&guid=69ff0e4b4da18f744844c41e5ca6fe3e&type=3#Close");
|
background-image: url("project://database/Assets/UI%20Toolkit/Assets/Window/Close.png?fileID=2800000&guid=69ff0e4b4da18f744844c41e5ca6fe3e&type=3#Close");
|
||||||
width: 25px;
|
width: 25px;
|
||||||
background-color: rgb(255, 64, 64);
|
background-color: rgb(255, 64, 64);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// UI项容器
|
/// UI项容器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModuleUIItems<TItem, TData> : ModuleUIPanel, IDisposable where TItem : ModuleUIItem<TData> {
|
public class ModuleUIItems<TItem, TData> : ModuleUIPanel where TItem : ModuleUIItem<TData> {
|
||||||
/// <summary> 模板资源 </summary>
|
/// <summary> 模板资源 </summary>
|
||||||
public readonly VisualTreeAsset templateAsset;
|
public readonly VisualTreeAsset templateAsset;
|
||||||
/// <summary> 生成UI项的函数 </summary>
|
/// <summary> 生成UI项的函数 </summary>
|
||||||
@@ -27,19 +27,19 @@ namespace MuHua {
|
|||||||
this.generate = generate;
|
this.generate = generate;
|
||||||
}
|
}
|
||||||
/// <summary> 释放资源 </summary>
|
/// <summary> 释放资源 </summary>
|
||||||
public void Dispose() {
|
public void Release() {
|
||||||
element.Clear();
|
element.Clear();
|
||||||
Items.ForEach(obj => obj.Dispose());
|
Items.ForEach(obj => obj.Dispose());
|
||||||
Items = new List<TItem>();
|
Items = new List<TItem>();
|
||||||
}
|
}
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
public void Create(List<TData> datas, bool isClear = true) {
|
public void Create(List<TData> datas, bool isClear = true) {
|
||||||
if (isClear) { Dispose(); }
|
if (isClear) { Release(); }
|
||||||
datas.ForEach(Create);
|
datas.ForEach(Create);
|
||||||
}
|
}
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
public void Create(TData data, bool isClear = false) {
|
public void Create(TData data, bool isClear = false) {
|
||||||
if (isClear) { Dispose(); }
|
if (isClear) { Release(); }
|
||||||
Create(data);
|
Create(data);
|
||||||
}
|
}
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using UnityEngine.UIElements;
|
|||||||
|
|
||||||
namespace MuHua {
|
namespace MuHua {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// UI控件
|
/// UI面板
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ModuleUIPanel {
|
public class ModuleUIPanel {
|
||||||
/// <summary> 绑定的元素 </summary>
|
/// <summary> 绑定的元素 </summary>
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace MuHua {
|
||||||
|
/// <summary>
|
||||||
|
/// UI控制接口
|
||||||
|
/// </summary>
|
||||||
|
public interface UIControl {
|
||||||
|
/// <summary> 更新UI状态 </summary>
|
||||||
|
public void Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 0721892edd97c594d80af856cbf293c8
|
guid: b46dec8e6f5bddc49a0a37b501d06229
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -8,7 +8,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下拉框
|
/// 下拉框
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UIDropdown<T> : ModuleUIPanel, IDisposable {
|
public class UIDropdown<T> : ModuleUIPanel, IDisposable, UIControl {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
internal readonly VisualElement canvas;
|
internal readonly VisualElement canvas;
|
||||||
/// <summary> 下拉框容器 </summary>
|
/// <summary> 下拉框容器 </summary>
|
||||||
@@ -59,7 +59,7 @@ namespace MuHua {
|
|||||||
}
|
}
|
||||||
public virtual void Dispose() {
|
public virtual void Dispose() {
|
||||||
canvas.Remove(DropdownContainer);
|
canvas.Remove(DropdownContainer);
|
||||||
DropdownItems.Dispose();
|
DropdownItems.Release();
|
||||||
Input.UnregisterCallback<ClickEvent>(evt => OpenDropdown());
|
Input.UnregisterCallback<ClickEvent>(evt => OpenDropdown());
|
||||||
DropdownContainer.UnregisterCallback<PointerDownEvent>(evt => CloseDropdown());
|
DropdownContainer.UnregisterCallback<PointerDownEvent>(evt => CloseDropdown());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 滚动视图
|
/// 滚动视图
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UIScrollView : ModuleUIPanel, IDisposable {
|
public class UIScrollView : ModuleUIPanel, IDisposable, UIControl {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
public readonly VisualElement canvas;
|
public readonly VisualElement canvas;
|
||||||
/// <summary> 水平滑块 </summary>
|
/// <summary> 水平滑块 </summary>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 滚动视图 - 水平
|
/// 滚动视图 - 水平
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UIScrollViewH : ModuleUIPanel, IDisposable {
|
public class UIScrollViewH : ModuleUIPanel, IDisposable, UIControl {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
public readonly VisualElement canvas;
|
public readonly VisualElement canvas;
|
||||||
/// <summary> 元素方向 </summary>
|
/// <summary> 元素方向 </summary>
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 滚动视图 - 垂直
|
/// 滚动视图 - 垂直
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UIScrollViewV : ModuleUIPanel, IDisposable {
|
public class UIScrollViewV : ModuleUIPanel, IDisposable, UIControl {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
public readonly VisualElement canvas;
|
public readonly VisualElement canvas;
|
||||||
/// <summary> 元素方向 </summary>
|
/// <summary> 元素方向 </summary>
|
||||||
|
|||||||
@@ -22,10 +22,10 @@ namespace MuHua {
|
|||||||
}
|
}
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
Items.Dispose();
|
Items.Release();
|
||||||
}
|
}
|
||||||
/// <summary> 释放资源 </summary>
|
/// <summary> 释放资源 </summary>
|
||||||
public virtual void Release() => Items.Dispose();
|
public virtual void Release() => Items.Release();
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
public virtual void Create(List<Data> datas, bool isClear = true) => Items.Create(datas, isClear);
|
public virtual void Create(List<Data> datas, bool isClear = true) => Items.Create(datas, isClear);
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ namespace MuHua {
|
|||||||
}
|
}
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
Items.Dispose();
|
Items.Release();
|
||||||
}
|
}
|
||||||
/// <summary> 释放资源 </summary>
|
/// <summary> 释放资源 </summary>
|
||||||
public virtual void Release() => Items.Dispose();
|
public virtual void Release() => Items.Release();
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
public virtual void Create(List<Data> datas, bool isClear = true) => Items.Create(datas, isClear);
|
public virtual void Create(List<Data> datas, bool isClear = true) => Items.Create(datas, isClear);
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
|
|||||||
@@ -23,10 +23,10 @@ namespace MuHua {
|
|||||||
}
|
}
|
||||||
public override void Dispose() {
|
public override void Dispose() {
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
Items.Dispose();
|
Items.Release();
|
||||||
}
|
}
|
||||||
/// <summary> 释放资源 </summary>
|
/// <summary> 释放资源 </summary>
|
||||||
public virtual void Release() => Items.Dispose();
|
public virtual void Release() => Items.Release();
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
public virtual void Create(List<Data> datas, bool isClear = true) => Items.Create(datas, isClear);
|
public virtual void Create(List<Data> datas, bool isClear = true) => Items.Create(datas, isClear);
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
|
|||||||
@@ -1,203 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UIElements;
|
|
||||||
|
|
||||||
namespace MuHua {
|
|
||||||
/// <summary>
|
|
||||||
/// 滚动条
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("使用 UIScrollerV 或者 UIScrollerH 替换")]
|
|
||||||
public class UIScroller : ModuleUIPanel {
|
|
||||||
/// <summary> 绑定的画布 </summary>
|
|
||||||
public readonly VisualElement canvas;
|
|
||||||
/// <summary> 元素方向 </summary>
|
|
||||||
public readonly UIDirection direction;
|
|
||||||
/// <summary> 值改变时 </summary>
|
|
||||||
public event Action<float> ValueChanged;
|
|
||||||
|
|
||||||
public float value;
|
|
||||||
public bool isDragger;
|
|
||||||
public float originalPosition;
|
|
||||||
public float pointerPosition;
|
|
||||||
|
|
||||||
public readonly UIScrollerFunc scrollerFunc;
|
|
||||||
|
|
||||||
public VisualElement Dragger => Q<VisualElement>("Dragger");
|
|
||||||
|
|
||||||
public UIScroller(VisualElement element, VisualElement canvas, UIDirection direction = UIDirection.FromLeftToRight) : base(element) {
|
|
||||||
this.canvas = canvas;
|
|
||||||
this.direction = direction;
|
|
||||||
|
|
||||||
if (direction == UIDirection.FromLeftToRight) { scrollerFunc = new FromLeftToRight(this); }
|
|
||||||
if (direction == UIDirection.FromRightToLeft) { scrollerFunc = new FromRightToLeft(this); }
|
|
||||||
if (direction == UIDirection.FromTopToBottom) { scrollerFunc = new FromTopToBottom(this); }
|
|
||||||
if (direction == UIDirection.FromBottomToTop) { scrollerFunc = new FromBottomToTop(this); }
|
|
||||||
|
|
||||||
//设置事件
|
|
||||||
Dragger.RegisterCallback<PointerDownEvent>(DraggerDown);
|
|
||||||
element.RegisterCallback<PointerDownEvent>(ElementDown);
|
|
||||||
|
|
||||||
canvas.RegisterCallback<PointerUpEvent>((evt) => isDragger = false);
|
|
||||||
canvas.RegisterCallback<PointerLeaveEvent>((evt) => isDragger = false);
|
|
||||||
}
|
|
||||||
/// <summary> 拖拽元素 </summary>
|
|
||||||
private void DraggerDown(PointerDownEvent evt) => scrollerFunc.DraggerDown(evt);
|
|
||||||
/// <summary> 按下元素 </summary>
|
|
||||||
private void ElementDown(PointerDownEvent evt) => scrollerFunc.ElementDown(evt);
|
|
||||||
/// <summary> 更新状态 </summary>
|
|
||||||
public void Update() => scrollerFunc.Update();
|
|
||||||
/// <summary> 更新值(0-1) </summary>
|
|
||||||
public void UpdateValue(float value, bool send = true) => scrollerFunc.UpdateValue(value, send);
|
|
||||||
|
|
||||||
public abstract class UIScrollerFunc {
|
|
||||||
public readonly UIScroller scroller;
|
|
||||||
public UIScrollerFunc(UIScroller scroller) => this.scroller = scroller;
|
|
||||||
/// <summary> 拖拽元素 </summary>
|
|
||||||
public abstract void DraggerDown(PointerDownEvent evt);
|
|
||||||
/// <summary> 按下元素 </summary>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 滑块从左到右
|
|
||||||
/// </summary>
|
|
||||||
public class FromLeftToRight : UIScrollerFunc {
|
|
||||||
public FromLeftToRight(UIScroller scroller) : base(scroller) {
|
|
||||||
scroller.element.style.flexDirection = FlexDirection.Row;
|
|
||||||
}
|
|
||||||
public override void DraggerDown(PointerDownEvent evt) {
|
|
||||||
scroller.isDragger = true;
|
|
||||||
scroller.originalPosition = scroller.Dragger.transform.position.x;
|
|
||||||
scroller.pointerPosition = UITool.GetMousePosition().x;
|
|
||||||
}
|
|
||||||
public override void ElementDown(PointerDownEvent evt) {
|
|
||||||
float offset = evt.localPosition.x - scroller.Dragger.resolvedStyle.width * 0.5f;
|
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
|
||||||
float value = Mathf.InverseLerp(0, max, offset);
|
|
||||||
UpdateValue(value);
|
|
||||||
}
|
|
||||||
public override void Update() {
|
|
||||||
if (!scroller.isDragger) { return; }
|
|
||||||
float differ = UITool.GetMousePosition().x - scroller.pointerPosition;
|
|
||||||
float offset = differ + scroller.originalPosition;
|
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
|
||||||
float value = Mathf.InverseLerp(0, max, offset);
|
|
||||||
UpdateValue(value);
|
|
||||||
}
|
|
||||||
public override void UpdateValue(float value, bool send = true) {
|
|
||||||
scroller.value = value;
|
|
||||||
if (send) { scroller.ValueChanged?.Invoke(value); }
|
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
|
||||||
float x = Mathf.Lerp(0, max, value);
|
|
||||||
scroller.Dragger.transform.position = new Vector3(x, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 滑块从右到左
|
|
||||||
/// </summary>
|
|
||||||
public class FromRightToLeft : UIScrollerFunc {
|
|
||||||
public FromRightToLeft(UIScroller scroller) : base(scroller) {
|
|
||||||
scroller.element.style.flexDirection = FlexDirection.RowReverse;
|
|
||||||
}
|
|
||||||
public override void DraggerDown(PointerDownEvent evt) {
|
|
||||||
scroller.isDragger = true;
|
|
||||||
scroller.originalPosition = scroller.Dragger.transform.position.x;
|
|
||||||
scroller.pointerPosition = UITool.GetMousePosition().x;
|
|
||||||
}
|
|
||||||
public override void ElementDown(PointerDownEvent evt) {
|
|
||||||
float offset = evt.localPosition.x - scroller.Dragger.resolvedStyle.width * 0.5f;
|
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
|
||||||
float value = Mathf.InverseLerp(max, 0, offset);
|
|
||||||
UpdateValue(value);
|
|
||||||
}
|
|
||||||
public override void Update() {
|
|
||||||
if (!scroller.isDragger) { return; }
|
|
||||||
float differ = UITool.GetMousePosition().x - scroller.pointerPosition;
|
|
||||||
float offset = differ + scroller.originalPosition;
|
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
|
||||||
float value = Mathf.InverseLerp(max, 0, offset);
|
|
||||||
UpdateValue(value);
|
|
||||||
}
|
|
||||||
public override void UpdateValue(float value, bool send = true) {
|
|
||||||
scroller.value = value;
|
|
||||||
if (send) { scroller.ValueChanged?.Invoke(value); }
|
|
||||||
float max = scroller.element.resolvedStyle.width - scroller.Dragger.resolvedStyle.width;
|
|
||||||
float x = Mathf.Lerp(max, 0, value);
|
|
||||||
scroller.Dragger.transform.position = new Vector3(x, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 滑块从上到下
|
|
||||||
/// </summary>
|
|
||||||
public class FromTopToBottom : UIScrollerFunc {
|
|
||||||
public FromTopToBottom(UIScroller scroller) : base(scroller) {
|
|
||||||
scroller.element.style.flexDirection = FlexDirection.Column;
|
|
||||||
}
|
|
||||||
public override void DraggerDown(PointerDownEvent evt) {
|
|
||||||
scroller.isDragger = true;
|
|
||||||
scroller.originalPosition = scroller.Dragger.transform.position.y;
|
|
||||||
scroller.pointerPosition = Screen.height - UITool.GetMousePosition().y;
|
|
||||||
}
|
|
||||||
public override void ElementDown(PointerDownEvent evt) {
|
|
||||||
float offset = evt.localPosition.y - scroller.Dragger.resolvedStyle.height * 0.5f;
|
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
|
||||||
float value = Mathf.InverseLerp(0, max, offset);
|
|
||||||
UpdateValue(value);
|
|
||||||
}
|
|
||||||
public override void Update() {
|
|
||||||
if (!scroller.isDragger) { return; }
|
|
||||||
float differ = Screen.height - UITool.GetMousePosition().y - scroller.pointerPosition;
|
|
||||||
float offset = differ + scroller.originalPosition;
|
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
|
||||||
float value = Mathf.InverseLerp(0, max, offset);
|
|
||||||
UpdateValue(value);
|
|
||||||
}
|
|
||||||
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(0, max, value);
|
|
||||||
scroller.Dragger.transform.position = new Vector3(0, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 滑块从下到上
|
|
||||||
/// </summary>
|
|
||||||
public class FromBottomToTop : UIScrollerFunc {
|
|
||||||
public FromBottomToTop(UIScroller scroller) : base(scroller) {
|
|
||||||
scroller.element.style.flexDirection = FlexDirection.ColumnReverse;
|
|
||||||
}
|
|
||||||
public override void DraggerDown(PointerDownEvent evt) {
|
|
||||||
scroller.isDragger = true;
|
|
||||||
scroller.originalPosition = scroller.Dragger.transform.position.y;
|
|
||||||
scroller.pointerPosition = Screen.height - UITool.GetMousePosition().y;
|
|
||||||
}
|
|
||||||
public override void ElementDown(PointerDownEvent evt) {
|
|
||||||
float offset = evt.localPosition.y - scroller.Dragger.resolvedStyle.height * 0.5f;
|
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
|
||||||
float value = Mathf.InverseLerp(max, 0, offset);
|
|
||||||
UpdateValue(value);
|
|
||||||
}
|
|
||||||
public override void Update() {
|
|
||||||
if (!scroller.isDragger) { return; }
|
|
||||||
float differ = Screen.height - UITool.GetMousePosition().y - scroller.pointerPosition;
|
|
||||||
float offset = differ + scroller.originalPosition;
|
|
||||||
float max = scroller.element.resolvedStyle.height - scroller.Dragger.resolvedStyle.height;
|
|
||||||
float value = Mathf.InverseLerp(max, 0, offset);
|
|
||||||
UpdateValue(value);
|
|
||||||
}
|
|
||||||
public override void UpdateValue(float value, bool send = true) {
|
|
||||||
scroller.value = value;
|
|
||||||
if (send) { scroller.ValueChanged?.Invoke(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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 滚动条 - 水平
|
/// 滚动条 - 水平
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UIScrollerH : ModuleUIPanel, IDisposable {
|
public class UIScrollerH : ModuleUIPanel, IDisposable, UIControl {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
public readonly VisualElement canvas;
|
public readonly VisualElement canvas;
|
||||||
/// <summary> 元素方向 </summary>
|
/// <summary> 元素方向 </summary>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 滚动条 - 垂直
|
/// 滚动条 - 垂直
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UIScrollerV : ModuleUIPanel, IDisposable {
|
public class UIScrollerV : ModuleUIPanel, IDisposable, UIControl {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
public readonly VisualElement canvas;
|
public readonly VisualElement canvas;
|
||||||
/// <summary> 元素方向 </summary>
|
/// <summary> 元素方向 </summary>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 滑动按钮
|
/// 滑动按钮
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UISlideButton<TItem, Data> : ModuleUIPanel where TItem : ModuleUIItem<Data> where Data : DataSlideButton {
|
public class UISlideButton<TItem, Data> : ModuleUIPanel, UIControl where TItem : ModuleUIItem<Data> where Data : DataSlideButton {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
public readonly VisualElement canvas;
|
public readonly VisualElement canvas;
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ namespace MuHua {
|
|||||||
ModuleUIItem<Data>.OnSelect += Settings;
|
ModuleUIItem<Data>.OnSelect += Settings;
|
||||||
}
|
}
|
||||||
public virtual void Dispose() {
|
public virtual void Dispose() {
|
||||||
Items.Dispose();
|
Items.Release();
|
||||||
}
|
}
|
||||||
public virtual void Update() {
|
public virtual void Update() {
|
||||||
if (data == null || data.element == null) { return; }
|
if (data == null || data.element == null) { return; }
|
||||||
@@ -55,7 +55,7 @@ namespace MuHua {
|
|||||||
/// <summary> 设置UI项 </summary>
|
/// <summary> 设置UI项 </summary>
|
||||||
public virtual void Settings(Data data) => this.data = data;
|
public virtual void Settings(Data data) => this.data = data;
|
||||||
/// <summary> 释放资源 </summary>
|
/// <summary> 释放资源 </summary>
|
||||||
public virtual void Release() => Items.Dispose();
|
public virtual void Release() => Items.Release();
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
public virtual void Create(List<Data> datas, bool isClear = true) => Items.Create(datas, isClear);
|
public virtual void Create(List<Data> datas, bool isClear = true) => Items.Create(datas, isClear);
|
||||||
/// <summary> 创建UI项 </summary>
|
/// <summary> 创建UI项 </summary>
|
||||||
|
|||||||
@@ -1,180 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UIElements;
|
|
||||||
|
|
||||||
namespace MuHua {
|
|
||||||
/// <summary>
|
|
||||||
/// 滑块
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("使用 UISliderV 或者 UISliderH 替换")]
|
|
||||||
public class UISlider : ModuleUIPanel {
|
|
||||||
/// <summary> 绑定的画布 </summary>
|
|
||||||
public readonly VisualElement canvas;
|
|
||||||
/// <summary> 元素方向 </summary>
|
|
||||||
public readonly UIDirection direction;
|
|
||||||
/// <summary> 值改变时 </summary>
|
|
||||||
public event Action<float> ValueChanged;
|
|
||||||
|
|
||||||
public float value;
|
|
||||||
public bool isDragger;
|
|
||||||
public float originalPosition;
|
|
||||||
public float pointerPosition;
|
|
||||||
|
|
||||||
public readonly UISliderFunc sliderFunc;
|
|
||||||
|
|
||||||
public Label Title => Q<Label>("Title");
|
|
||||||
public VisualElement Container => Q<VisualElement>("Container");
|
|
||||||
public VisualElement Tracker => Q<VisualElement>("Tracker");
|
|
||||||
public VisualElement Dragger => Q<VisualElement>("Dragger");
|
|
||||||
|
|
||||||
public UISlider(VisualElement element, VisualElement canvas, UIDirection direction = UIDirection.FromLeftToRight) : base(element) {
|
|
||||||
this.canvas = canvas;
|
|
||||||
this.direction = direction;
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 滑块 - 水平
|
/// 滑块 - 水平
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UISliderH : ModuleUIPanel, IDisposable {
|
public class UISliderH : ModuleUIPanel, IDisposable, UIControl {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
public readonly VisualElement canvas;
|
public readonly VisualElement canvas;
|
||||||
/// <summary> 元素方向 </summary>
|
/// <summary> 元素方向 </summary>
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 滑块 - 垂直
|
/// 滑块 - 垂直
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class UISliderV : ModuleUIPanel, IDisposable {
|
public class UISliderV : ModuleUIPanel, IDisposable, UIControl {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
public readonly VisualElement canvas;
|
public readonly VisualElement canvas;
|
||||||
/// <summary> 元素方向 </summary>
|
/// <summary> 元素方向 </summary>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -7,9 +8,11 @@ namespace MuHua {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 悬浮窗口
|
/// 悬浮窗口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class UIWindow : ModuleUIPanel {
|
public abstract class UIWindow : ModuleUIPanel, IDisposable, UIControl {
|
||||||
/// <summary> 绑定的画布 </summary>
|
/// <summary> 绑定的画布 </summary>
|
||||||
public readonly VisualElement canvas;
|
public readonly VisualElement canvas;
|
||||||
|
/// <summary> 隐藏的USS类名 </summary>
|
||||||
|
public string hideClassName = "document-page-hide";
|
||||||
|
|
||||||
private bool isDownMove;
|
private bool isDownMove;
|
||||||
private Vector3 pointerPosition;
|
private Vector3 pointerPosition;
|
||||||
@@ -26,10 +29,16 @@ namespace MuHua {
|
|||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
|
|
||||||
Top.RegisterCallback<PointerDownEvent>(TopDown);
|
Top.RegisterCallback<PointerDownEvent>(TopDown);
|
||||||
canvas.RegisterCallback<PointerUpEvent>((evt) => isDownMove = false);
|
canvas.RegisterCallback<PointerUpEvent>(DraggerUpOrLeave);
|
||||||
canvas.RegisterCallback<PointerLeaveEvent>((evt) => isDownMove = false);
|
canvas.RegisterCallback<PointerLeaveEvent>(DraggerUpOrLeave);
|
||||||
|
Close.RegisterCallback<ClickEvent>(CloseButton);
|
||||||
Close.RegisterCallback<ClickEvent>((evt) => Settings(false));
|
}
|
||||||
|
/// <summary> 解绑事件,防止内存泄漏 </summary>
|
||||||
|
public virtual void Dispose() {
|
||||||
|
Top.UnregisterCallback<PointerDownEvent>(TopDown);
|
||||||
|
canvas.UnregisterCallback<PointerUpEvent>(DraggerUpOrLeave);
|
||||||
|
canvas.UnregisterCallback<PointerLeaveEvent>(DraggerUpOrLeave);
|
||||||
|
Close.UnregisterCallback<ClickEvent>(CloseButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> 按下Top </summary>
|
/// <summary> 按下Top </summary>
|
||||||
@@ -38,10 +47,18 @@ namespace MuHua {
|
|||||||
pointerPosition = UITool.GetMousePosition();
|
pointerPosition = UITool.GetMousePosition();
|
||||||
originalPosition = Window.transform.position;
|
originalPosition = Window.transform.position;
|
||||||
}
|
}
|
||||||
|
/// <summary> 鼠标松开或离开 </summary>
|
||||||
|
private void DraggerUpOrLeave(EventBase evt) {
|
||||||
|
isDownMove = false;
|
||||||
|
}
|
||||||
|
/// <summary> 关闭按钮 </summary>
|
||||||
|
private void CloseButton(EventBase evt) {
|
||||||
|
Settings(false);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> 设置活动状态 </summary>
|
/// <summary> 设置活动状态 </summary>
|
||||||
public virtual void Settings(bool active) {
|
public virtual void Settings(bool active) {
|
||||||
element.style.display = active ? DisplayStyle.Flex : DisplayStyle.None;
|
element.EnableInClassList(hideClassName, !active);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> 更新状态 </summary>
|
/// <summary> 更新状态 </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user