Skip to content

Instantly share code, notes, and snippets.

@kirillrybin
Last active March 30, 2016 11:52
Show Gist options
  • Save kirillrybin/762c80d277c199656def to your computer and use it in GitHub Desktop.
Save kirillrybin/762c80d277c199656def to your computer and use it in GitHub Desktop.
NGUI Unity3d : Getting Screen size via http://www.zedia.net/2013/ngui-unity3d-getting-screen-size/
using UnityEngine;
public class DisplaySize{
protected static DisplaySize _instance;
public static DisplaySize instance{
get {
if (_instance == null){
_instance = new DisplaySize();
}
return _instance;
}
}
public GameObject gameObject;
public float width;
public float height;
public void CalculateSize(){
UIRoot mRoot = NGUITools.FindInParents<UIRoot>(gameObject);
float ratio = (float)mRoot.activeHeight / Screen.height;
width = Mathf.Ceil(Screen.width * ratio);
height = Mathf.Ceil(Screen.height * ratio);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment