合并代码

This commit is contained in:
MuHua-123
2024-11-15 18:28:21 +08:00
parent 497b43a446
commit 72d1f89b54
274 changed files with 4939 additions and 1968 deletions
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6678239d4b978fa4e986f9992cd24262
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c38e84236dde7c64cbb63ced7e27b9ad
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,30 @@
@import url("unity-theme://default");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/Fonts.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/Dropdown.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/Foldout.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/InputField.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/PopupPrompt.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/PopupWindow.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/ScrollView/ScrollerHorizontal.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/ScrollView/ScrollerVertical.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/ScrollView/ScrollView.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/ScrollView/ScrollViewHorizontal.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/ScrollView/ScrollViewVertical.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/Slider.uss");
@import url("/Packages/com.muhua.uicontrol/Assets/USS/Toggle.uss");
VisualElement {}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4a132c40dbcde0e4b8ee5330aebc6c23
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12388, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fc4572784e24c9145b0ba1215575e82a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,52 @@
.dropdown {
flex-direction: row;
background-color: rgba(255, 255, 255, 0.5);
width: 100%;
height: 30px;
flex-grow: 0;
flex-shrink: 1;
}
.dropdown-label {
flex-grow: 0;
flex-basis: auto;
flex-shrink: 0;
min-width: 150px;
-unity-text-align: middle-left;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 5px;
width: auto;
background-color: rgba(0, 0, 0, 0);
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
}
.dropdown-box {
background-color: rgb(255, 255, 255);
width: auto;
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
flex-direction: row;
padding-top: 0;
padding-right: 7px;
padding-left: 7px;
}
.dropdown-text {
-unity-text-align: middle-left;
height: 100%;
width: 100%;
white-space: nowrap;
text-overflow: ellipsis;
overflow: visible;
}
.dropdown-arrow {
padding-right: 0;
translate: 0 0;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f963dadb562d5884ebe5565d9e95110c
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
+43
View File
@@ -0,0 +1,43 @@
.foldout {
}
.foldout-title {
flex-direction: row;
align-items: center;
}
.foldout-title-image {
background-color: rgb(51, 51, 51);
width: 10px;
height: 10px;
border-top-left-radius: 30px;
border-top-right-radius: 30px;
border-bottom-right-radius: 30px;
border-bottom-left-radius: 30px;
margin-top: 10px;
margin-right: 10px;
margin-bottom: 10px;
margin-left: 10px;
flex-grow: 0;
flex-shrink: 0;
}
.foldout-title-label {
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
height: 30px;
width: 100%;
flex-shrink: 1;
flex-grow: 1;
-unity-text-align: middle-left;
}
.foldout-container {
padding-left: 30px;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: de4110da990ddc747843c5fb483c86e1
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
+2
View File
@@ -0,0 +1,2 @@
.unity-text-element {
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc67c76a4f0792b4ba9b6c17ec7a3658
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,49 @@
.input-field {
flex-direction: row;
background-color: rgba(255, 255, 255, 0.5);
width: 100%;
height: 30px;
flex-grow: 0;
flex-shrink: 1;
}
.input-field-label {
flex-grow: 0;
flex-basis: auto;
flex-shrink: 0;
min-width: 150px;
-unity-text-align: middle-left;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 5px;
width: auto;
background-color: rgba(0, 0, 0, 0);
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
}
.input-field-box {
background-color: rgb(255, 255, 255);
width: auto;
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
}
.input-field-text {
-unity-text-align: middle-left;
height: 100%;
width: 100%;
padding-right: 0;
padding-left: 7px;
white-space: nowrap;
text-overflow: ellipsis;
overflow: visible;
}
.input-field-text-d {
-unity-font-style: italic;
color: rgba(27, 27, 27, 0.6);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03cd515915708e84f84ad5a8ac7f39fc
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,101 @@
.popup-prompt {
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
align-items: center;
justify-content: center;
}
.popup-prompt-background {
width: 300px;
height: 200px;
background-color: rgba(255, 255, 255, 0.5);
border-top-width: 10px;
border-right-width: 10px;
border-bottom-width: 10px;
border-left-width: 10px;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
border-bottom-right-radius: 15px;
border-bottom-left-radius: 15px;
}
.popup-prompt-content {
width: 100%;
height: 70%;
}
.popup-prompt-bottom {
height: 30%;
align-items: center;
align-self: auto;
justify-content: center;
width: 100%;
}
.popup-prompt-label {
scale: 1 1;
-unity-text-align: middle-center;
flex-grow: 1;
border-top-width: 0;
border-right-width: 0;
border-bottom-width: 0;
border-left-width: 0;
border-top-left-radius: 0;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
}
.popup-prompt-button {
width: 80px;
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
height: 30px;
background-color: rgb(0, 181, 255);
border-top-width: 5px;
border-right-width: 5px;
border-bottom-width: 5px;
border-left-width: 5px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
border-left-color: rgba(0, 0, 0, 0);
border-right-color: rgba(0, 0, 0, 0);
border-top-color: rgba(0, 0, 0, 0);
border-bottom-color: rgba(0, 0, 0, 0);
-unity-text-align: middle-center;
}
.popup-prompt-button:hover {
scale: 1.1 1.1;
transition-duration: 0.2s;
background-color: rgb(0, 181, 255);
}
.popup-prompt-button:focus {
border-top-width: 5px;
border-right-width: 5px;
border-bottom-width: 5px;
border-left-width: 5px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
background-color: rgb(0, 181, 255);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7d555d2a2ed2d0042bf8a6aa00bdcfe0
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,95 @@
.popup-window {
background-color: rgba(0, 0, 0, 0.3);
width: 100%;
height: 100%;
align-items: center;
justify-content: center;
}
.popup-window-background {
width: 300px;
height: 400px;
background-color: rgba(255, 255, 255, 0.5);
border-top-width: 10px;
border-right-width: 10px;
border-bottom-width: 10px;
border-left-width: 10px;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
border-bottom-right-radius: 15px;
border-bottom-left-radius: 15px;
}
.popup-window-top {
height: 10%;
}
.popup-window-middle {
height: 80%;
}
.popup-window-bottom {
height: 10%;
align-items: center;
justify-content: center;
}
.popup-window-title {
width: 100%;
height: 100%;
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-center;
font-size: 24px;
}
.popup-window-button {
margin-top: 0;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
border-top-width: 5px;
border-right-width: 5px;
border-bottom-width: 5px;
border-left-width: 5px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
width: 80px;
height: 30px;
border-left-color: rgba(0, 0, 0, 0);
border-right-color: rgba(0, 0, 0, 0);
border-top-color: rgba(0, 0, 0, 0);
border-bottom-color: rgba(0, 0, 0, 0);
background-color: rgb(0, 181, 255);
font-size: 24px;
}
.popup-window-button:hover {
scale: 1.05 1.05;
transition-duration: 0.2s;
background-color: rgb(0, 181, 255);
}
.popup-window-button:focus {
background-color: rgb(0, 181, 255);
border-top-width: 5px;
border-right-width: 5px;
border-bottom-width: 5px;
border-left-width: 5px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 614da9cbef6567f4dbe07797fb050475
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8a21016c3754b4c4f9f339247cc04870
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,24 @@
.scroll-view {
height: 100%;
width: 100%;
flex-direction: row;
}
.scroll-view-viewport {
width: 100%;
height: 100%;
}
.scroll-view-container {
}
.scroll-view-scroller {
height: 100%;
width: 30px;
background-color: rgb(255, 255, 255);
}
.scroll-view-dragger {
background-color: rgb(255, 134, 134);
height: 30px;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03dbe2cf697b06e4c89e88b4d46d76ea
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,30 @@
.horizontal-scroll-view {
width: 100%;
height: 100%;
}
.horizontal-scroll-view-viewport {
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.6);
overflow: hidden;
}
.horizontal-scroll-view-container {
width: 1000px;
height: 100%;
background-color: rgba(0, 0, 0, 0.2);
transition-duration: 0.1s;
}
.horizontal-scroll-view-scroller {
height: 30px;
width: 100%;
background-color: rgb(255, 255, 255);
}
.horizontal-scroll-view-dragger {
width: 30px;
height: 100%;
background-color: rgb(255, 141, 141);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ad929d1cc924d94f8b6bdd74f5986b4
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,32 @@
.vertical-scroll-view {
width: 100%;
height: 100%;
flex-direction: row;
}
.vertical-scroll-view-viewport {
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0.6);
overflow: hidden;
}
.vertical-scroll-view-container {
width: 100%;
height: 1000px;
background-color: rgba(0, 0, 0, 0.2);
flex-shrink: 0;
transition-duration: 0.1s;
}
.vertical-scroll-view-scroller {
width: 30px;
height: 100%;
background-color: rgb(255, 255, 255);
}
.vertical-scroll-view-dragger {
height: 30px;
width: 100%;
background-color: rgb(255, 141, 141);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9fd4c2e9476885e4ea09eec173385ef3
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,11 @@
.horizontal-scroller {
width: 100%;
height: 30px;
background-color: rgb(255, 255, 255);
}
.horizontal-scroller-dragger {
background-color: rgb(255, 126, 126);
width: 30px;
height: 100%;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7feb150ff7e13c94482b3b5c3fc7e0e5
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
@@ -0,0 +1,11 @@
.vertical-scroller {
width: 30px;
height: 100%;
background-color: rgb(255, 255, 255);
}
.vertical-scroller-dragger {
background-color: rgb(255, 126, 126);
width: 100%;
height: 30px;
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7602d968081373c40b29023dfa3593bb
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
+129
View File
@@ -0,0 +1,129 @@
.horizontal-slider {
flex-direction: row;
width: auto;
height: 30px;
flex-grow: 0;
flex-shrink: 1;
align-items: center;
justify-content: space-between;
}
.horizontal-slider-label {
flex-grow: 0;
flex-basis: auto;
flex-shrink: 0;
min-width: 70px;
-unity-text-align: middle-left;
padding-top: 0;
padding-right: 0;
padding-bottom: 0;
padding-left: 0;
width: auto;
background-color: rgba(0, 0, 0, 0);
margin-top: 5px;
margin-right: 5px;
margin-bottom: 5px;
margin-left: 5px;
border-top-width: 0;
border-right-width: 0;
border-bottom-width: 0;
border-left-width: 0;
border-top-left-radius: 0;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
.horizontal-slider-background {
height: 10px;
width: 100%;
margin-left: 10px;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;
padding-right: 0;
padding-left: 0;
background-color: rgb(128, 128, 128);
padding-top: 0;
padding-bottom: 0;
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);
}
.horizontal-slider-container {
height: 100%;
width: auto;
margin-right: 0;
margin-left: 0;
margin-top: 0;
margin-bottom: 0;
}
.horizontal-slider-tracker {
height: 100%;
background-color: rgb(255, 255, 255);
width: 0;
flex-direction: row;
align-items: center;
justify-content: flex-end;
border-top-left-radius: 3px;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
border-bottom-left-radius: 3px;
}
.horizontal-slider-dragger {
width: 16px;
height: 16px;
position: absolute;
background-color: rgb(255, 255, 255);
translate: 8px 0;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
border-bottom-left-radius: 10px;
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);
}
.horizontal-slider-field {
background-color: rgb(255, 255, 255);
width: 40px;
height: 20px;
flex-grow: 0;
flex-shrink: 0;
border-top-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-bottom-left-radius: 5px;
margin-top: 5px;
margin-right: 5px;
margin-bottom: 5px;
margin-left: 5px;
}
.horizontal-slider-field-box {
width: 100%;
height: 100%;
align-items: center;
justify-content: space-around;
}
.horizontal-slider-field-text {
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c161c16266dbad447b027442b9f3d1ae
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
+34
View File
@@ -0,0 +1,34 @@
.toggle {
flex-direction: row;
overflow: hidden;
}
.toggle-checkmark {
width: 24px;
height: 24px;
border-top-width: 1px;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
border-left-color: rgb(100, 100, 100);
border-right-color: rgb(100, 100, 100);
border-top-color: rgb(100, 100, 100);
border-bottom-color: rgb(100, 100, 100);
background-color: rgb(255, 255, 255);
-unity-background-image-tint-color: rgb(65, 65, 65);
margin-top: 3px;
margin-right: 3px;
margin-bottom: 3px;
margin-left: 3px;
}
.toggle-checkmark:hover {
border-left-color: rgb(0, 0, 0);
border-right-color: rgb(0, 0, 0);
border-top-color: rgb(0, 0, 0);
border-bottom-color: rgb(0, 0, 0);
}
.toggle-checkmark-a {
background-color: rgb(147, 147, 147);
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8854406ee13fdba42832b51910d3b251
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d7b7f7b1b1ebc514f98aa5e5423780d3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+80
View File
@@ -0,0 +1,80 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEditor;
using MuHua;
namespace MuHuaEditor.UIControl {
public class CreateUSS : Editor {
public static readonly string USS = "Packages/com.muhua.uicontrol/Assets/USS/";
/// <summary>
/// 创建自定义控件的USS
/// </summary>
/// <param name="ussResourcesPath"></param>
/// <param name="name"></param>
private static void USSCreate(string usspath, string name) {
string selectPath = AssetDatabase.GetAssetPath(Selection.activeObject);
string filePath = $"{selectPath}/{name}.uss";
AssetDatabase.CopyAsset(usspath + ".uss", filePath);
AssetDatabase.Refresh();
Object asset = AssetDatabase.LoadAssetAtPath(filePath, typeof(Object));
Selection.activeObject = asset;
}
[MenuItem("Assets/Create/UI Toolkit/Fonts USS")]
private static void USSFonts() {
USSCreate(USS + "Fonts", "Fonts");
}
[MenuItem("Assets/Create/UI Toolkit/ScrollView/ScrollerHorizontal USS")]
private static void USSScrollerHorizontal() {
USSCreate(USS + "ScrollView/ScrollerHorizontal", "ScrollerHorizontal");
}
[MenuItem("Assets/Create/UI Toolkit/ScrollView/ScrollerVertical USS")]
private static void USSScrollerVertical() {
USSCreate(USS + "ScrollView/ScrollerVertical", "ScrollerVertical");
}
[MenuItem("Assets/Create/UI Toolkit/ScrollView/ScrollView USS")]
private static void USSScrollView() {
USSCreate(USS + "ScrollView/ScrollView", "ScrollView");
}
[MenuItem("Assets/Create/UI Toolkit/ScrollView/ScrollViewHorizontal USS")]
private static void USSScrollViewHorizontal() {
USSCreate(USS + "ScrollView/ScrollViewHorizontal", "ScrollViewHorizontal");
}
[MenuItem("Assets/Create/UI Toolkit/ScrollView/ScrollViewVertical USS")]
private static void USSScrollViewVertical() {
USSCreate(USS + "ScrollView/ScrollViewVertical", "ScrollViewVertical");
}
[MenuItem("Assets/Create/UI Toolkit/Dropdown USS")]
private static void USSDropdown() {
USSCreate(USS + "Dropdown", "Dropdown");
}
[MenuItem("Assets/Create/UI Toolkit/Foldout USS")]
private static void USSFoldout() {
USSCreate(USS + "Foldout", "Foldout");
}
[MenuItem("Assets/Create/UI Toolkit/InputField USS")]
private static void USSInputField() {
USSCreate(USS + "InputField", "InputField");
}
[MenuItem("Assets/Create/UI Toolkit/PopupPrompt USS")]
private static void USSPopupPrompt() {
USSCreate(USS + "PopupPrompt", "PopupPrompt");
}
[MenuItem("Assets/Create/UI Toolkit/PopupWindow USS")]
private static void USSPopupWindow() {
USSCreate(USS + "PopupWindow", "PopupWindow");
}
[MenuItem("Assets/Create/UI Toolkit/Slider USS")]
private static void USSSlider() {
USSCreate(USS + "Slider", "Slider");
}
[MenuItem("Assets/Create/UI Toolkit/Toggle USS")]
private static void USSToggle() {
USSCreate(USS + "Toggle", "Toggle");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 76969ecdaf2dfbb4ebe3158ac878c064
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,18 @@
{
"name": "MuHuaEditor.UIControl",
"rootNamespace": "",
"references": [
"GUID:f2f8bb6405747de46b4fdb1313592dd5"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: d65fad5c0ea42e04d9f1ce8a25a767a0
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9efed5badf2dabb4d80f2f285b50bae0
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 83b14667ab3d30c419e00ca29d617be8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class MUFloatField : FloatField {
public new class UxmlFactory : UxmlFactory<MUFloatField, UxmlTraits> { }
public new class UxmlTraits : FloatField.UxmlTraits { }
public VisualElement inputElement;
public VisualElement textElement;
public MUFloatField() {
ClearClassList();
AddToClassList("input-field");
labelElement.ClearClassList();
labelElement.AddToClassList("unity-text-element");
labelElement.AddToClassList("input-field-label");
inputElement = this.Q<VisualElement>("unity-text-input");
inputElement.ClearClassList();
inputElement.AddToClassList("input-field-box");
textElement = inputElement.Q<VisualElement>("");
textElement.ClearClassList();
textElement.AddToClassList("unity-text-element");
textElement.AddToClassList("input-field-text");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1723fbf2e9a4ff74c8fdbc5388ca21a1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,28 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua{
public class MULongField : LongField {
public new class UxmlFactory : UxmlFactory<MULongField, UxmlTraits> { }
public new class UxmlTraits : LongField.UxmlTraits { }
public MULongField() {
ClearClassList();
AddToClassList("input-field");
labelElement.ClearClassList();
labelElement.AddToClassList("unity-text-element");
labelElement.AddToClassList("input-field-label");
VisualElement inputElement = this.Q<VisualElement>("unity-text-input");
inputElement.ClearClassList();
inputElement.AddToClassList("input-field-box");
VisualElement textElement = inputElement.Q<VisualElement>("");
textElement.ClearClassList();
textElement.AddToClassList("unity-text-element");
textElement.AddToClassList("input-field-text");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e80321332164d2b45b486ad26b5be961
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class MUTextField : TextField {
public new class UxmlFactory : UxmlFactory<MUTextField, UxmlTraits> { }
public new class UxmlTraits : TextField.UxmlTraits {
public UxmlStringAttributeDescription DefaultPrompt = new UxmlStringAttributeDescription {
name = "default-prompt"
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUTextField textField = (MUTextField)ve;
textField.DefaultPrompt = DefaultPrompt.GetValueFromBag(bag, cc);
textField.SetDefaultPrompt();
}
}
public string DefaultPrompt { get; set; }
public VisualElement inputElement => this.Q<VisualElement>("unity-text-input");
public VisualElement textElement => inputElement.Q<VisualElement>("");
public MUTextField() {
ClearClassList();
AddToClassList("input-field");
labelElement.ClearClassList();
labelElement.AddToClassList("unity-text-element");
labelElement.AddToClassList("input-field-label");
inputElement.ClearClassList();
inputElement.AddToClassList("input-field-box");
textElement.ClearClassList();
textElement.AddToClassList("unity-text-element");
textElement.AddToClassList("input-field-text");
RegisterCallback<FocusInEvent>((evt) => { PrepareInput(); });
RegisterCallback<FocusOutEvent>((evt) => { SetDefaultPrompt(); });
}
public void PrepareInput() {
textElement.RemoveFromClassList("input-field-text-d");
if (text != DefaultPrompt) { return; }
text = "";
}
public void SetDefaultPrompt() {
textElement.RemoveFromClassList("input-field-text-d");
if (value != "") { return; }
text = DefaultPrompt;
textElement.AddToClassList("input-field-text-d");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9d99552e73f58694f9dde4009dc6f0fb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+31
View File
@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class MUDropdown : DropdownField {
public new class UxmlFactory : UxmlFactory<MUDropdown, UxmlTraits> { }
public new class UxmlTraits : DropdownField.UxmlTraits { }
public MUDropdown() {
ClearClassList();
AddToClassList("dropdown");
labelElement.ClearClassList();
labelElement.AddToClassList("unity-text-element");
labelElement.AddToClassList("dropdown-label");
VisualElement inputElement = this.Query<VisualElement>(null, "unity-popup-field__input");
inputElement.ClearClassList();
inputElement.AddToClassList("dropdown-box");
VisualElement textElement = this.Query<VisualElement>(null, "unity-base-popup-field__text");
textElement.ClearClassList();
textElement.AddToClassList("unity-text-element");
textElement.AddToClassList("dropdown-text");
VisualElement arrowElement = this.Query<VisualElement>(null, "unity-base-popup-field__arrow");
arrowElement.AddToClassList("dropdown-arrow");
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 17d0169e7671d5442a79e525ee388bd7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+95
View File
@@ -0,0 +1,95 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MuHua {
public class MUFoldout : VisualElement {
public new class UxmlFactory : UxmlFactory<MUFoldout, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
private UxmlStringAttributeDescription Text = new UxmlStringAttributeDescription {
name = "text",
defaultValue = "标题"
};
private UxmlBoolAttributeDescription Active = new UxmlBoolAttributeDescription {
name = "active",
defaultValue = false
};
public UxmlIntAttributeDescription Count = new UxmlIntAttributeDescription {
name = "count"
};
public UxmlStringAttributeDescription AssetPath = new UxmlStringAttributeDescription {
name = "asset-path"
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUFoldout foldout = (MUFoldout)ve;
foldout.Text = Text.GetValueFromBag(bag, cc);
foldout.Active = Active.GetValueFromBag(bag, cc);
foldout.AssetPath = AssetPath.GetValueFromBag(bag, cc);
#if UNITY_EDITOR
VisualTreeAsset asset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(foldout.AssetPath);
if (asset == null) { return; }
foldout.ClearContainer();
int count = Count.GetValueFromBag(bag, cc);
for (int i = 0; i < count; i++) { foldout.AddContainer(asset); }
#endif
}
}
public Label labelElement = new Label();
public VisualElement title = new VisualElement();
public VisualElement image = new VisualElement();
public VisualElement container = new VisualElement();
public string Text {
get => labelElement.text;
set => labelElement.text = value;
}
public bool Active {
get => isActive;
set => SetActive(value);
}
public void AddContainer(VisualTreeAsset asset) {
AddContainer(asset.Instantiate());
}
public void AddContainer(VisualElement element) {
container.Add(element);
}
public void ClearContainer() {
container.Clear();
}
internal bool isActive;
internal string AssetPath { get; set; }
internal void SetActive(bool value) {
isActive = value;
container.style.display = Active ? DisplayStyle.Flex : DisplayStyle.None;
}
public MUFoldout() {
//设置名称
title.name = "title";
image.name = "image";
labelElement.name = "label";
container.name = "container";
//设置USS类名
AddToClassList("foldout");
title.AddToClassList("foldout-title");
image.AddToClassList("foldout-title-image");
labelElement.AddToClassList("foldout-title-label");
container.AddToClassList("foldout-container");
//设置层级结构
hierarchy.Add(title);
hierarchy.Add(container);
title.Add(image);
title.Add(labelElement);
//设置事件
title.RegisterCallback<ClickEvent>((evt) => Active = !Active);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a638c4a7cfde51d4cbc15810d986605c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,186 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class MUSliderHorizontal : VisualElement {
public enum RoundDataType {
= 0,
= 1,
= 2,
}
public new class UxmlFactory : UxmlFactory<MUSliderHorizontal, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
private UxmlStringAttributeDescription Text = new UxmlStringAttributeDescription {
name = "text"
};
private UxmlFloatAttributeDescription MinValue = new UxmlFloatAttributeDescription {
name = "min-value"
};
private UxmlFloatAttributeDescription MaxValue = new UxmlFloatAttributeDescription {
name = "max-value"
};
private UxmlFloatAttributeDescription SlidingValue = new UxmlFloatAttributeDescription {
name = "sliding-value"
};
private UxmlBoolAttributeDescription DisplayInput = new UxmlBoolAttributeDescription {
name = "display-input"
};
private UxmlEnumAttributeDescription<RoundDataType> DataType = new UxmlEnumAttributeDescription<RoundDataType> {
name = "data-type"
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUSliderHorizontal slider = (MUSliderHorizontal)ve;
slider.Text = Text.GetValueFromBag(bag, cc);
slider.MinValue = MinValue.GetValueFromBag(bag, cc);
slider.MaxValue = MaxValue.GetValueFromBag(bag, cc);
slider.SlidingValue = SlidingValue.GetValueFromBag(bag, cc);
slider.DisplayInput = DisplayInput.GetValueFromBag(bag, cc);
slider.DataType = DataType.GetValueFromBag(bag, cc);
}
}
public event Action<float> SlidingValueChanged;
public Label labelElement = new Label();
public MUFloatField floatField = new MUFloatField();
public VisualElement background = new VisualElement();
public VisualElement container = new VisualElement();
public VisualElement tracker = new VisualElement();
public VisualElement dragger = new VisualElement();
public string Text {
get => labelElement.text;
set => UpdateLabelElement(value);
}
public float MinValue {
get => minValue;
set { minValue = value; UpdateFloatField(); }
}
public float MaxValue {
get => maxValue;
set { maxValue = value; UpdateFloatField(); }
}
public float SlidingValue {
get => slidingValue;
set => UpdateSlidingValue(value);
}
public bool DisplayInput {
get => isDisplayInput;
set => UpdateFloatField(value);
}
public RoundDataType DataType {
get => dataType;
set { dataType = value; UpdateFloatField(); }
}
public float Value {
get => UpdateValue();
set => UpdateValue(value);
}
internal float minValue;
internal float maxValue;
internal float slidingValue;
internal bool isDisplayInput;
internal bool isDragger;
internal float mousePosition;
internal float originalPosition;
public RoundDataType dataType;
internal float MaxPosition { get => container.resolvedStyle.width; }
internal float CurrentPosition { get => slidingValue * container.resolvedStyle.width; }
internal void UpdateLabelElement(string value) {
bool display = value != "" && value != null;
labelElement.text = value;
labelElement.style.display = display ? DisplayStyle.Flex : DisplayStyle.None;
}
internal void UpdateSlidingValue(float value) {
UpdateDragger(value);
SlidingValueChanged?.Invoke(Value);
}
internal void UpdateDragger(float value) {
slidingValue = value;
slidingValue = Mathf.Clamp(slidingValue, 0, 1);
tracker.style.width = CurrentPosition;
UpdateFloatField();
}
internal void UpdateFloatField(bool value) {
isDisplayInput = value;
floatField.style.display = isDisplayInput ? DisplayStyle.Flex : DisplayStyle.None;
}
internal void UpdateFloatField() {
floatField.value = Value;
}
internal float UpdateValue() {
float value = (MaxValue - MinValue) * SlidingValue;
if (dataType == RoundDataType.) { value = (float)Math.Round(value, 2); }
if (dataType == RoundDataType.) { value = Mathf.FloorToInt(value); }
return Mathf.Clamp(value, MinValue, MaxValue);
}
internal void UpdateValue(float value) {
slidingValue = value / (MaxValue - MinValue);
slidingValue = Mathf.Clamp(slidingValue, 0, 1);
tracker.style.width = CurrentPosition;
UpdateFloatField();
}
public MUSliderHorizontal() {
//设置名称
labelElement.name = "Label";
floatField.name = "FloatField";
background.name = "Background";
container.name = "Container";
tracker.name = "Tracker";
dragger.name = "Dragger";
//设置USS类名
AddToClassList("horizontal-slider");
labelElement.ClearClassList();
labelElement.AddToClassList("unity-text-element");
labelElement.AddToClassList("horizontal-slider-label");
background.AddToClassList("horizontal-slider-background");
container.AddToClassList("horizontal-slider-container");
tracker.AddToClassList("horizontal-slider-tracker");
dragger.AddToClassList("horizontal-slider-dragger");
floatField.ClearClassList();
floatField.AddToClassList("horizontal-slider-field");
floatField.inputElement.ClearClassList();
floatField.inputElement.AddToClassList("horizontal-slider-field-box");
floatField.textElement.ClearClassList();
floatField.textElement.AddToClassList("unity-text-element");
floatField.textElement.AddToClassList("horizontal-slider-field-text");
//设置层级结构
hierarchy.Add(labelElement);
hierarchy.Add(background);
hierarchy.Add(floatField);
background.Add(container);
container.Add(tracker);
tracker.Add(dragger);
//设置事件
dragger.RegisterCallback<PointerDownEvent>(DraggerDown);
dragger.RegisterCallback<PointerMoveEvent>(DraggerDrag);
dragger.RegisterCallback<PointerUpEvent>((evt) => isDragger = false);
dragger.RegisterCallback<PointerLeaveEvent>((evt) => isDragger = false);
container.RegisterCallback<PointerDownEvent>(ContainerDown);
}
private void DraggerDown(PointerDownEvent evt) {
isDragger = true;
mousePosition = evt.position.x;
originalPosition = CurrentPosition;
}
private void DraggerDrag(PointerMoveEvent evt) {
if (!isDragger) { return; }
float offset = evt.position.x - mousePosition;
float value = (originalPosition + offset) / MaxPosition;
UpdateSlidingValue(value);
}
private void ContainerDown(PointerDownEvent evt) {
float value = evt.localPosition.x / MaxPosition;
UpdateSlidingValue(value);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1fd74f9e0c7ede342a809b375fd4175b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+48
View File
@@ -0,0 +1,48 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class MUToggle : VisualElement {
public new class UxmlFactory : UxmlFactory<MUToggle, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
private UxmlBoolAttributeDescription Value = new UxmlBoolAttributeDescription {
name = "Value"
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUToggle toggle = (MUToggle)ve;
toggle.Value = Value.GetValueFromBag(bag, cc);
}
}
public event Action<bool> OnChange;
public VisualElement checkmark = new VisualElement();
/// <summary> 设置值 触发事件 </summary>
public bool Value {
get { return value; }
set { SetValue(value); OnChange?.Invoke(value); }
}
/// <summary> 设置值不会触发事件 </summary>
public void SetValue(bool value) {
this.value = value;
if (value) { checkmark.AddToClassList("toggle-checkmark-a"); }
else { checkmark.RemoveFromClassList("toggle-checkmark-a"); }
}
internal bool value;
public MUToggle() {
//设置名称
checkmark.name = "Checkmark";
//设置USS类名
AddToClassList("toggle");
checkmark.AddToClassList("toggle-checkmark");
//设置层级结构
hierarchy.Add(checkmark);
//设置事件
checkmark.RegisterCallback<ClickEvent>((evt) => Value = !Value);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cb8deac54a479ee4595f01b00b8403f4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,3 @@
{
"name": "MuHua.UIControl"
}
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f2f8bb6405747de46b4fdb1313592dd5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ba211e11f722a6e4d985f60d27b7dfc7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,65 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class MUPopupPrompt : VisualElement {
public new class UxmlFactory : UxmlFactory<MUPopupPrompt, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
public UxmlStringAttributeDescription LabelText = new UxmlStringAttributeDescription {
name = "Label-Text", defaultValue = "弹窗内容"
};
public UxmlStringAttributeDescription ButtonText = new UxmlStringAttributeDescription {
name = "Button-Text", defaultValue = "确认"
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUPopupPrompt popupPrompt = ve as MUPopupPrompt;
popupPrompt.labelText = LabelText.GetValueFromBag(bag, cc);
popupPrompt.buttonText = ButtonText.GetValueFromBag(bag, cc);
}
}
//布局
public VisualElement background = new VisualElement();
public VisualElement content = new VisualElement();
public VisualElement bottom = new VisualElement();
//组件
public Label label = new Label();
public Button button = new Button();
//参数
public Action callback;
public string labelText { get => label.text; set => label.text = value; }
public string buttonText { get => button.text; set => button.text = value; }
public MUPopupPrompt() {
//清除原有样式
label.ClearClassList();
button.ClearClassList();
//设置USS类名
AddToClassList("popup-prompt");
background.AddToClassList("popup-prompt-background");
content.AddToClassList("popup-prompt-content");
bottom.AddToClassList("popup-prompt-bottom");
label.AddToClassList("unity-text-element");
label.AddToClassList("popup-prompt-label");
button.AddToClassList("unity-text-element");
button.AddToClassList("popup-prompt-button");
//设置层级结构
hierarchy.Add(background);
background.Add(content);
background.Add(bottom);
content.Add(label);
bottom.Add(button);
//设置事件
button.RegisterCallback<ClickEvent>((evt) => Close());
}
public void Open(string text, Action action) {
labelText = text; callback = action; visible = true;
}
public void Close() {
callback?.Invoke(); callback = null; visible = false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d03e3806ea383d14f8f2aadeb9c5cd00
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,90 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MuHua {
public class MUPopupWindow : VisualElement {
public new class UxmlFactory : UxmlFactory<MUPopupWindow, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
public UxmlStringAttributeDescription TitleText = new UxmlStringAttributeDescription {
name = "Title-Text", defaultValue = "标题"
};
public UxmlStringAttributeDescription ButtonText = new UxmlStringAttributeDescription {
name = "Button-Text", defaultValue = "确认"
};
public UxmlStringAttributeDescription AssetPath = new UxmlStringAttributeDescription {
name = "Asset-Path"
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUPopupWindow popup = ve as MUPopupWindow;
popup.titleText = TitleText.GetValueFromBag(bag, cc);
popup.buttonText = ButtonText.GetValueFromBag(bag, cc);
popup.assetPath = AssetPath.GetValueFromBag(bag, cc);
#if UNITY_EDITOR
VisualTreeAsset asset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(popup.assetPath);
if (asset != null) { popup.ReplaceContent(asset.Instantiate()); }
else { popup.middle.Clear(); }
#endif
}
}
//布局
public VisualElement background = new VisualElement();
public VisualElement top = new VisualElement();
public VisualElement middle = new VisualElement();
public VisualElement bottom = new VisualElement();
//组件
public Label title = new Label();
public Button button = new Button();
//参数
public Action callback;
public string assetPath { get; set; }
public string titleText { get => title.text; set => title.text = value; }
public string buttonText { get => button.text; set => button.text = value; }
public MUPopupWindow() {
//清除原有样式
title.ClearClassList();
button.ClearClassList();
//设置USS类名
AddToClassList("popup-window");
background.AddToClassList("popup-window-background");
top.AddToClassList("popup-window-top");
middle.AddToClassList("popup-window-middle");
bottom.AddToClassList("popup-window-bottom");
title.AddToClassList("unity-text-element");
title.AddToClassList("popup-window-title");
button.AddToClassList("unity-text-element");
button.AddToClassList("popup-window-button");
//设置层级结构
hierarchy.Add(background);
background.Add(top);
background.Add(middle);
background.Add(bottom);
top.Add(title);
bottom.Add(button);
//设置事件
button.RegisterCallback<ClickEvent>((evt) => Close());
}
public void Open(Action action) {
callback = action;
visible = true;
}
public void Close() {
callback?.Invoke();
callback = null;
visible = false;
}
public void ReplaceContent(VisualElement element) {
middle.Clear();
middle.Add(element);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b9f7a20f4d66c4a42840fbb21226ce48
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8cdf1edce1f3c1047a25a8845aee7f35
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MuHua {
public class MUScrollView : VisualElement {
public new class UxmlFactory : UxmlFactory<MUScrollView, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
}
public VisualElement viewport = new VisualElement();
public VisualElement container = new VisualElement();
public MUScrollView() {
//设置名称
viewport.name = "viewport";
container.name = "container";
//设置USS类名
AddToClassList("scroll-view");
viewport.AddToClassList("scroll-view-viewport");
container.AddToClassList("scroll-view-container");
//设置层级结构
hierarchy.Add(viewport);
viewport.Add(container);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1f44619e724604b47834e3639ffe2947
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,138 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MuHua {
public class MUScrollViewHorizontal : VisualElement {
public new class UxmlFactory : UxmlFactory<MUScrollViewHorizontal, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
private UxmlIntAttributeDescription MouseWheelScrollSize = new UxmlIntAttributeDescription {
name = "mouse-wheel-scroll-size",
defaultValue = 18
};
private UxmlFloatAttributeDescription SlidingValue = new UxmlFloatAttributeDescription {
name = "sliding-value",
defaultValue = 0
};
public UxmlIntAttributeDescription Count = new UxmlIntAttributeDescription {
name = "count"
};
public UxmlStringAttributeDescription AssetPath = new UxmlStringAttributeDescription {
name = "asset-path"
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUScrollViewHorizontal scrollView = (MUScrollViewHorizontal)ve;
scrollView.MouseWheelScrollSize = MouseWheelScrollSize.GetValueFromBag(bag, cc);
scrollView.SlidingValue = SlidingValue.GetValueFromBag(bag, cc);
scrollView.AssetPath = AssetPath.GetValueFromBag(bag, cc);
#if UNITY_EDITOR
VisualTreeAsset asset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(scrollView.AssetPath);
if (asset == null) { return; }
scrollView.ClearContainer();
int count = Count.GetValueFromBag(bag, cc);
for (int i = 0; i < count; i++) { scrollView.AddContainer(asset); }
#endif
scrollView.scroller.MouseWheelScrollSize = scrollView.MouseWheelScrollSize;
scrollView.ContainerRelease();
}
}
public MUScrollerHorizontal scroller = new MUScrollerHorizontal();
public VisualElement viewport = new VisualElement();
public VisualElement container = new VisualElement();
public string AssetPath { get; set; }
public float MouseWheelScrollSize { get; set; }
public float SlidingValue { get; set; }
public void AddContainer(VisualTreeAsset asset) {
AddContainer(asset.Instantiate());
}
public void AddContainer(VisualElement element) {
container.Add(element);
}
public void ClearContainer() {
container.Clear();
}
internal bool isDragger;
internal float mousePosition;
internal float ViewportWidth { get => viewport.resolvedStyle.width; }
internal float ContainerWidth { get => container.resolvedStyle.width; }
internal float MaxPosition { get => ComputeMaxPosition(); }
internal float ComputeMaxPosition() {
float value = ViewportWidth - ContainerWidth;
return value <= 0 ? value : -1;
}
internal void UpdateVisualElement(float value) {
SlidingValue = value;
container.transform.position = new Vector3(MaxPosition * SlidingValue, 0);
scroller.UpdateVisualElement(SlidingValue);
}
public MUScrollViewHorizontal() {
//设置名称
viewport.name = "viewport";
container.name = "container";
//设置USS类名
AddToClassList("horizontal-scroll-view");
viewport.AddToClassList("horizontal-scroll-view-viewport");
container.AddToClassList("horizontal-scroll-view-container");
scroller.ClearClassList();
scroller.AddToClassList("horizontal-scroll-view-scroller");
VisualElement dragger = scroller.dragger;
dragger.ClearClassList();
dragger.AddToClassList("horizontal-scroll-view-dragger");
//设置层级结构
hierarchy.Add(viewport);
hierarchy.Add(scroller);
viewport.Add(container);
//设置事件
scroller.SlidingValueChanged += UpdateVisualElement;
container.RegisterCallback<PointerDownEvent>(ContainerDown);
container.RegisterCallback<PointerMoveEvent>(ContainerDrag);
container.RegisterCallback<PointerUpEvent>((evt) => ContainerRelease());
container.RegisterCallback<PointerLeaveEvent>((evt) => ContainerRelease());
container.RegisterCallback<WheelEvent>(ContainerWheel);
container.generateVisualContent += ContainerGenerateVisualContent;
}
private void ContainerDown(PointerDownEvent evt) {
isDragger = true;
mousePosition = evt.position.x - SlidingValue * MaxPosition;
}
private void ContainerDrag(PointerMoveEvent evt) {
if (!isDragger) { return; }
float offset = evt.position.x - mousePosition;
float value = offset / MaxPosition;
UpdateVisualElement(value);
mousePosition = evt.position.x - SlidingValue * MaxPosition;
}
private void ContainerRelease() {
isDragger = false;
float value = Mathf.Clamp01(SlidingValue);
container.schedule.Execute(() => { UpdateVisualElement(value); }).StartingIn(1);
}
private void ContainerWheel(WheelEvent evt) {
float wheel = Mathf.Clamp(evt.delta.y, -1, 1);
float current = SlidingValue * MaxPosition;
float offset = current - wheel * MouseWheelScrollSize;
float value = offset / MaxPosition;
UpdateVisualElement(value);
ContainerRelease();
}
private void ContainerGenerateVisualContent(MeshGenerationContext mgc) {
float ratio = Mathf.Clamp01(ViewportWidth / ContainerWidth);
scroller.UpdateDragger(ratio);
ContainerRelease();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6d083933c2f0cfa448e7c5a5f22c253c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,139 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MuHua {
public class MUScrollViewVertical : VisualElement {
public new class UxmlFactory : UxmlFactory<MUScrollViewVertical, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
private UxmlIntAttributeDescription MouseWheelScrollSize = new UxmlIntAttributeDescription {
name = "mouse-wheel-scroll-size",
defaultValue = 18
};
private UxmlFloatAttributeDescription SlidingValue = new UxmlFloatAttributeDescription {
name = "sliding-value",
defaultValue = 0
};
public UxmlIntAttributeDescription Count = new UxmlIntAttributeDescription {
name = "count"
};
public UxmlStringAttributeDescription AssetPath = new UxmlStringAttributeDescription {
name = "asset-path"
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUScrollViewVertical scrollView = (MUScrollViewVertical)ve;
scrollView.MouseWheelScrollSize = MouseWheelScrollSize.GetValueFromBag(bag, cc);
scrollView.SlidingValue = SlidingValue.GetValueFromBag(bag, cc);
scrollView.AssetPath = AssetPath.GetValueFromBag(bag, cc);
#if UNITY_EDITOR
VisualTreeAsset asset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(scrollView.AssetPath);
if (asset == null) { return; }
scrollView.ClearContainer();
int count = Count.GetValueFromBag(bag, cc);
for (int i = 0; i < count; i++) { scrollView.AddContainer(asset); }
#endif
scrollView.scroller.MouseWheelScrollSize = scrollView.MouseWheelScrollSize;
scrollView.ContainerRelease();
}
}
public MUScrollerVertical scroller = new MUScrollerVertical();
public VisualElement viewport = new VisualElement();
public VisualElement container = new VisualElement();
public string AssetPath { get; set; }
public float MouseWheelScrollSize { get; set; }
public float SlidingValue { get; set; }
public void AddContainer(VisualTreeAsset asset) {
AddContainer(asset.Instantiate());
}
public void AddContainer(VisualElement element) {
container.Add(element);
}
public void ClearContainer() {
container.Clear();
}
internal bool isDragger;
internal float mousePosition;
internal float ViewportHeight { get => viewport.resolvedStyle.height; }
internal float ContainerHeight { get => container.resolvedStyle.height; }
internal float MaxPosition { get => ComputeMaxPosition(); }
internal float ComputeMaxPosition() {
float value = ViewportHeight - ContainerHeight;
return value <= 0 ? value : -1;
}
internal void UpdateVisualElement(float value) {
SlidingValue = value;
container.transform.position = new Vector3(0, MaxPosition * SlidingValue);
scroller.UpdateVisualElement(SlidingValue);
}
public MUScrollViewVertical() {
//设置名称
viewport.name = "viewport";
container.name = "container";
//设置USS类名
AddToClassList("vertical-scroll-view");
viewport.AddToClassList("vertical-scroll-view-viewport");
container.AddToClassList("vertical-scroll-view-container");
scroller.ClearClassList();
scroller.AddToClassList("vertical-scroll-view-scroller");
VisualElement dragger = scroller.dragger;
dragger.ClearClassList();
dragger.AddToClassList("vertical-scroll-view-dragger");
//设置层级结构
hierarchy.Add(viewport);
hierarchy.Add(scroller);
viewport.Add(container);
//设置事件
scroller.SlidingValueChanged += UpdateVisualElement;
container.RegisterCallback<PointerDownEvent>(ContainerDown);
container.RegisterCallback<PointerMoveEvent>(ContainerDrag);
container.RegisterCallback<PointerUpEvent>((evt) => ContainerRelease());
container.RegisterCallback<PointerLeaveEvent>((evt) => ContainerRelease());
container.RegisterCallback<WheelEvent>(ContainerWheel);
container.generateVisualContent += ContainerGenerateVisualContent;
}
private void ContainerDown(PointerDownEvent evt) {
isDragger = true;
mousePosition = evt.position.y - SlidingValue * MaxPosition;
}
private void ContainerDrag(PointerMoveEvent evt) {
if (!isDragger) { return; }
float offset = evt.position.y - mousePosition;
float value = offset / MaxPosition;
UpdateVisualElement(value);
mousePosition = evt.position.y - SlidingValue * MaxPosition;
}
private void ContainerRelease() {
isDragger = false;
float value = Mathf.Clamp01(SlidingValue);
container.schedule.Execute(() => { UpdateVisualElement(value); }).StartingIn(1);
}
private void ContainerWheel(WheelEvent evt) {
float wheel = Mathf.Clamp(evt.delta.y, -1, 1);
float current = SlidingValue * MaxPosition;
float offset = current - wheel * MouseWheelScrollSize;
float value = offset / MaxPosition;
UpdateVisualElement(value);
ContainerRelease();
}
private void ContainerGenerateVisualContent(MeshGenerationContext mgc) {
float ratio = Mathf.Clamp01(ViewportHeight / ContainerHeight);
scroller.UpdateDragger(ratio);
ContainerRelease();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e8d4926c5a75b394b843a5630d5005f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,105 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class MUScrollerHorizontal : VisualElement {
public new class UxmlFactory : UxmlFactory<MUScrollerHorizontal, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
private UxmlIntAttributeDescription MouseWheelScrollSize = new UxmlIntAttributeDescription {
name = "mouse-wheel-scroll-size",
defaultValue = 18
};
private UxmlFloatAttributeDescription SlidingValue = new UxmlFloatAttributeDescription {
name = "sliding-value",
defaultValue = 0
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUScrollerHorizontal scroller = (MUScrollerHorizontal)ve;
scroller.MouseWheelScrollSize = MouseWheelScrollSize.GetValueFromBag(bag, cc);
scroller.SlidingValue = SlidingValue.GetValueFromBag(bag, cc);
scroller.ElasticRestoration();
}
}
public event Action<float> SlidingValueChanged;
public VisualElement dragger = new VisualElement();
public float MouseWheelScrollSize { get; set; }
public float SlidingValue { get; set; }
internal bool isDragger;
internal float mousePosition;
internal float ViewportWidth { get => resolvedStyle.width; }
internal float ContainerWidth { get => dragger.resolvedStyle.width; }
internal float MaxPosition { get => ComputeMaxPosition(); }
internal float ComputeMaxPosition() {
float value = ViewportWidth - ContainerWidth;
return value >= 0 ? value : -1;
}
internal void UpdateDragger(float ratio) {
dragger.style.width = ratio * resolvedStyle.width;
}
internal void UpdateVisualElement(float value, bool callback = false) {
SlidingValue = Mathf.Clamp(value, 0, 1);
dragger.transform.position = new Vector3(MaxPosition * SlidingValue, 0);
if (callback) { SlidingValueChanged?.Invoke(SlidingValue); }
}
internal void ElasticRestoration() {
dragger.schedule.Execute(() => { UpdateVisualElement(SlidingValue); }).StartingIn(1);
}
public MUScrollerHorizontal() {
//设置名称
dragger.name = "dragger";
//设置USS类名
AddToClassList("horizontal-scroller");
dragger.AddToClassList("horizontal-scroller-dragger");
//设置层级结构
hierarchy.Add(dragger);
//设置事件
dragger.RegisterCallback<PointerDownEvent>(DraggerDown);
dragger.RegisterCallback<PointerMoveEvent>(DraggerDrag);
dragger.generateVisualContent += DraggerGenerateVisualContent;
RegisterCallback<PointerDownEvent>(ScrollerDown);
RegisterCallback<WheelEvent>(ScrollerWheel);
RegisterCallback<PointerUpEvent>((evt) => ScrollerRelease());
RegisterCallback<PointerLeaveEvent>((evt) => ScrollerRelease());
}
private void DraggerDown(PointerDownEvent evt) {
isDragger = true;
mousePosition = evt.position.x - SlidingValue * MaxPosition;
}
private void DraggerDrag(PointerMoveEvent evt) {
if (!isDragger) { return; }
float offset = evt.position.x - mousePosition;
float value = offset / MaxPosition;
UpdateVisualElement(value, true);
mousePosition = evt.position.x - SlidingValue * MaxPosition;
}
private void DraggerGenerateVisualContent(MeshGenerationContext mgc) {
ElasticRestoration();
}
private void ScrollerDown(PointerDownEvent evt) {
float offset = evt.localPosition.x - dragger.resolvedStyle.width * 0.5f;
float value = offset / MaxPosition;
UpdateVisualElement(value, true);
}
private void ScrollerWheel(WheelEvent evt) {
float wheel = Mathf.Clamp(evt.delta.y, -1, 1);
float current = SlidingValue * MaxPosition;
float offset = current + wheel * MouseWheelScrollSize;
float value = offset / MaxPosition;
UpdateVisualElement(value, true);
}
private void ScrollerRelease() {
isDragger = false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e9c31f78aa7665041a4858f2db3b5c07
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,105 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class MUScrollerVertical : VisualElement {
public new class UxmlFactory : UxmlFactory<MUScrollerVertical, UxmlTraits> { }
public new class UxmlTraits : VisualElement.UxmlTraits {
private UxmlIntAttributeDescription MouseWheelScrollSize = new UxmlIntAttributeDescription {
name = "mouse-wheel-scroll-size",
defaultValue = 18
};
private UxmlFloatAttributeDescription SlidingValue = new UxmlFloatAttributeDescription {
name = "sliding-value",
defaultValue = 0
};
public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) {
base.Init(ve, bag, cc);
MUScrollerVertical scroller = (MUScrollerVertical)ve;
scroller.MouseWheelScrollSize = MouseWheelScrollSize.GetValueFromBag(bag, cc);
scroller.SlidingValue = SlidingValue.GetValueFromBag(bag, cc);
scroller.ElasticRestoration();
}
}
public event Action<float> SlidingValueChanged;
public VisualElement dragger = new VisualElement();
public float MouseWheelScrollSize { get; set; }
public float SlidingValue { get; set; }
internal bool isDragger;
internal float mousePosition;
internal float ViewportHeight { get => resolvedStyle.height; }
internal float ContainerHeight { get => dragger.resolvedStyle.height; }
internal float MaxPosition { get => ComputeMaxPosition(); }
internal float ComputeMaxPosition() {
float value = ViewportHeight - ContainerHeight;
return value >= 0 ? value : -1;
}
internal void UpdateDragger(float ratio) {
dragger.style.height = ratio * resolvedStyle.height;
}
internal void UpdateVisualElement(float value, bool callback = false) {
SlidingValue = Mathf.Clamp(value, 0, 1);
dragger.transform.position = new Vector3(0, MaxPosition * SlidingValue);
if (callback) { SlidingValueChanged?.Invoke(SlidingValue); }
}
internal void ElasticRestoration() {
dragger.schedule.Execute(() => { UpdateVisualElement(SlidingValue); }).StartingIn(1);
}
public MUScrollerVertical() {
//设置名称
dragger.name = "dragger";
//设置USS类名
AddToClassList("vertical-scroller");
dragger.AddToClassList("vertical-scroller-dragger");
//设置层级结构
hierarchy.Add(dragger);
//设置事件
dragger.RegisterCallback<PointerDownEvent>(DraggerDown);
dragger.RegisterCallback<PointerMoveEvent>(DraggerDrag);
dragger.generateVisualContent += DraggerGenerateVisualContent;
RegisterCallback<PointerDownEvent>(ScrollerDown);
RegisterCallback<WheelEvent>(ScrollerWheel);
RegisterCallback<PointerUpEvent>((evt) => ScrollerRelease());
RegisterCallback<PointerLeaveEvent>((evt) => ScrollerRelease());
}
private void DraggerDown(PointerDownEvent evt) {
isDragger = true;
mousePosition = evt.position.y - SlidingValue * MaxPosition;
}
private void DraggerDrag(PointerMoveEvent evt) {
if (!isDragger) { return; }
float offset = evt.position.y - mousePosition;
float value = offset / MaxPosition;
UpdateVisualElement(value, true);
mousePosition = evt.position.y - SlidingValue * MaxPosition;
}
private void DraggerGenerateVisualContent(MeshGenerationContext mgc) {
ElasticRestoration();
}
private void ScrollerDown(PointerDownEvent evt) {
float offset = evt.localPosition.y - dragger.resolvedStyle.height * 0.5f;
float value = offset / MaxPosition;
UpdateVisualElement(value, true);
}
private void ScrollerWheel(WheelEvent evt) {
float wheel = Mathf.Clamp(evt.delta.y, -1, 1);
float current = SlidingValue * MaxPosition;
float offset = current + wheel * MouseWheelScrollSize;
float value = offset / MaxPosition;
UpdateVisualElement(value, true);
}
private void ScrollerRelease() {
isDragger = false;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 170e690428c828a4bbfad60ded902e45
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: af81a61bb7f5221428d4d976cff44866
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class UIViewExtend<ViewModel> : MonoBehaviour where ViewModel : UIViewModel {
public ViewModel view;
public virtual VisualElement element => view.Q<VisualElement>();
public T Q<T>(string name = null, string className = null) where T : VisualElement {
return element.Q<T>(name, className);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c3f91d8edeffb1143b3eb547a09cc321
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class UIViewModel : MonoBehaviour {
public UIDocument document;
public VisualElement element => document.rootVisualElement;
public T Q<T>(string name = null, string className = null) where T : VisualElement {
return element.Q<T>(name, className);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f15a2fe11989e884d9294ac8577594a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public class UIViewTemplate<Data> {
public Data value;
public VisualElement element;
public virtual void SetValue(VisualTreeAsset asset, Data value) {
this.value = value;
this.element = asset.Instantiate();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1962450aff64953408148b16dd9ff69f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,30 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
namespace MuHua {
public static class UIViewTool {
public static List<Template> Instantiate<Template, V>(this VisualElement parent, VisualTreeAsset template, V[] list) where Template : UIViewTemplate<V>, new() {
List<Template> templates = new List<Template>();
for (int i = 0; i < list.Length; i++) {
templates.Add(parent.Instantiate<Template, V>(template, list[i]));
}
return templates;
}
public static List<Template> Instantiate<Template, V>(this VisualElement parent, VisualTreeAsset template, List<V> list) where Template : UIViewTemplate<V>, new() {
List<Template> templates = new List<Template>();
for (int i = 0; i < list.Count; i++) {
templates.Add(parent.Instantiate<Template, V>(template, list[i]));
}
return templates;
}
public static Template Instantiate<Template, V>(this VisualElement parent, VisualTreeAsset template, V value) where Template : UIViewTemplate<V>, new() {
Template temp = new Template();
temp.SetValue(template, value);
parent.Add(temp.element);
return temp;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f47b238dc04f6f243b00dd9ab82419bd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+11
View File
@@ -0,0 +1,11 @@
{
"name": "com.muhua.uicontrol",
"version": "0.0.3",
"displayName": "MuHua UIControl",
"description": "\u57fa\u4e8eUI Toolkit\u7684\u81ea\u5b9a\u4e49\u63a7\u4ef6",
"author": {
"name": "MuHua",
"email": "2960208585@qq.com"
},
"type": "tool"
}
+7
View File
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 91f2ffdb42f95d74dab890cd2c0de2ff
PackageManifestImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: