1
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 弹出窗口
|
||||
/// </summary>
|
||||
public class UIPopup : ModuleUIPanel {
|
||||
|
||||
private Action callback;
|
||||
|
||||
public VisualElement GamePopup => Q<VisualElement>("GamePopup");
|
||||
|
||||
public VisualElement Top => Q<VisualElement>("Top");
|
||||
public Label Title => Top.Q<Label>("Title");
|
||||
public VisualElement Container => Top.Q<VisualElement>("Container");
|
||||
|
||||
public VisualElement Bottom => Q<VisualElement>("Bottom");
|
||||
public VisualElement Button => Bottom.Q<VisualElement>("Button");
|
||||
|
||||
public UIPopup(VisualElement element) : base(element) {
|
||||
Button.RegisterCallback<ClickEvent>((evt) => ButtonClick());
|
||||
}
|
||||
|
||||
/// <summary> 按钮点击 </summary>
|
||||
public virtual void ButtonClick() {
|
||||
Settings(false);
|
||||
callback?.Invoke();
|
||||
callback = null;
|
||||
}
|
||||
|
||||
/// <summary> 设置活动状态 </summary>
|
||||
public virtual void Settings(bool active, string content = "", Action callback = null) {
|
||||
GamePopup.EnableInClassList("gamepopup-hide", !active);
|
||||
if (!active) { return; }
|
||||
Title.text = content;
|
||||
this.callback = callback;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed2066d85ddf89443a608b697b3dbf30
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using MuHua;
|
||||
|
||||
/// <summary>
|
||||
/// 加载进度
|
||||
/// </summary>
|
||||
public class UIProgres : ModuleUIPanel {
|
||||
|
||||
public UISliderH progress;
|
||||
|
||||
public VisualElement Progress => element.Q<VisualElement>("Progress");
|
||||
public Label Title => Progress.Q<Label>("Title");
|
||||
|
||||
public UIProgres(VisualElement element) : base(element) {
|
||||
progress = new UISliderH(Progress, element);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置进度(0-1)
|
||||
/// </summary>
|
||||
/// <param name="value"></param>
|
||||
public void Settings(bool active, string content = "", float value = 0) {
|
||||
Title.text = content;
|
||||
progress.UpdateValue(value, false);
|
||||
element.EnableInClassList("document-page-hide", !active);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3691f81ba66e3764d8e341abf37fa35a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 悬浮窗口
|
||||
/// </summary>
|
||||
public abstract class UIWindow : ModuleUIPanel {
|
||||
/// <summary> 绑定的画布 </summary>
|
||||
public readonly VisualElement canvas;
|
||||
|
||||
private bool isDownMove;
|
||||
private Vector3 pointerPosition;
|
||||
private Vector3 originalPosition;
|
||||
|
||||
public VisualElement Window => Q<VisualElement>("Window");
|
||||
public VisualElement Top => Q<VisualElement>("Top");
|
||||
public VisualElement Container => Q<VisualElement>("Container");
|
||||
|
||||
public Label Title => Q<Label>("Title");
|
||||
public VisualElement Close => Q<VisualElement>("Close");
|
||||
|
||||
public UIWindow(VisualElement element, VisualElement canvas) : base(element) {
|
||||
this.canvas = canvas;
|
||||
|
||||
Top.RegisterCallback<PointerDownEvent>(TopDown);
|
||||
canvas.RegisterCallback<PointerUpEvent>((evt) => isDownMove = false);
|
||||
canvas.RegisterCallback<PointerLeaveEvent>((evt) => isDownMove = false);
|
||||
|
||||
Close.RegisterCallback<ClickEvent>((evt) => SetActive(false));
|
||||
}
|
||||
|
||||
/// <summary> 按下Top </summary>
|
||||
private void TopDown(PointerDownEvent evt) {
|
||||
isDownMove = true;
|
||||
pointerPosition = UITool.GetMousePosition();
|
||||
originalPosition = Window.transform.position;
|
||||
}
|
||||
|
||||
/// <summary> 设置活动状态 </summary>
|
||||
public virtual void SetActive(bool active) {
|
||||
Window.EnableInClassList("window-hidden", !active);
|
||||
}
|
||||
|
||||
/// <summary> 更新状态 </summary>
|
||||
public virtual void Update() {
|
||||
if (!isDownMove) { return; }
|
||||
Vector3 mousePosition = UITool.GetMousePosition();
|
||||
Vector3 offset = mousePosition - pointerPosition;
|
||||
Vector3 position = originalPosition + new Vector3(offset.x, -offset.y);
|
||||
|
||||
float width = canvas.resolvedStyle.width - Window.resolvedStyle.width;
|
||||
float height = canvas.resolvedStyle.height - Window.resolvedStyle.height;
|
||||
position.x = Mathf.Clamp(position.x, 0, width);
|
||||
position.y = Mathf.Clamp(position.y, 0, height);
|
||||
|
||||
Window.transform.position = position;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8db6302b07dcf8649b966f15c6fad581
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user