Skip to content

Instantly share code, notes, and snippets.

@gksen
Forked from ok3141/Script.cs
Created August 15, 2016 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gksen/1743fe25807131c6e66ae5280e24d63a to your computer and use it in GitHub Desktop.
Save gksen/1743fe25807131c6e66ae5280e24d63a to your computer and use it in GitHub Desktop.
Unity get scale factor (Android-like style for DP)
void Awake() {
var refDp = scaler.referenceResolution.y;
var realDp = Screen.height * 160 / Screen.dpi;
var factor = refDp / realDp;
Debug.Log ("RefDP: " + refDp + " realDP: " + realDp + " factor: " + factor);
if (factor < 1) {
factor = (factor + 1) / 2f;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment