Drag + Click 이벤트 동시사용할 때 Drag 민감도 조절

PhysicalDragThreshold

Scrollview + Button 조합이거나

 

OnPointerDown + OnBeginDrag 조합을 사용할 경우 해상도가 너무 클경우

Drag가 너무 쉽게 되버려서 클릭을 못하는 경우가 생긴다.

 

EventSystem에 pixelDragThreshold 값을 조정하여 민감도를 조정할 수 있으며,

아래의 스크립트는 해상도에 따른 민감도 조절을 계산한다.

 

 

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
 
public class PhysicalDragThreshold : MonoBehaviour
{
    private const float inchToCm = 2.54f;
    private EventSystem eventSystem = null;
 
    private readonly float dragThresholdCM = 0.5f;
 
    void Start()
    {
        if (eventSystem == null)
        {
            eventSystem = GetComponent<EventSystem>();
        }
 
        SetDragThreshold();
    }
 
    private void SetDragThreshold()
    {
        if (eventSystem != null)
        {
            eventSystem.pixelDragThreshold = (int)(dragThresholdCM * Screen.dpi / inchToCm);
        }
    }
}

 

댓글

Designed by JB FACTORY