Skip to content

Instantly share code, notes, and snippets.

@dskjal
Last active September 22, 2016 21:06
Show Gist options
  • Select an option

  • Save dskjal/b15078ffe7f928f8930b7a43acb2912c to your computer and use it in GitHub Desktop.

Select an option

Save dskjal/b15078ffe7f928f8930b7a43acb2912c to your computer and use it in GitHub Desktop.
Unity で適切なフォントサイズを計算
// 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