Created
December 22, 2016 02:14
-
-
Save MiketoString/3cbe3a4a56ea0bb5eaded1d497650fc2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.EventSystems; | |
public class DpiEventSystemDragThreshold : MonoBehaviour | |
{ | |
public int referenceDPI = 100; | |
public float referencePixelDrag = 8f; | |
public bool verbose = true; | |
void Awake() | |
{ | |
UpdateDragThreshold( Screen.dpi ); | |
} | |
public void UpdateDragThreshold(float screenDpi) | |
{ | |
EventSystem eventSystem = GetComponent<EventSystem>(); | |
if (eventSystem == null) { | |
Debug.LogWarning("Missing EventSystemComponent on DpiEventSystemDragThreshold", this); | |
} | |
eventSystem.pixelDragThreshold = Mathf.RoundToInt(screenDpi/ referenceDPI*referencePixelDrag); | |
if( verbose ) { | |
Debug.Log( "DpiEventSystemDragThreshold set to: " + eventSystem.pixelDragThreshold + ", for dpi: " + screenDpi + ", reference: " + referencePixelDrag + " / " + referenceDPI ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment