1
This commit is contained in:
@@ -9,7 +9,7 @@ using MuHua;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class InputMenu : InputControl {
|
public class InputMenu : InputControl {
|
||||||
|
|
||||||
private UIMenuPanel menu;
|
// private UIMenuPanel menu;
|
||||||
|
|
||||||
protected override void ModuleInput_OnInputMode(InputMode mode) {
|
protected override void ModuleInput_OnInputMode(InputMode mode) {
|
||||||
// throw new System.NotImplementedException();
|
// throw new System.NotImplementedException();
|
||||||
@@ -19,16 +19,16 @@ public class InputMenu : InputControl {
|
|||||||
/// <summary> 鼠标左键 </summary>
|
/// <summary> 鼠标左键 </summary>
|
||||||
public void OnMouseLeft(InputValue inputValue) {
|
public void OnMouseLeft(InputValue inputValue) {
|
||||||
if (inputValue.isPressed) return;
|
if (inputValue.isPressed) return;
|
||||||
UIShortcutMenu.I.Close();
|
// UIShortcutMenu.I.Close();
|
||||||
}
|
}
|
||||||
/// <summary> 鼠标右键 </summary>
|
/// <summary> 鼠标右键 </summary>
|
||||||
public void OnMouseRight(InputValue inputValue) {
|
public void OnMouseRight(InputValue inputValue) {
|
||||||
UIShortcutMenu.I.Add("测试1/测试11", () => { Debug.Log("测试1/测试11"); });
|
// UIShortcutMenu.I.Add("测试1/测试11", () => { Debug.Log("测试1/测试11"); });
|
||||||
UIShortcutMenu.I.Add("测试1/测试12", () => { Debug.Log("测试1/测试12"); });
|
// UIShortcutMenu.I.Add("测试1/测试12", () => { Debug.Log("测试1/测试12"); });
|
||||||
|
|
||||||
UIShortcutMenu.I.Add("测试2", () => { Debug.Log("测试2"); });
|
// UIShortcutMenu.I.Add("测试2", () => { Debug.Log("测试2"); });
|
||||||
|
|
||||||
UIShortcutMenu.I.Open();
|
// UIShortcutMenu.I.Open();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,169 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.UIElements;
|
|
||||||
using MuHua;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// UI快捷菜单
|
|
||||||
/// </summary>
|
|
||||||
public class UIShortcutMenu : ModuleUISingle<UIShortcutMenu> {
|
|
||||||
/// <summary> 菜单模板 </summary>
|
|
||||||
public VisualTreeAsset menuTreeAsset;
|
|
||||||
/// <summary> 项目模板 </summary>
|
|
||||||
public VisualTreeAsset itemTreeAsset;
|
|
||||||
|
|
||||||
/// <summary> 数据列表 </summary>
|
|
||||||
public List<DataMenuItem> datas = new List<DataMenuItem>();
|
|
||||||
/// <summary> 控件列表 </summary>
|
|
||||||
public static List<UIControl> controls = new List<UIControl>();
|
|
||||||
|
|
||||||
public override VisualElement Element => root.Q<VisualElement>("ShortcutMenu");
|
|
||||||
|
|
||||||
protected override void Awake() => NoReplace(false);
|
|
||||||
|
|
||||||
private void Update() => controls.ForEach(control => control.Update());
|
|
||||||
|
|
||||||
private void OnDestroy() => controls.ForEach(control => control.Dispose());
|
|
||||||
|
|
||||||
/// <summary> 打开菜单 </summary>
|
|
||||||
public void Open() {
|
|
||||||
Close();
|
|
||||||
Vector3 position = UITool.GetMousePosition(Element);
|
|
||||||
UIMenuPanel menuPanel = Create();
|
|
||||||
menuPanel.Settings(position, datas);
|
|
||||||
}
|
|
||||||
/// <summary> 关闭菜单 </summary>
|
|
||||||
public void Close() {
|
|
||||||
controls.ForEach(control => control.Dispose());
|
|
||||||
controls.Clear();
|
|
||||||
Element.Clear();
|
|
||||||
}
|
|
||||||
/// <summary> 创建子菜单 </summary>
|
|
||||||
public UIMenuPanel Create() {
|
|
||||||
// 创建菜单元素
|
|
||||||
VisualElement element = menuTreeAsset.Instantiate();
|
|
||||||
element.EnableInClassList("menu", true);
|
|
||||||
Element.Add(element);
|
|
||||||
UIMenuPanel menuPanel = new UIMenuPanel(element, itemTreeAsset);
|
|
||||||
controls.Add(menuPanel);
|
|
||||||
return menuPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> 添加菜单项(方法) </summary>
|
|
||||||
public void Add(string name, Action callback) {
|
|
||||||
string[] names = name.Split('/');
|
|
||||||
|
|
||||||
List<DataMenuItem> datas = this.datas;
|
|
||||||
for (int i = 0; i < names.Length; i++) {
|
|
||||||
string menu = names[i];
|
|
||||||
DataMenuItem item = datas.Find(obj => obj.name == menu);
|
|
||||||
if (item == null) {
|
|
||||||
item = new DataMenuItem { name = menu };
|
|
||||||
if (i == names.Length - 1) { item.callback = callback; }
|
|
||||||
datas.Add(item);
|
|
||||||
}
|
|
||||||
datas = item.items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary> 移除菜单项 </summary>
|
|
||||||
public void Remove(string name) {
|
|
||||||
string[] names = name.Split('/');
|
|
||||||
List<DataMenuItem> datas = this.datas;
|
|
||||||
DataMenuItem parent = null;
|
|
||||||
DataMenuItem target = null;
|
|
||||||
|
|
||||||
for (int i = 0; i < names.Length; i++) {
|
|
||||||
string menu = names[i];
|
|
||||||
target = datas.Find(obj => obj.name == menu);
|
|
||||||
if (target == null) return; // 未找到,直接返回
|
|
||||||
if (i == names.Length - 1) {
|
|
||||||
// 找到要移除的项
|
|
||||||
datas.Remove(target);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
parent = target;
|
|
||||||
datas = target.items;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// UI快捷菜单面板
|
|
||||||
/// </summary>
|
|
||||||
public class UIMenuPanel : ModuleUIPanel, UIControl {
|
|
||||||
|
|
||||||
public UIMenuPanel menuPanel;
|
|
||||||
public VisualElement submenu;
|
|
||||||
public ModuleUIItems<UIItem, DataMenuItem> items;
|
|
||||||
|
|
||||||
public VisualElement Container => Q<VisualElement>("Container");
|
|
||||||
|
|
||||||
public UIMenuPanel(VisualElement element, VisualTreeAsset templateAsset) : base(element) {
|
|
||||||
items = new ModuleUIItems<UIItem, DataMenuItem>(Container, templateAsset,
|
|
||||||
(data, element) => new UIItem(data, element, this));
|
|
||||||
}
|
|
||||||
public void Update() {
|
|
||||||
// throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
public void Dispose() {
|
|
||||||
items.Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Settings(Vector3 position, List<DataMenuItem> datas) {
|
|
||||||
items.Create(datas);
|
|
||||||
element.transform.position = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> 打开子菜单 </summary>
|
|
||||||
public void Open(VisualElement submenu, List<DataMenuItem> datas) {
|
|
||||||
if (this.submenu == submenu) { return; }
|
|
||||||
// 更新子菜单
|
|
||||||
this.submenu = submenu;
|
|
||||||
if (menuPanel == null) { menuPanel = UIShortcutMenu.I.Create(); }
|
|
||||||
float x = submenu.worldBound.position.x + submenu.resolvedStyle.width;
|
|
||||||
float y = submenu.worldBound.position.y - 5;
|
|
||||||
Vector3 position = new Vector3(x, y, 0);
|
|
||||||
menuPanel.Settings(position, datas);
|
|
||||||
bool isEnable = datas != null && datas.Count > 0;
|
|
||||||
menuPanel.OpenSubmenu(isEnable);
|
|
||||||
}
|
|
||||||
public void OpenSubmenu(bool open) {
|
|
||||||
element.EnableInClassList("menu-hide", !open);
|
|
||||||
menuPanel?.OpenSubmenu(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary> UI项目 </summary>
|
|
||||||
public class UIItem : ModuleUIItem<DataMenuItem> {
|
|
||||||
public readonly UIMenuPanel parent;
|
|
||||||
|
|
||||||
public Label Name => element.Q<Label>("Name");
|
|
||||||
public VisualElement Arrow => element.Q<VisualElement>("Arrow");
|
|
||||||
|
|
||||||
public UIItem(DataMenuItem value, VisualElement element, UIMenuPanel parent) : base(value, element) {
|
|
||||||
this.parent = parent;
|
|
||||||
Name.text = value.name;
|
|
||||||
Arrow.EnableInClassList("menu-arrow-hide", value.items == null || value.items.Count == 0);
|
|
||||||
element.RegisterCallback<MouseDownEvent>(MouseDownEvent);
|
|
||||||
element.RegisterCallback<MouseMoveEvent>(MouseMoveEvent);
|
|
||||||
}
|
|
||||||
private void MouseDownEvent(MouseDownEvent evt) {
|
|
||||||
value.callback?.Invoke();
|
|
||||||
UIShortcutMenu.I.Close();
|
|
||||||
}
|
|
||||||
private void MouseMoveEvent(MouseMoveEvent evt) {
|
|
||||||
parent.Open(element, value.items);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// 菜单项目
|
|
||||||
/// </summary>
|
|
||||||
public class DataMenuItem {
|
|
||||||
/// <summary> 名称 </summary>
|
|
||||||
public string name;
|
|
||||||
/// <summary> 回调 </summary>
|
|
||||||
public Action callback;
|
|
||||||
/// <summary> 子菜单项 </summary>
|
|
||||||
public List<DataMenuItem> items = new List<DataMenuItem>();
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c22eaed15bf06ed44ac6ed66f7a6487c
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: df40a9389111de24a8e95adccd3cb8d3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 398 B |
@@ -0,0 +1,140 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 556aa0a60c7c1b947a80bd5f89e13850
|
||||||
|
TextureImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 13
|
||||||
|
mipmaps:
|
||||||
|
mipMapMode: 0
|
||||||
|
enableMipMap: 0
|
||||||
|
sRGBTexture: 1
|
||||||
|
linearTexture: 0
|
||||||
|
fadeOut: 0
|
||||||
|
borderMipMap: 0
|
||||||
|
mipMapsPreserveCoverage: 0
|
||||||
|
alphaTestReferenceValue: 0.5
|
||||||
|
mipMapFadeDistanceStart: 1
|
||||||
|
mipMapFadeDistanceEnd: 3
|
||||||
|
bumpmap:
|
||||||
|
convertToNormalMap: 0
|
||||||
|
externalNormalMap: 0
|
||||||
|
heightScale: 0.25
|
||||||
|
normalMapFilter: 0
|
||||||
|
flipGreenChannel: 0
|
||||||
|
isReadable: 0
|
||||||
|
streamingMipmaps: 0
|
||||||
|
streamingMipmapsPriority: 0
|
||||||
|
vTOnly: 0
|
||||||
|
ignoreMipmapLimit: 0
|
||||||
|
grayScaleToAlpha: 0
|
||||||
|
generateCubemap: 6
|
||||||
|
cubemapConvolution: 0
|
||||||
|
seamlessCubemap: 0
|
||||||
|
textureFormat: 1
|
||||||
|
maxTextureSize: 2048
|
||||||
|
textureSettings:
|
||||||
|
serializedVersion: 2
|
||||||
|
filterMode: 1
|
||||||
|
aniso: 1
|
||||||
|
mipBias: 0
|
||||||
|
wrapU: 1
|
||||||
|
wrapV: 1
|
||||||
|
wrapW: 0
|
||||||
|
nPOTScale: 0
|
||||||
|
lightmap: 0
|
||||||
|
compressionQuality: 50
|
||||||
|
spriteMode: 1
|
||||||
|
spriteExtrude: 1
|
||||||
|
spriteMeshType: 1
|
||||||
|
alignment: 0
|
||||||
|
spritePivot: {x: 0.5, y: 0.5}
|
||||||
|
spritePixelsToUnits: 100
|
||||||
|
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
|
||||||
|
spriteGenerateFallbackPhysicsShape: 1
|
||||||
|
alphaUsage: 1
|
||||||
|
alphaIsTransparency: 1
|
||||||
|
spriteTessellationDetail: -1
|
||||||
|
textureType: 8
|
||||||
|
textureShape: 1
|
||||||
|
singleChannelComponent: 0
|
||||||
|
flipbookRows: 1
|
||||||
|
flipbookColumns: 1
|
||||||
|
maxTextureSizeSet: 0
|
||||||
|
compressionQualitySet: 0
|
||||||
|
textureFormatSet: 0
|
||||||
|
ignorePngGamma: 0
|
||||||
|
applyGammaDecoding: 0
|
||||||
|
swizzle: 50462976
|
||||||
|
cookieLightType: 0
|
||||||
|
platformSettings:
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: DefaultTexturePlatform
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
ignorePlatformSupport: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: Standalone
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
ignorePlatformSupport: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: WebGL
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
ignorePlatformSupport: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
- serializedVersion: 3
|
||||||
|
buildTarget: Android
|
||||||
|
maxTextureSize: 2048
|
||||||
|
resizeAlgorithm: 0
|
||||||
|
textureFormat: -1
|
||||||
|
textureCompression: 1
|
||||||
|
compressionQuality: 50
|
||||||
|
crunchedCompression: 0
|
||||||
|
allowsAlphaSplitting: 0
|
||||||
|
overridden: 0
|
||||||
|
ignorePlatformSupport: 0
|
||||||
|
androidETC2FallbackOverride: 0
|
||||||
|
forceMaximumCompressionQuality_BC6H_BC7: 0
|
||||||
|
spriteSheet:
|
||||||
|
serializedVersion: 2
|
||||||
|
sprites: []
|
||||||
|
outline: []
|
||||||
|
physicsShape: []
|
||||||
|
bones: []
|
||||||
|
spriteID: 5e97eb03825dee720800000000000000
|
||||||
|
internalID: 0
|
||||||
|
vertices: []
|
||||||
|
indices:
|
||||||
|
edges: []
|
||||||
|
weights: []
|
||||||
|
secondaryTextures: []
|
||||||
|
nameFileIdTable: {}
|
||||||
|
mipmapLimitGroupName:
|
||||||
|
pSDRemoveMatte: 0
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6477bb920cf3e3a4fbaf3e01082e3ae3
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 快捷菜单
|
||||||
|
/// </summary>
|
||||||
|
public class ShortcutMenu : Module<ShortcutMenu> {
|
||||||
|
/// <summary> 数据列表 </summary>
|
||||||
|
public List<ShortcutMenuItem> menuItems = new List<ShortcutMenuItem>();
|
||||||
|
|
||||||
|
/// <summary> 打开菜单 </summary>
|
||||||
|
public void Open() => UIShortcutMenu.I?.Open(UIShortcutMenu.I.MousePosition, menuItems);
|
||||||
|
|
||||||
|
/// <summary> 关闭菜单 </summary>
|
||||||
|
public void Close() => UIShortcutMenu.I?.Close();
|
||||||
|
|
||||||
|
/// <summary> 添加菜单项(1级菜单/2级菜单/3级菜单) </summary>
|
||||||
|
public void Add(string name, Action callback) {
|
||||||
|
string[] names = name.Split('/');
|
||||||
|
ShortcutMenuItem item = Find(names[0], menuItems, true);
|
||||||
|
for (int i = 1; i < names.Length; i++) {
|
||||||
|
item = Find(names[i], item.menuItems, true);
|
||||||
|
}
|
||||||
|
item.callback = callback;
|
||||||
|
}
|
||||||
|
/// <summary> 移除菜单项(???/???/子级菜单) </summary>
|
||||||
|
public void Remove(string name) {
|
||||||
|
string[] names = name.Split('/');
|
||||||
|
List<ShortcutMenuItem> menuItems = this.menuItems;
|
||||||
|
ShortcutMenuItem item = Find(names[0], menuItems, false);
|
||||||
|
for (int i = 1; i < names.Length; i++) {
|
||||||
|
if (item == null) return;
|
||||||
|
menuItems = item.menuItems;
|
||||||
|
item = Find(names[i], menuItems, false);
|
||||||
|
}
|
||||||
|
menuItems.Remove(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> 子项目查找 </summary>
|
||||||
|
private ShortcutMenuItem Find(string menu, List<ShortcutMenuItem> menuItems, bool isCreate) {
|
||||||
|
ShortcutMenuItem item = menuItems.Find(obj => obj.name == menu);
|
||||||
|
if (item != null || !isCreate) { return item; }
|
||||||
|
item = new ShortcutMenuItem { name = menu };
|
||||||
|
menuItems.Add(item);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 422a458e7229d6b4a8fff66af1840238
|
guid: 23732e20aab811a4eba63cc0f810d659
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 菜单项目
|
||||||
|
/// </summary>
|
||||||
|
public class ShortcutMenuItem {
|
||||||
|
/// <summary> 名称 </summary>
|
||||||
|
public string name;
|
||||||
|
/// <summary> 回调 </summary>
|
||||||
|
public Action callback;
|
||||||
|
/// <summary> 子菜单项 </summary>
|
||||||
|
public List<ShortcutMenuItem> menuItems = new List<ShortcutMenuItem>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: fac2916b09800194a8389027d4b54ce8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UI快捷菜单面板
|
||||||
|
/// </summary>
|
||||||
|
public class UIMenuPanel : ModuleUIPanel, UIControl {
|
||||||
|
|
||||||
|
public UIMenuPanel menuPanel;
|
||||||
|
public VisualElement submenu;
|
||||||
|
public ModuleUIItems<UIItem, ShortcutMenuItem> items;
|
||||||
|
|
||||||
|
public VisualElement Container => Q<VisualElement>("Container");
|
||||||
|
|
||||||
|
public UIMenuPanel(VisualElement element, VisualTreeAsset templateAsset) : base(element) {
|
||||||
|
items = new ModuleUIItems<UIItem, ShortcutMenuItem>(Container, templateAsset,
|
||||||
|
(data, element) => new UIItem(data, element, this));
|
||||||
|
}
|
||||||
|
public void Update() {
|
||||||
|
// throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
public void Dispose() {
|
||||||
|
items.Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Settings(Vector3 position, List<ShortcutMenuItem> datas) {
|
||||||
|
items.Create(datas);
|
||||||
|
element.transform.position = position;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> 打开子菜单 </summary>
|
||||||
|
public void Open(VisualElement submenu, List<ShortcutMenuItem> datas) {
|
||||||
|
if (this.submenu == submenu) { return; }
|
||||||
|
// 更新子菜单
|
||||||
|
this.submenu = submenu;
|
||||||
|
if (menuPanel == null) { menuPanel = UIShortcutMenu.I.Create(); }
|
||||||
|
float x = submenu.worldBound.position.x + submenu.resolvedStyle.width;
|
||||||
|
float y = submenu.worldBound.position.y - 4;
|
||||||
|
Vector3 position = new Vector3(x, y, 0);
|
||||||
|
menuPanel.Settings(position, datas);
|
||||||
|
bool isEnable = datas != null && datas.Count > 0;
|
||||||
|
menuPanel.OpenSubmenu(isEnable);
|
||||||
|
}
|
||||||
|
public void OpenSubmenu(bool open) {
|
||||||
|
element.EnableInClassList("menu-hide", !open);
|
||||||
|
menuPanel?.OpenSubmenu(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary> UI项目 </summary>
|
||||||
|
public class UIItem : ModuleUIItem<ShortcutMenuItem> {
|
||||||
|
public readonly UIMenuPanel parent;
|
||||||
|
|
||||||
|
public Label Name => element.Q<Label>("Name");
|
||||||
|
public VisualElement Arrow => element.Q<VisualElement>("Arrow");
|
||||||
|
|
||||||
|
public UIItem(ShortcutMenuItem value, VisualElement element, UIMenuPanel parent) : base(value, element) {
|
||||||
|
this.parent = parent;
|
||||||
|
Name.text = value.name;
|
||||||
|
Arrow.EnableInClassList("menu-arrow-hide", value.menuItems == null || value.menuItems.Count == 0);
|
||||||
|
element.RegisterCallback<MouseDownEvent>(MouseDownEvent);
|
||||||
|
element.RegisterCallback<MouseMoveEvent>(MouseMoveEvent);
|
||||||
|
}
|
||||||
|
private void MouseDownEvent(MouseDownEvent evt) {
|
||||||
|
value.callback?.Invoke();
|
||||||
|
UIShortcutMenu.I.Close();
|
||||||
|
}
|
||||||
|
private void MouseMoveEvent(MouseMoveEvent evt) {
|
||||||
|
parent.Open(element, value.menuItems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cbfff4523d382a14eb835f39d022b39d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using MuHua;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// UI快捷菜单
|
||||||
|
/// </summary>
|
||||||
|
public class UIShortcutMenu : ModuleUISingle<UIShortcutMenu> {
|
||||||
|
/// <summary> 菜单模板 </summary>
|
||||||
|
public VisualTreeAsset MenuPanel;
|
||||||
|
/// <summary> 项目模板 </summary>
|
||||||
|
public VisualTreeAsset MenuTemplate;
|
||||||
|
|
||||||
|
/// <summary> 控件列表 </summary>
|
||||||
|
public static List<UIControl> controls = new List<UIControl>();
|
||||||
|
|
||||||
|
public Vector3 MousePosition => UITool.GetMousePosition(Element);
|
||||||
|
|
||||||
|
public override VisualElement Element => root.Q<VisualElement>("ShortcutMenu");
|
||||||
|
|
||||||
|
protected override void Awake() => NoReplace(false);
|
||||||
|
|
||||||
|
private void Update() => controls.ForEach(control => control.Update());
|
||||||
|
|
||||||
|
private void OnDestroy() => controls.ForEach(control => control.Dispose());
|
||||||
|
|
||||||
|
/// <summary> 打开菜单 </summary>
|
||||||
|
public void Open(Vector3 position, List<ShortcutMenuItem> datas) {
|
||||||
|
Close();
|
||||||
|
UIMenuPanel menuPanel = Create();
|
||||||
|
menuPanel.Settings(position, datas);
|
||||||
|
}
|
||||||
|
/// <summary> 关闭菜单 </summary>
|
||||||
|
public void Close() {
|
||||||
|
controls.ForEach(control => control.Dispose());
|
||||||
|
controls.Clear();
|
||||||
|
Element.Clear();
|
||||||
|
}
|
||||||
|
/// <summary> 创建子菜单 </summary>
|
||||||
|
public UIMenuPanel Create() {
|
||||||
|
// 创建菜单元素
|
||||||
|
VisualElement element = MenuPanel.Instantiate();
|
||||||
|
element.EnableInClassList("menu", true);
|
||||||
|
Element.Add(element);
|
||||||
|
UIMenuPanel menuPanel = new UIMenuPanel(element, MenuTemplate);
|
||||||
|
controls.Add(menuPanel);
|
||||||
|
return menuPanel;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 422a458e7229d6b4a8fff66af1840238
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences:
|
||||||
|
- document: {instanceID: 0}
|
||||||
|
- MenuPanel: {fileID: 9197481963319205126, guid: 5034a86c1b336b644968fdb3be5f851a, type: 3}
|
||||||
|
- MenuTemplate: {fileID: 9197481963319205126, guid: 1ee167986f6e9a840a45450b4b6adfc2, type: 3}
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 32fa60a7591d8e149b02b5fac56adfb4
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f405743ede2617b4c92bf64862e7402e
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
.menu-unit {
|
||||||
|
flex-direction: row;
|
||||||
|
align-self: flex-start;
|
||||||
|
flex-grow: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 25px;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-unit:hover {
|
||||||
|
background-color: rgba(0, 0, 0, 0.2);
|
||||||
|
border-top-left-radius: 5px;
|
||||||
|
border-top-right-radius: 5px;
|
||||||
|
border-bottom-right-radius: 5px;
|
||||||
|
border-bottom-left-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-arrow {
|
||||||
|
flex-grow: 0;
|
||||||
|
height: 20px;
|
||||||
|
width: 25px;
|
||||||
|
background-image: url("project://database/Assets/ModuleCore/ModuleUISMenu/Assets/%E7%AE%AD%E5%A4%B4.png?fileID=2800000&guid=556aa0a60c7c1b947a80bd5f89e13850&type=3#箭头");
|
||||||
|
-unity-background-image-tint-color: rgb(51, 50, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-arrow-hide {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
+3
-2
@@ -1,5 +1,5 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 31e24fa07355f6e42841c8f1d0e77e54
|
guid: 4b1be5340ef21d843bdd2f0eb2375cfe
|
||||||
ScriptedImporter:
|
ScriptedImporter:
|
||||||
internalIDToNameTable: []
|
internalIDToNameTable: []
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
@@ -7,4 +7,5 @@ ScriptedImporter:
|
|||||||
userData:
|
userData:
|
||||||
assetBundleName:
|
assetBundleName:
|
||||||
assetBundleVariant:
|
assetBundleVariant:
|
||||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
|
||||||
|
disableValidation: 0
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<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="Item" src="project://database/Assets/ModuleCore/ModuleUISMenu/UI%20Toolkit/MenuPanel/MenuTemplate.uxml?fileID=9197481963319205126&guid=1ee167986f6e9a840a45450b4b6adfc2&type=3#MenuTemplate" />
|
||||||
|
<Style src="project://database/Assets/ModuleCore/ModuleUISMenu/UI%20Toolkit/MenuPanel/MenuPanel.uss?fileID=7433441132597879392&guid=4b1be5340ef21d843bdd2f0eb2375cfe&type=3#MenuPanel" />
|
||||||
|
<ui:VisualElement name="Container" style="background-color: rgb(255, 255, 255); border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; padding-top: 3px; padding-right: 3px; padding-bottom: 3px; padding-left: 3px; align-self: flex-start; min-width: 150px; 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);">
|
||||||
|
<ui:Instance template="Item" name="Item" />
|
||||||
|
<ui:Instance template="Item" name="Item" />
|
||||||
|
<ui:Instance template="Item" name="Item" />
|
||||||
|
<ui:Instance template="Item" name="Item" />
|
||||||
|
<ui:Instance template="Item" name="Item" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:UXML>
|
||||||
+4
-2
@@ -1,7 +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">
|
<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/GamePanel/ShortcutMenu/ShortcutMenu.uss?fileID=7433441132597879392&guid=a53da9fc389948e40ac96af14dd02c10&type=3#ShortcutMenu" />
|
<Style src="project://database/Assets/ModuleCore/ModuleUISMenu/UI%20Toolkit/MenuPanel/MenuPanel.uss?fileID=7433441132597879392&guid=4b1be5340ef21d843bdd2f0eb2375cfe&type=3#MenuPanel" />
|
||||||
<ui:VisualElement class="menu-unit">
|
<ui:VisualElement class="menu-unit">
|
||||||
<ui:Label tabindex="-1" text="Label" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Name" style="-unity-text-align: middle-center; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; height: 30px;" />
|
<ui:VisualElement style="width: 30px;" />
|
||||||
|
<ui:Label tabindex="-1" text="Label" parse-escape-sequences="true" display-tooltip-when-elided="true" name="Name" style="-unity-text-align: middle-center; margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px;" />
|
||||||
|
<ui:VisualElement style="flex-grow: 1;" />
|
||||||
<ui:VisualElement name="Arrow" class="menu-arrow" />
|
<ui:VisualElement name="Arrow" class="menu-arrow" />
|
||||||
</ui:VisualElement>
|
</ui:VisualElement>
|
||||||
</ui:UXML>
|
</ui:UXML>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
.menu {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-hide {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<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="ShortcutMenu" src="project://database/Assets/UI%20Toolkit/GamePanel/ShortcutMenu/ShortcutMenu.uxml?fileID=9197481963319205126&guid=531a74f84d51b5d49a048079629e13e0&type=3#ShortcutMenu" />
|
|
||||||
<Style src="project://database/Assets/UI%20Toolkit/Document/Document.uss?fileID=7433441132597879392&guid=9205939af30a4394f8f2e34232b27890&type=3#Document" />
|
|
||||||
<ui:Instance template="ShortcutMenu" name="ShortcutMenu" picking-mode="Ignore" class="document-page" />
|
|
||||||
</ui:UXML>
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
<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="Item" src="project://database/Assets/UI%20Toolkit/GamePanel/ShortcutMenu/ItemTemplate.uxml?fileID=9197481963319205126&guid=1ee167986f6e9a840a45450b4b6adfc2&type=3#ItemTemplate" />
|
|
||||||
<Style src="project://database/Assets/UI%20Toolkit/GamePanel/ShortcutMenu/ShortcutMenu.uss?fileID=7433441132597879392&guid=a53da9fc389948e40ac96af14dd02c10&type=3#ShortcutMenu" />
|
|
||||||
<ui:VisualElement name="Container" style="background-color: rgb(255, 255, 255); border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; align-self: flex-start;">
|
|
||||||
<ui:Instance template="Item" name="Item" />
|
|
||||||
<ui:Instance template="Item" name="Item" />
|
|
||||||
<ui:Instance template="Item" name="Item" />
|
|
||||||
<ui:Instance template="Item" name="Item" />
|
|
||||||
<ui:Instance template="Item" name="Item" />
|
|
||||||
</ui:VisualElement>
|
|
||||||
</ui:UXML>
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
.menu {
|
|
||||||
position: absolute;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-hide {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-unit {
|
|
||||||
flex-direction: row;
|
|
||||||
align-self: flex-start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-unit:hover {
|
|
||||||
background-color: rgba(0, 0, 0, 0.2);
|
|
||||||
border-top-left-radius: 5px;
|
|
||||||
border-top-right-radius: 5px;
|
|
||||||
border-bottom-right-radius: 5px;
|
|
||||||
border-bottom-left-radius: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-arrow {
|
|
||||||
flex-grow: 0;
|
|
||||||
height: 30px;
|
|
||||||
width: 30px;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
.menu-arrow-hide {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user