Skip to content

Instantly share code, notes, and snippets.

@ChuckSavage
Last active October 29, 2016 06:09
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 ChuckSavage/c9d552e8f94316ec6bce13b5a51399ca to your computer and use it in GitHub Desktop.
Save ChuckSavage/c9d552e8f94316ec6bce13b5a51399ca to your computer and use it in GitHub Desktop.
NGUI DisplaySize
/*
* Modified this guys code - http://www.zedia.net/2013/ngui-unity3d-getting-screen-size/comment-page-1/
*/
public static class DisplaySize
{
public static float ScreenHeight(this Transform t)
{
UIRoot root = t.root.GetComponent<UIRoot>() ?? NGUITools.FindInParents<UIRoot>(t);
float ratio = (float)root.activeHeight / Screen.height;
return Mathf.Ceil(Screen.height * ratio);
}
public static float ScreenWidth(this Transform t)
{
UIRoot root = t.root.GetComponent<UIRoot>() ?? NGUITools.FindInParents<UIRoot>(t);
float ratio = (float)root.activeHeight / Screen.height;
return Mathf.Ceil(Screen.width * ratio);
}
}
@ChuckSavage
Copy link
Author

Turns out NGUITools.screenSize is the way to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment