Merge branch 'main' into 快捷菜单
This commit is contained in:
@@ -1,27 +0,0 @@
|
|||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UIElements;
|
|
||||||
|
|
||||||
public class TestEditorWindow : EditorWindow {
|
|
||||||
[SerializeField]
|
|
||||||
private VisualTreeAsset m_VisualTreeAsset = default;
|
|
||||||
|
|
||||||
[MenuItem("Window/MuHua/TestEditorWindow")]
|
|
||||||
public static void ShowExample() {
|
|
||||||
TestEditorWindow wnd = GetWindow<TestEditorWindow>();
|
|
||||||
wnd.titleContent = new GUIContent("TestEditorWindow");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CreateGUI() {
|
|
||||||
// Each editor window contains a root VisualElement object
|
|
||||||
VisualElement root = rootVisualElement;
|
|
||||||
|
|
||||||
// VisualElements objects can contain other VisualElement following a tree hierarchy.
|
|
||||||
VisualElement label = new Label("Hello World! From C#");
|
|
||||||
root.Add(label);
|
|
||||||
|
|
||||||
// Instantiate UXML
|
|
||||||
VisualElement labelFromUXML = m_VisualTreeAsset.Instantiate();
|
|
||||||
root.Add(labelFromUXML);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
<ui:Label tabindex="-1" text="下拉框" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Title" class="dropdown-title" />
|
<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: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: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("project://database/Assets/UI%20Toolkit/DefaultTheme/UnityDefaultRuntimeTheme.tss?fileID=4154780841294389669&guid=05f864e67ee1ecb4bbe67427564d394c&type=3#arrow-down"); -unity-background-image-tint-color: rgb(51, 51, 51);" />
|
<ui:VisualElement name="Icon" class="dropdown-icon" style="background-image: url("project://database/Assets/UI%20Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss?fileID=4154780841294389669&guid=05f864e67ee1ecb4bbe67427564d394c&type=3#arrow-down"); -unity-background-image-tint-color: rgb(51, 51, 51);" />
|
||||||
<ui:VisualElement name="Positioner" class="dropdown-scrollview" />
|
<ui:VisualElement name="Positioner" class="dropdown-scrollview" />
|
||||||
<ui:VisualElement name="DropdownScrollView" class="scrollview dropdown-scrollview dropdown-hide">
|
<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="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;">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
|
<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&guid=1e0657eb9266c804ea6adea1a16c74b2&type=3#Dropdown" />
|
<Style src="project://database/Assets/UI%20Toolkit/Component/Dropdown/Dropdown.uss?fileID=7433441132597879392&guid=1e0657eb9266c804ea6adea1a16c74b2&type=3#Dropdown" />
|
||||||
<ui:Button text="Button" parse-escape-sequences="true" display-tooltip-when-elided="true" class="dropdown-unit">
|
<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("project://database/Assets/UI%20Toolkit/DefaultTheme/UnityDefaultRuntimeTheme.tss?fileID=-6090568113533005507&guid=05f864e67ee1ecb4bbe67427564d394c&type=3#check"); -unity-background-image-tint-color: rgb(51, 51, 51);" />
|
<ui:VisualElement name="Check" class="dropdown-hide" style="width: 20px; height: 20px; background-image: url("project://database/Assets/UI%20Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss?fileID=-6090568113533005507&guid=05f864e67ee1ecb4bbe67427564d394c&type=3#check"); -unity-background-image-tint-color: rgb(51, 51, 51);" />
|
||||||
</ui:Button>
|
</ui:Button>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
flex-grow: 0;
|
flex-grow: 0;
|
||||||
height: 30px;
|
height: 30px;
|
||||||
width: 30px;
|
width: 30px;
|
||||||
background-image: url("project://database/Assets/UI%20Toolkit/DefaultTheme/UnityDefaultRuntimeTheme.tss?fileID=-1087164816274819069&guid=05f864e67ee1ecb4bbe67427564d394c&type=3#arrow-right@2x");
|
background-image: url("project://database/Assets/UI%20Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss?fileID=-1087164816274819069&guid=05f864e67ee1ecb4bbe67427564d394c&type=3#arrow-right@2x");
|
||||||
-unity-background-image-tint-color: rgb(51, 51, 51);
|
-unity-background-image-tint-color: rgb(51, 51, 51);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<ui:VisualElement class="toggle" style="flex-direction: row-reverse;">
|
<ui:VisualElement class="toggle" style="flex-direction: row-reverse;">
|
||||||
<ui:Label tabindex="-1" text="不在提示" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Title" class="toggle-title" style="color: rgb(28, 28, 28); padding-bottom: 5px; padding-top: 3px; padding-right: 3px; padding-left: 3px;" />
|
<ui:Label tabindex="-1" text="不在提示" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Title" class="toggle-title" style="color: rgb(28, 28, 28); padding-bottom: 5px; padding-top: 3px; padding-right: 3px; padding-left: 3px;" />
|
||||||
<ui:VisualElement name="Input" class="toggle-input">
|
<ui:VisualElement name="Input" class="toggle-input">
|
||||||
<ui:VisualElement name="Check" class="toggle-check toggle-check-hide" style="background-image: url("project://database/Assets/UI%20Toolkit/DefaultTheme/UnityDefaultRuntimeTheme.tss?fileID=-6090568113533005507&guid=05f864e67ee1ecb4bbe67427564d394c&type=3#check"); -unity-background-image-tint-color: rgb(51, 51, 51);" />
|
<ui:VisualElement name="Check" class="toggle-check toggle-check-hide" style="background-image: url("project://database/Assets/UI%20Toolkit/UnityThemes/UnityDefaultRuntimeTheme.tss?fileID=-6090568113533005507&guid=05f864e67ee1ecb4bbe67427564d394c&type=3#check"); -unity-background-image-tint-color: rgb(51, 51, 51);" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: ed61f5627e04e114eb2c086ae01dc7b4
|
guid: f59b127d657274c4e9b94a15b801c1a1
|
||||||
folderAsset: yes
|
folderAsset: yes
|
||||||
DefaultImporter:
|
DefaultImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using UnityEditor.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
namespace MuHuaEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// 编辑器
|
||||||
|
/// </summary>
|
||||||
|
public abstract class ModuleUIEditor<T> : Editor where T : Object {
|
||||||
|
/// <summary> UXML 资源 </summary>
|
||||||
|
public VisualTreeAsset VisualTreeAsset = default;
|
||||||
|
|
||||||
|
/// <summary> 选中目标 </summary>
|
||||||
|
protected T value;
|
||||||
|
/// <summary> 绑定文档 </summary>
|
||||||
|
public VisualElement Element = null;
|
||||||
|
/// <summary> 控件列表 </summary>
|
||||||
|
public List<UIControl> controls = new List<UIControl>();
|
||||||
|
|
||||||
|
public virtual void Awake() => value = target as T;
|
||||||
|
|
||||||
|
/// <summary> 在OnEnable中注册 </summary>
|
||||||
|
private void OnEnable() => EditorApplication.update += Update;
|
||||||
|
|
||||||
|
/// <summary> 在OnDisable中注销 </summary>
|
||||||
|
private void OnDisable() => EditorApplication.update -= Update;
|
||||||
|
|
||||||
|
public override VisualElement CreateInspectorGUI() {
|
||||||
|
VisualElement root = new VisualElement();
|
||||||
|
// 1. 添加 Script 字段(只读)
|
||||||
|
var scriptProperty = serializedObject.FindProperty("m_Script");
|
||||||
|
if (scriptProperty != null) {
|
||||||
|
var scriptField = new PropertyField(scriptProperty);
|
||||||
|
scriptField.SetEnabled(false); // 只读
|
||||||
|
root.Add(scriptField);
|
||||||
|
}
|
||||||
|
// 实例化 UXML
|
||||||
|
if (VisualTreeAsset != null) {
|
||||||
|
Element = VisualTreeAsset.Instantiate();
|
||||||
|
root.Add(Element);
|
||||||
|
Initial();
|
||||||
|
}
|
||||||
|
// 如果没设置 UXML,返回默认 Inspector
|
||||||
|
return root ?? new IMGUIContainer(() => DrawDefaultInspector());
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Update() => controls.ForEach(control => control.Update());
|
||||||
|
|
||||||
|
public virtual void OnDestroy() => controls.ForEach(control => control.Dispose());
|
||||||
|
|
||||||
|
/// <summary> 初始化 </summary>
|
||||||
|
public abstract void Initial();
|
||||||
|
|
||||||
|
/// <summary> 添加控件 </summary>
|
||||||
|
public void AddControl(UIControl control) => controls.Add(control);
|
||||||
|
/// <summary> 移除控件 </summary>
|
||||||
|
public void RemoveControl(UIControl control) => controls.Remove(control);
|
||||||
|
/// <summary> 查询UI元素 </summary>
|
||||||
|
public VE Q<VE>(string name = null, string className = null) where VE : VisualElement => Element.Q<VE>(name, className);
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-3
@@ -1,10 +1,9 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: ccbcb6aee5874ac4ba30fcb269d7c7ba
|
guid: a8a211ecbf2acb642a002e2ccac32de4
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
defaultReferences:
|
defaultReferences: []
|
||||||
- m_VisualTreeAsset: {fileID: 9197481963319205126, guid: d23b67a16b48c2243aabe57056dbfbed, type: 3}
|
|
||||||
executionOrder: 0
|
executionOrder: 0
|
||||||
icon: {instanceID: 0}
|
icon: {instanceID: 0}
|
||||||
userData:
|
userData:
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
namespace MuHuaEditor {
|
||||||
|
/// <summary>
|
||||||
|
/// 编辑器窗口
|
||||||
|
/// </summary>
|
||||||
|
public abstract class ModuleUIEditorWindow : EditorWindow {
|
||||||
|
/// <summary> UXML 资源 </summary>
|
||||||
|
public VisualTreeAsset VisualTreeAsset = default;
|
||||||
|
|
||||||
|
/// <summary> 绑定文档 </summary>
|
||||||
|
public VisualElement Element;
|
||||||
|
/// <summary> 控件列表 </summary>
|
||||||
|
public List<UIControl> controls = new List<UIControl>();
|
||||||
|
|
||||||
|
public virtual void CreateGUI() {
|
||||||
|
// Instantiate UXML
|
||||||
|
Element = VisualTreeAsset.Instantiate();
|
||||||
|
Element.style.flexGrow = 1;
|
||||||
|
rootVisualElement.Add(Element);
|
||||||
|
Initial();
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void Update() => controls.ForEach(control => control.Update());
|
||||||
|
|
||||||
|
public virtual void OnDestroy() => controls.ForEach(control => control.Dispose());
|
||||||
|
|
||||||
|
/// <summary> 初始化 </summary>
|
||||||
|
public abstract void Initial();
|
||||||
|
|
||||||
|
/// <summary> 添加控件 </summary>
|
||||||
|
public void AddControl(UIControl control) => controls.Add(control);
|
||||||
|
/// <summary> 移除控件 </summary>
|
||||||
|
public void RemoveControl(UIControl control) => controls.Remove(control);
|
||||||
|
/// <summary> 查询UI元素 </summary>
|
||||||
|
public T Q<T>(string name = null, string className = null) where T : VisualElement => Element.Q<T>(name, className);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7a2fd8030b7392643995372e5c88631f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "ModuleEditor",
|
"name": "MuHuaEditor.UITool",
|
||||||
"rootNamespace": "",
|
"rootNamespace": "",
|
||||||
"references": [
|
"references": [
|
||||||
"GUID:432b70115e987f44abb984cfe7de384f"
|
"GUID:6206345d516a2bb4a821a7ee90e1b5d5"
|
||||||
],
|
],
|
||||||
"includePlatforms": [
|
"includePlatforms": [
|
||||||
"Editor"
|
"Editor"
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 779534da92936794a829f8bf18309372
|
guid: 3a65c91317a32ac438ed8542cf646c2f
|
||||||
AssemblyDefinitionImporter:
|
AssemblyDefinitionImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
userData:
|
userData:
|
||||||
@@ -71,9 +71,16 @@ namespace MuHua {
|
|||||||
}
|
}
|
||||||
/// <summary> 视图滚轮滑动 </summary>
|
/// <summary> 视图滚轮滑动 </summary>
|
||||||
private void ViewportWheel(WheelEvent evt) {
|
private void ViewportWheel(WheelEvent evt) {
|
||||||
float x = Mathf.Clamp(evt.delta.x, -1, 1);
|
float maxWidth = Viewport.resolvedStyle.width - Container.resolvedStyle.width;
|
||||||
float y = Mathf.Clamp(evt.delta.y, -1, 1);
|
float minWidth = Mathf.Min(Viewport.resolvedStyle.width, Container.resolvedStyle.width);
|
||||||
UpdateValue(new Vector2(value.x - x, value.y - y));
|
float x = evt.delta.x * minWidth / maxWidth;
|
||||||
|
|
||||||
|
float maxHeight = Viewport.resolvedStyle.height - Container.resolvedStyle.height;
|
||||||
|
float minHeight = Mathf.Min(Viewport.resolvedStyle.height, Container.resolvedStyle.height);
|
||||||
|
float y = evt.delta.y * minHeight / maxHeight;
|
||||||
|
|
||||||
|
value = value - new Vector2(x, y);
|
||||||
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
/// <summary> 拖拽按下 </summary>
|
/// <summary> 拖拽按下 </summary>
|
||||||
private void DraggerDown(PointerDownEvent evt) {
|
private void DraggerDown(PointerDownEvent evt) {
|
||||||
|
|||||||
@@ -76,8 +76,11 @@ namespace MuHua {
|
|||||||
}
|
}
|
||||||
/// <summary> 滚轮滑动 </summary>
|
/// <summary> 滚轮滑动 </summary>
|
||||||
private void ViewportWheel(WheelEvent evt) {
|
private void ViewportWheel(WheelEvent evt) {
|
||||||
float wheel = Mathf.Clamp(evt.delta.y, -1, 1);
|
float maxHeight = Viewport.resolvedStyle.height - Container.resolvedStyle.height;
|
||||||
UpdateValue(value - wheel);
|
float minHeight = Mathf.Min(Viewport.resolvedStyle.height, Container.resolvedStyle.height);
|
||||||
|
float y = evt.delta.y * minHeight / maxHeight;
|
||||||
|
value = value - y;
|
||||||
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
/// <summary> 拖拽按下 </summary>
|
/// <summary> 拖拽按下 </summary>
|
||||||
private void DraggerDown(PointerDownEvent evt) {
|
private void DraggerDown(PointerDownEvent evt) {
|
||||||
|
|||||||
@@ -76,8 +76,11 @@ namespace MuHua {
|
|||||||
}
|
}
|
||||||
/// <summary> 滚轮滑动 </summary>
|
/// <summary> 滚轮滑动 </summary>
|
||||||
private void ViewportWheel(WheelEvent evt) {
|
private void ViewportWheel(WheelEvent evt) {
|
||||||
float wheel = Mathf.Clamp(evt.delta.y, -1, 1);
|
float maxHeight = Viewport.resolvedStyle.height - Container.resolvedStyle.height;
|
||||||
UpdateValue(value - wheel);
|
float minHeight = Mathf.Min(Viewport.resolvedStyle.height, Container.resolvedStyle.height);
|
||||||
|
float y = evt.delta.y * minHeight / maxHeight;
|
||||||
|
value = value - y;
|
||||||
|
UpdateValue(value);
|
||||||
}
|
}
|
||||||
/// <summary> 拖拽按下 </summary>
|
/// <summary> 拖拽按下 </summary>
|
||||||
private void DraggerDown(PointerDownEvent evt) {
|
private void DraggerDown(PointerDownEvent evt) {
|
||||||
|
|||||||
Reference in New Issue
Block a user