合并代码

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
@@ -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: