少年修仙传客户端代码仓库
lcy
2025-02-14 0167b3649bcbac139c4fa68568f45ac2ebabd0b7
10360 仙匠大会滑动触发增加限制,避免在其他窗口触发
1个文件已修改
44 ■■■■ 已修改文件
System/LianQi/DragSelectComponentEx.cs 44 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/LianQi/DragSelectComponentEx.cs
@@ -1,5 +1,7 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections.Generic;
namespace vnxbqy.UI
{
@@ -7,6 +9,7 @@
    public class DragSelectComponentEx : MonoBehaviour
    {
        [SerializeField] float m_Sensitive = 10f;
        [SerializeField] GameObject m_TargetObject;
        public event Action<int> onDragComplete;
@@ -27,6 +30,11 @@
                m_StartDrag = true;
                start_position = Input.mousePosition;
                isArea = RectTransformUtility.RectangleContainsScreenPoint(this.transform as RectTransform, start_position, CameraManager.uiCamera);
                if (!IsOverTarget())
                {
                    m_StartDrag = false;
                    return;
                }
            }
            else if (Input.GetMouseButtonUp(0) && m_StartDrag)
            {
@@ -49,17 +57,43 @@
                        direction = delta.y > 0 ? 2 : -2; // 2 表示向上滑动,-2 表示向下滑动
                    }
                    if (onDragComplete != null)
                    // 新增目标对象检测条件
                    if (onDragComplete != null && isArea)
                    {
                        if (isArea)
                        {
                            onDragComplete(direction);
                        }
                        onDragComplete(direction);
                    }
                }
            }
        }
        // 新增目标检测方法
        private bool IsOverTarget()
        {
            if (m_TargetObject == null) return true;
            PointerEventData eventData = new PointerEventData(EventSystem.current)
            {
                position = Input.mousePosition
            };
            List<RaycastResult> results = new List<RaycastResult>();
            EventSystem.current.RaycastAll(eventData, results);
            if (results.Count > 0)
            {
                RaycastResult result = results[0];
                if (result.gameObject == m_TargetObject)
                {
                    return true;
                }
                if (result.gameObject.transform.parent.gameObject == m_TargetObject)
                {
                    return true;
                }
            }
            return false;
        }
        private void OnDisable()
        {
            m_StartDrag = false;