Skip to content

Instantly share code, notes, and snippets.

@MiketoString
Created December 22, 2016 02:14
Show Gist options
  • Save MiketoString/3cbe3a4a56ea0bb5eaded1d497650fc2 to your computer and use it in GitHub Desktop.
Save MiketoString/3cbe3a4a56ea0bb5eaded1d497650fc2 to your computer and use it in GitHub Desktop.
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