少年修仙传客户端代码仓库
hch
2025-03-19 6770e1eb64c4282def45adb824b14b2a407fdd30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using System;
 
namespace vnxbqy.UI
{
    [DisallowMultipleComponent]
    public class DragSelectComponent : MonoBehaviour
    {
        [SerializeField] float m_Sensitive = 10f;
 
        public event Action<int> onDragComplete;
 
        private bool m_StartDrag = false;
 
        Vector3 start_position = Vector3.zero;
 
        private void LateUpdate()
        {
            if (Input.touchCount > 1)
            {
                m_StartDrag = false;
                return;
            }
            if (Input.GetMouseButtonDown(0))
            {
                m_StartDrag = true;
                start_position = Input.mousePosition;
            }
            else if (Input.GetMouseButtonUp(0) && m_StartDrag)
            {
                var delta = Input.mousePosition - start_position;
                m_StartDrag = false;
                if (Mathf.Abs(delta.x * 0.1f) >= m_Sensitive)
                {
                    if (onDragComplete != null)
                    {
                        onDragComplete(delta.x > 0 ? -1 : 1);
                    }
                }
            }
        }
 
        void OnDisable()
        {
            m_StartDrag = false;
        }
    }
}