Last active
October 29, 2016 06:09
-
-
Save ChuckSavage/c9d552e8f94316ec6bce13b5a51399ca to your computer and use it in GitHub Desktop.
NGUI DisplaySize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out NGUITools.screenSize is the way to go.