增加UIToggle和UIDropdown

This commit is contained in:
MuHua-123
2025-04-22 15:45:57 +08:00
parent f6d1cd4d87
commit 9a34f2bd18
33 changed files with 755 additions and 32 deletions
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ee662750a93822c408a0c1d04b7bb488
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+14
View File
@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MuHua;
/// <summary>
/// UI模块
/// </summary>
public class ModuleUI : ModuleSingle<ModuleUI> {
protected override void Awake() => NoReplace();
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a3ee54ac782eb1d4a9c8b92a859c3d38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b4d3d9edca07b4c4e9e7128eb34a1511
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,41 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using MuHua;
/// <summary>
/// 测试页面
/// </summary>
public class UITestPage : ModuleUIPage {
public VisualTreeAsset TemplateAsset;
public List<string> list;
private UIToggle toggle;
private UIDropdown<string> dropdown;
private UIScrollView scrollView;
public override VisualElement Element => root;
public VisualElement Toggle => Q<VisualElement>("Toggle");
public VisualElement Dropdown => Q<VisualElement>("Dropdown");
public VisualElement ScrollView => Q<VisualElement>("ScrollView");
private void Awake() {
toggle = new UIToggle(Toggle);
toggle.ValueChanged += (value) => Debug.Log(value);
dropdown = new UIDropdown<string>(Dropdown, root, TemplateAsset);
dropdown.SetValue(list);
dropdown.ValueChanged += (value) => Debug.Log(value);
scrollView = new UIScrollView(ScrollView, root, UIDirection.FromTopToBottom);
}
private void Update() {
dropdown.Update();
scrollView.Update();
}
private void OnDestroy() {
dropdown.Release();
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a47690fe988195040a2e528bb2e8bce6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -228,6 +228,56 @@ MeshFilter:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 218982090}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &321363682
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 321363683}
- component: {fileID: 321363684}
m_Layer: 0
m_Name: UITestPage
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &321363683
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 321363682}
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: 1327183334}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &321363684
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 321363682}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a47690fe988195040a2e528bb2e8bce6, type: 3}
m_Name:
m_EditorClassIdentifier:
document: {fileID: 1327183335}
TemplateAsset: {fileID: 9197481963319205126, guid: f2787443498675b4c80a0bcedd37c0dc, type: 3}
list:
- 111
- 222
- 333
--- !u!1 &495038689
GameObject:
m_ObjectHideFlags: 0
@@ -275,7 +325,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &701611851
Transform:
m_ObjectHideFlags: 0
@@ -426,7 +476,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
m_IsActive: 0
--- !u!4 &851831250
Transform:
m_ObjectHideFlags: 0
@@ -479,8 +529,8 @@ Camera:
m_GameObject: {fileID: 963194225}
m_Enabled: 1
serializedVersion: 2
m_ClearFlags: 1
m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0}
m_ClearFlags: 2
m_BackGroundColor: {r: 0.2, g: 0.2, b: 0.2, a: 0}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
@@ -580,6 +630,68 @@ MonoBehaviour:
m_MipBias: 0
m_VarianceClampScale: 0.9
m_ContrastAdaptiveSharpening: 0
--- !u!1 &1327183333
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1327183334}
- component: {fileID: 1327183335}
- component: {fileID: 1327183336}
m_Layer: 0
m_Name: "----\u754C\u9762\u6A21\u5757----"
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1327183334
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1327183333}
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:
- {fileID: 321363683}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &1327183335
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1327183333}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_PanelSettings: {fileID: 11400000, guid: 4caef6f0e9981084a9e0cbfd447fac06, type: 2}
m_ParentUI: {fileID: 0}
sourceAsset: {fileID: 9197481963319205126, guid: 31e24fa07355f6e42841c8f1d0e77e54, type: 3}
m_SortingOrder: 0
--- !u!114 &1327183336
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1327183333}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a3ee54ac782eb1d4a9c8b92a859c3d38, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1334378334
GameObject:
m_ObjectHideFlags: 0
@@ -771,3 +883,4 @@ SceneRoots:
- {fileID: 701611851}
- {fileID: 495038690}
- {fileID: 851831250}
- {fileID: 1327183334}
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 34cba154d61f21b40b40b8f2f13d76de
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,110 @@
.dropdown {
flex-grow: 0;
flex-direction: row;
height: 40px;
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
padding-left: 5px;
}
.dropdown-title {
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
min-width: 100px;
font-size: 18px;
-unity-text-align: middle-left;
color: rgb(255, 255, 255);
}
.dropdown-input {
flex-grow: 1;
background-color: rgb(229, 229, 229);
flex-direction: row;
align-items: center;
justify-content: space-between;
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
padding-left: 5px;
}
.dropdown-tag {
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
-unity-text-align: middle-left;
}
.dropdown-icon {
width: 20px;
height: 20px;
}
.dropdown-scrollview {
width: auto;
height: auto;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
flex-grow: 1;
position: absolute;
top: 32px;
left: 0;
right: 0;
bottom: auto;
max-height: 100px;
}
.dropdown-container {
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
}
.dropdown-hide {
opacity: 0;
display: none;
}
.dropdown-unit {
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
background-color: rgba(0, 0, 0, 0);
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
padding-left: 5px;
height: 30px;
border-top-width: 0;
border-right-width: 0;
border-bottom-width: 0;
border-left-width: 0;
-unity-text-align: middle-left;
flex-direction: row-reverse;
align-items: center;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
border-bottom-left-radius: 3px;
}
.dropdown-unit:hover {
background-color: rgba(0, 0, 0, 0.2);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e0657eb9266c804ea6adea1a16c74b2
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,29 @@
<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="DropdownTemplate" src="project://database/Assets/UI%20Toolkit/Component/Dropdown/DropdownTemplate.uxml?fileID=9197481963319205126&amp;guid=f2787443498675b4c80a0bcedd37c0dc&amp;type=3#DropdownTemplate" />
<Style src="project://database/Assets/UI%20Toolkit/Component/Dropdown/Dropdown.uss?fileID=7433441132597879392&amp;guid=1e0657eb9266c804ea6adea1a16c74b2&amp;type=3#Dropdown" />
<ui:VisualElement class="dropdown">
<ui:Label tabindex="-1" text="下拉框" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Title" class="dropdown-title" />
<ui:VisualElement name="Input" class="dropdown-input">
<ui:Label tabindex="-1" text="标签" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Tag" class="dropdown-tag" />
<ui:VisualElement name="Icon" class="dropdown-icon" style="background-image: url(&quot;project://database/Assets/UI%20Toolkit/Theme/UnityDefaultRuntimeTheme.tss?fileID=4154780841294389669&amp;guid=59bfacbee7a859f42904b05799bf9437&amp;type=3#arrow-down&quot;); -unity-background-image-tint-color: rgb(51, 51, 51);" />
<ui:VisualElement name="Positioner" class="dropdown-scrollview" />
<ui:VisualElement name="DropdownScrollView" class="scrollview dropdown-scrollview dropdown-hide">
<ui:VisualElement name="Viewport" class="scrollview-viewport" style="margin-right: 0; margin-bottom: 0; margin-top: 0; margin-left: 0; background-color: rgb(255, 255, 255); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">
<ui:VisualElement name="Container" class="scrollview-container" style="width: 100%; height: auto; background-color: rgba(255, 255, 255, 0); padding-top: 0; padding-right: 0; padding-bottom: 0; padding-left: 0;">
<ui:Instance template="DropdownTemplate" name="DropdownTemplate" />
<ui:Instance template="DropdownTemplate" name="DropdownTemplate" />
<ui:Instance template="DropdownTemplate" name="DropdownTemplate" />
<ui:Instance template="DropdownTemplate" name="DropdownTemplate" />
<ui:Instance template="DropdownTemplate" name="DropdownTemplate" />
</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" style="display: none;">
<ui:VisualElement name="Dragger" class="scroller-vertical-dragger scrollview-vertical-scroller-dragger" />
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 58251f1c92414424eb285cc650757918
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
@@ -0,0 +1,6 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<Style src="project://database/Assets/UI%20Toolkit/Component/Dropdown/Dropdown.uss?fileID=7433441132597879392&amp;guid=1e0657eb9266c804ea6adea1a16c74b2&amp;type=3#Dropdown" />
<ui:Button text="Button" parse-escape-sequences="true" display-tooltip-when-elided="true" class="dropdown-unit">
<ui:VisualElement name="Check" class="dropdown-hide" style="width: 20px; height: 20px; background-image: url(&quot;project://database/Assets/UI%20Toolkit/Theme/UnityDefaultRuntimeTheme.tss?fileID=-6090568113533005507&amp;guid=59bfacbee7a859f42904b05799bf9437&amp;type=3#check&quot;); -unity-background-image-tint-color: rgb(51, 51, 51);" />
</ui:Button>
</ui:UXML>
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f2787443498675b4c80a0bcedd37c0dc
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e1a1aec9a6e95db489c4fa0e75fa3eaf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,52 @@
.toggle {
width: auto;
height: 40px;
padding-top: 5px;
padding-right: 5px;
padding-bottom: 5px;
padding-left: 5px;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.toggle-title {
-unity-text-align: middle-left;
font-size: 18px;
color: rgb(255, 255, 255);
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
}
.toggle-input {
width: 20px;
height: 20px;
background-color: rgb(229, 229, 229);
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
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);
}
.toggle-check {
flex-grow: 1;
}
.toggle-check-hide {
display: none;
opacity: 0;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9110c01e0b68bd9429ca5de756897be0
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,9 @@
<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/Component/Toggle/Toggle.uss?fileID=7433441132597879392&amp;guid=9110c01e0b68bd9429ca5de756897be0&amp;type=3#Toggle" />
<ui:VisualElement class="toggle">
<ui:Label tabindex="-1" text="开关" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Title" class="toggle-title" />
<ui:VisualElement name="Input" class="toggle-input">
<ui:VisualElement name="Check" class="toggle-check toggle-check-hide" style="background-image: url(&quot;project://database/Assets/UI%20Toolkit/Theme/UnityDefaultRuntimeTheme.tss?fileID=-6090568113533005507&amp;guid=59bfacbee7a859f42904b05799bf9437&amp;type=3#check&quot;); -unity-background-image-tint-color: rgb(51, 51, 51);" />
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 1fb475832cb8d164fba93f4b38a10155
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 498f074189938e8478e7fdf2a6d482cf
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+14
View File
@@ -0,0 +1,14 @@
.document-page {
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
display: flex;
opacity: 1;
}
.document-page-hide {
display: none;
opacity: 0;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9205939af30a4394f8f2e34232b27890
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,27 @@
<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="Toggle" src="project://database/Assets/UI%20Toolkit/Component/Toggle/Toggle.uxml?fileID=9197481963319205126&amp;guid=1fb475832cb8d164fba93f4b38a10155&amp;type=3#Toggle" />
<ui:Template name="Dropdown" src="project://database/Assets/UI%20Toolkit/Component/Dropdown/Dropdown.uxml?fileID=9197481963319205126&amp;guid=58251f1c92414424eb285cc650757918&amp;type=3#Dropdown" />
<Style src="project://database/Assets/UI%20Toolkit/Document/Document.uss?fileID=7433441132597879392&amp;guid=9205939af30a4394f8f2e34232b27890&amp;type=3#Document" />
<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: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" />
<ui:Toggle label="Toggle" />
<ui:Instance template="Dropdown" name="Dropdown" style="width: 200px;" />
<ui:DropdownField label="Dropdown" />
<ui:TextField picking-mode="Ignore" label="Text Field" value="filler text" />
<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="Dragger" class="scroller-vertical-dragger scrollview-vertical-scroller-dragger" />
</ui:VisualElement>
</ui:VisualElement>
</ui:UXML>
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 31e24fa07355f6e42841c8f1d0e77e54
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
@@ -1,10 +1,12 @@
@import url("unity-theme://default");
@import url("/Assets/UI Toolkit/FontLibrary/Fonts.uss");
@import url("/Assets/UI Toolkit/Component/Dropdown/Dropdown.uss");
@import url("/Assets/UI Toolkit/Component/InputField/InputField.uss");
@import url("/Assets/UI Toolkit/Component/Scroller/Scroller.uss");
@import url("/Assets/UI Toolkit/Component/ScrollView/ScrollView.uss");
@import url("/Assets/UI Toolkit/Component/Slider/Slider.uss");
@import url("/Assets/UI Toolkit/Component/Toggle/Toggle.uss");
@import url("/Assets/UI Toolkit/Component/Window/Window.uss");
@@ -21,4 +23,7 @@
VisualElement {}
@@ -0,0 +1,124 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
/// <summary>
/// 下拉框
/// </summary>
public class UIDropdown<T> : ModuleUIPanel {
/// <summary> 绑定的画布 </summary>
internal readonly VisualElement canvas;
/// <summary> 下拉框容器 </summary>
internal readonly VisualElement DropdownContainer;
/// <summary> 下拉框滚动视图 </summary>
internal readonly VisualElement DropdownScrollView;
/// <summary> 选项模板 </summary>
internal readonly VisualTreeAsset TemplateAsset;
/// <summary> 值改变时 </summary>
public event Action<T> ValueChanged;
public T value;
public List<T> list = new List<T>();
internal UIScrollView scrollView;
internal ModuleUIItems<UIDropdownItem, T> DropdownItems;
/// <summary> 数据操作 </summary
public T this[int index] => list[index];
/// <summary> 总数 </summary
public int Count => list.Count;
internal Label Tag => Q<Label>("Tag");
internal Label Title => Q<Label>("Title");
internal VisualElement Input => Q<VisualElement>("Input");
internal VisualElement Icon => Q<VisualElement>("Icon");
internal VisualElement Positioner => Q<VisualElement>("Positioner");
public UIDropdown(VisualElement element, VisualElement canvas, VisualTreeAsset TemplateAsset) : base(element) {
this.canvas = canvas;
this.TemplateAsset = TemplateAsset;
DropdownContainer = new VisualElement();
DropdownContainer.EnableInClassList("dropdown-container", true);
DropdownContainer.EnableInClassList("dropdown-hide", true);
canvas.Add(DropdownContainer);
DropdownScrollView = Q<VisualElement>("DropdownScrollView");
DropdownScrollView.EnableInClassList("dropdown-hide", false);
DropdownContainer.Add(DropdownScrollView);
scrollView = new UIScrollView(DropdownScrollView, DropdownContainer, UIDirection.FromTopToBottom);
DropdownItems = new ModuleUIItems<UIDropdownItem, T>(scrollView.Container, TemplateAsset,
(data, element) => new UIDropdownItem(data, element, this));
Input.RegisterCallback<ClickEvent>(evt => OpenDropdown());
DropdownContainer.RegisterCallback<PointerDownEvent>(evt => CloseDropdown());
}
public virtual void Release() {
canvas.Remove(DropdownContainer);
DropdownItems.Release();
}
public virtual void Update() {
scrollView.Update();
}
/// <summary> 打开下拉框 </summary>
public void OpenDropdown() {
float width = Positioner.resolvedStyle.width;
Vector2 position = Positioner.worldBound.position;
DropdownScrollView.style.width = width;
DropdownScrollView.style.left = position.x;
DropdownScrollView.style.top = position.y;
DropdownContainer.EnableInClassList("dropdown-hide", false);
DropdownItems.Create(list);
}
/// <summary> 关闭下拉框 </summary>
public void CloseDropdown() {
DropdownContainer.EnableInClassList("dropdown-hide", true);
}
/// <summary> 更新值 </summary>
public void UpdateValue(T value, bool send = true) {
this.value = value;
Tag.text = value.ToString();
if (send) { ValueChanged?.Invoke(value); }
}
/// <summary> 设置值 </summary>
public void SetValue(List<T> list) {
this.list = list;
if (list.Count > 0) { UpdateValue(list[0], false); }
}
#region UI项定义
/// <summary>
/// 设置标题 UI项
/// </summary>
internal class UIDropdownItem : ModuleUIItem<T> {
public readonly UIDropdown<T> parent;
public Button Button => Q<Button>();
public VisualElement Check => Q<VisualElement>("Check");
public UIDropdownItem(T value, VisualElement element, UIDropdown<T> parent) : base(value, element) {
this.parent = parent;
Button.text = value.ToString();
Button.clicked += Select;
Check.EnableInClassList("dropdown-hide", !value.Equals(parent.value));
}
public override void DefaultState() {
Check.EnableInClassList("dropdown-hide", true);
}
public override void SelectState() {
parent.UpdateValue(value);
parent.CloseDropdown();
Check.EnableInClassList("dropdown-hide", false);
}
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 963896b6158778848b262b161abaa3a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -24,21 +24,16 @@ namespace MuHua {
public readonly UIScroller horizontal;
public readonly UIScroller vertical;
public readonly VisualElement Viewport;
public readonly VisualElement Container;
public readonly VisualElement ScrollerHorizontal;
public readonly VisualElement ScrollerVertical;
public VisualElement Viewport => Q<VisualElement>("Viewport");
public VisualElement Container => Q<VisualElement>("Container");
public VisualElement ScrollerHorizontal => Q<VisualElement>("ScrollerHorizontal");
public VisualElement ScrollerVertical => Q<VisualElement>("ScrollerVertical");
public UIScrollView(VisualElement element, VisualElement canvas, UIDirection direction = UIDirection.HorizontalAndVertical,
UIDirection sh = UIDirection.FromLeftToRight, UIDirection sv = UIDirection.FromTopToBottom) : base(element) {
this.canvas = canvas;
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;
if (sh == UIDirection.FromLeftToRight) { horizontal = new UIScroller(ScrollerHorizontal, canvas, sh); }
@@ -23,14 +23,12 @@ namespace MuHua {
public readonly UIScrollerFunc scrollerFunc;
public readonly VisualElement Dragger;
public VisualElement Dragger => Q<VisualElement>("Dragger");
public UIScroller(VisualElement element, VisualElement canvas, UIDirection direction = UIDirection.FromLeftToRight) : base(element) {
this.canvas = canvas;
this.direction = direction;
Dragger = element.Q<VisualElement>("Dragger");
if (direction == UIDirection.FromLeftToRight) { scrollerFunc = new FromLeftToRight(this); }
if (direction == UIDirection.FromRightToLeft) { scrollerFunc = new FromRightToLeft(this); }
if (direction == UIDirection.FromTopToBottom) { scrollerFunc = new FromTopToBottom(this); }
@@ -23,18 +23,14 @@ namespace MuHua {
public readonly UISliderFunc sliderFunc;
public readonly VisualElement Container;
public readonly VisualElement Tracker;
public readonly VisualElement Dragger;
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;
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); }
@@ -0,0 +1,37 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
/// <summary>
/// 开关
/// </summary>
public class UIToggle : ModuleUIPanel {
/// <summary> 值改变时 </summary>
public event Action<bool> ValueChanged;
public bool value;// 当前值
/// <summary> 标题 </summary>
public string title {
get => Title.text;
set => Title.text = value;
}
public Label Title => Q<Label>("Title");
public VisualElement Input => Q<VisualElement>("Input");
public VisualElement Check => Q<VisualElement>("Check");
public UIToggle(VisualElement element) : base(element) {
Input.RegisterCallback<ClickEvent>(evt => UpdateValue(!value));
}
/// <summary> 更新值 </summary>
public void UpdateValue(bool value, bool send = true) {
this.value = value;
Check.EnableInClassList("toggle-check-hide", !value);
if (send) { ValueChanged?.Invoke(value); }
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3d9f9369fdae61a42ba2cc2d4a52b2ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -3,10 +3,6 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
#if ENABLE_INPUT_SYSTEM && UNITY_INPUT_SYSTEM_PACKAGE
using UnityEngine.InputSystem;
#endif
namespace MuHua {
/// <summary>
/// 悬浮窗口
@@ -19,12 +15,12 @@ namespace MuHua {
private Vector3 pointerPosition;
private Vector3 originalPosition;
public VisualElement Window => element.Q<VisualElement>("Window");
public VisualElement Top => element.Q<VisualElement>("Top");
public VisualElement Container => element.Q<VisualElement>("Container");
public VisualElement Window => Q<VisualElement>("Window");
public VisualElement Top => Q<VisualElement>("Top");
public VisualElement Container => Q<VisualElement>("Container");
public Label Title => element.Q<Label>("Title");
public VisualElement Close => element.Q<VisualElement>("Close");
public Label Title => Q<Label>("Title");
public VisualElement Close => Q<VisualElement>("Close");
public UIWindow(VisualElement element, VisualElement canvas) : base(element) {
this.canvas = canvas;