修复 2021.3.2f1 工程中出现的api缺失问题

This commit is contained in:
2026-06-25 14:50:57 +08:00
parent bfce70eb6f
commit af50f72656
2 changed files with 100 additions and 70 deletions
+22 -14
View File
@@ -1,6 +1,6 @@
/*
* UniWindowDragMove.cs
*
*
* 作者: Kirurobo http://twitter.com/kirurobo
* 许可证: MIT
*/
@@ -10,22 +10,23 @@ using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
#if ENABLE_LEGACY_INPUT_MANAGER
#elif ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace Kirurobo
namespace Kirurobo
{
public class UniWindowMoveHandle : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler, IPointerUpHandler
public class UniWindowMoveHandle : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler,
IPointerUpHandler
{
private UniWindowController _uniwinc;
/// <summary>
/// 窗口最大化时是否禁用移动
/// </summary>
[Tooltip("窗口已最大化(缩放)时禁用拖拽移动。")]
public bool disableOnZoomed = true;
[Tooltip("窗口已最大化(缩放)时禁用拖拽移动。")] public bool disableOnZoomed = true;
/// <summary>
/// 拖动中则为 true
@@ -34,6 +35,7 @@ namespace Kirurobo
{
get { return _isDragging; }
}
private bool _isDragging = false;
/// <summary>
@@ -56,17 +58,21 @@ namespace Kirurobo
/// 记录拖动前自动命中测试是否启用
/// </summary>
private bool _isHitTestEnabled;
/// <summary>
/// 拖动开始时窗口内坐标[像素]
/// </summary>
private Vector2 _dragStartedPosition;
// 首次帧更新前调用 Start
void Start()
{
// 获取场景中的 UniWindowController
#if UNITY_2022_1_OR_NEWER
_uniwinc = GameObject.FindAnyObjectByType<UniWindowController>();
#else
_uniwinc = GameObject.FindObjectOfType<UniWindowController>();
#endif
if (_uniwinc) _isHitTestEnabled = _uniwinc.isHitTestEnabled;
//// 下面的代码似乎不需要,所以注释掉以免擅自更改
@@ -85,7 +91,7 @@ namespace Kirurobo
// 仅通过鼠标左键拖动
if (eventData.button != PointerEventData.InputButton.Left) return;
// Mac 上行为会有所不同
// 实际上仅在 Retina 支持启用时,但 eventData.position 的坐标系与窗口坐标系的缩放会不一致
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
@@ -93,7 +99,7 @@ namespace Kirurobo
#else
_dragStartedPosition = eventData.position;
#endif
// 如果 _isDragging 为 false,则判断即将开始拖动
if (!_isDragging)
{
@@ -102,7 +108,7 @@ namespace Kirurobo
_uniwinc.isHitTestEnabled = false;
_uniwinc.isClickThrough = false;
}
_isDragging = true;
}
@@ -130,11 +136,12 @@ namespace Kirurobo
{
if (_isDragging)
{
_uniwinc.isHitTestEnabled = _isHitTestEnabled;
_uniwinc.isHitTestEnabled = _isHitTestEnabled;
}
_isDragging = false;
}
/// <summary>
/// 非最大化时,通过鼠标拖动移动窗口
/// </summary>
@@ -158,7 +165,8 @@ namespace Kirurobo
// 如果鼠标按钮已松开,则结束拖动
var buttons = UniWindowController.GetMouseButtons();
if ((buttons & UniWindowController.MouseButton.Left) == UniWindowController.MouseButton.None) {
if ((buttons & UniWindowController.MouseButton.Left) == UniWindowController.MouseButton.None)
{
EndDragging();
return;
}
@@ -203,4 +211,4 @@ namespace Kirurobo
#endif
}
}
}
}