增加更新接口

This commit is contained in:
MuHua-123
2025-08-28 14:24:09 +08:00
parent 301030487e
commit 04b65e6945
38 changed files with 155 additions and 509 deletions
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -7,9 +8,11 @@ namespace MuHua {
/// <summary>
/// 悬浮窗口
/// </summary>
public abstract class UIWindow : ModuleUIPanel {
public abstract class UIWindow : ModuleUIPanel, IDisposable, UIControl {
/// <summary> 绑定的画布 </summary>
public readonly VisualElement canvas;
/// <summary> 隐藏的USS类名 </summary>
public string hideClassName = "document-page-hide";
private bool isDownMove;
private Vector3 pointerPosition;
@@ -26,10 +29,16 @@ namespace MuHua {
this.canvas = canvas;
Top.RegisterCallback<PointerDownEvent>(TopDown);
canvas.RegisterCallback<PointerUpEvent>((evt) => isDownMove = false);
canvas.RegisterCallback<PointerLeaveEvent>((evt) => isDownMove = false);
Close.RegisterCallback<ClickEvent>((evt) => Settings(false));
canvas.RegisterCallback<PointerUpEvent>(DraggerUpOrLeave);
canvas.RegisterCallback<PointerLeaveEvent>(DraggerUpOrLeave);
Close.RegisterCallback<ClickEvent>(CloseButton);
}
/// <summary> 解绑事件,防止内存泄漏 </summary>
public virtual void Dispose() {
Top.UnregisterCallback<PointerDownEvent>(TopDown);
canvas.UnregisterCallback<PointerUpEvent>(DraggerUpOrLeave);
canvas.UnregisterCallback<PointerLeaveEvent>(DraggerUpOrLeave);
Close.UnregisterCallback<ClickEvent>(CloseButton);
}
/// <summary> 按下Top </summary>
@@ -38,10 +47,18 @@ namespace MuHua {
pointerPosition = UITool.GetMousePosition();
originalPosition = Window.transform.position;
}
/// <summary> 鼠标松开或离开 </summary>
private void DraggerUpOrLeave(EventBase evt) {
isDownMove = false;
}
/// <summary> 关闭按钮 </summary>
private void CloseButton(EventBase evt) {
Settings(false);
}
/// <summary> 设置活动状态 </summary>
public virtual void Settings(bool active) {
element.style.display = active ? DisplayStyle.Flex : DisplayStyle.None;
element.EnableInClassList(hideClassName, !active);
}
/// <summary> 更新状态 </summary>