Last active
September 22, 2016 21:06
-
-
Save dskjal/b15078ffe7f928f8930b7a43acb2912c to your computer and use it in GitHub Desktop.
Unity で適切なフォントサイズを計算
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
| // BEGIN MIT LICENSE BLOCK // | |
| // | |
| // Copyright (c) 2016 dskjal | |
| // This software is released under the MIT License. | |
| // http://opensource.org/licenses/mit-license.php | |
| // | |
| // END MIT LICENSE BLOCK // | |
| private void getProperFontSize(GUIStyle style, int nLines, int textAreaHeight) { | |
| int maxHeight = textAreaHeight / nLines; | |
| int curHeight = getFontHeight(style); | |
| if(curHeight > maxHeight) { | |
| while(curHeight > maxHeight) { | |
| style.fontSize = style.fontSize-1; | |
| curHeight = getFontHeight(style); | |
| } | |
| style.fontSize = style.fontSize + 1; | |
| } | |
| else { | |
| while(curHeight < maxHeight) { | |
| style.fontSize = style.fontSize + 1; | |
| curHeight = getFontHeight(style); | |
| } | |
| style.fontSize = style.fontSize - 1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment