Skip to content

Instantly share code, notes, and snippets.

@boj
Created August 4, 2012 00:37
Show Gist options
  • Save boj/3253068 to your computer and use it in GitHub Desktop.
Save boj/3253068 to your computer and use it in GitHub Desktop.
Unity3d Aspect Ratio Check
using UnityEngine;
using System.Collections;
public class GameConfig : MonoBehaviour {
public static bool isFourThreeAspect() {
int factor = gcd(Screen.width, Screen.height);
int wFactor = Screen.width / factor;
int hFactor = Screen.height / factor;
if (wFactor == 3 && hFactor == 4) {
return true;
} else {
return false;
}
}
public static bool isSixteenNineAspect() {
int factor = gcd(Screen.width, Screen.height);
int wFactor = Screen.width / factor;
int hFactor = Screen.height / factor;
if (wFactor == 9 && hFactor == 16) {
return true;
} else {
return false;
}
}
public static int gcd(int a, int b) {
return (b == 0) ? a : gcd (b, a % b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment