change font size and scrollbar size on mobile

This commit is contained in:
in0finite 2019-07-26 21:46:06 +02:00
parent c8f846eb61
commit de459d92d6

View file

@ -24,6 +24,14 @@ namespace SanAndreasUnity.Behaviours
}
}
bool m_isFirstOnGUI = true;
[SerializeField] int m_defaultFontSizeOnMobile = 16;
[SerializeField] float m_scrollbarSizeMultiplierOnMobile = 2f;
// note: UIManager's OnGUI() should execute before other OnGUI()s, because other scripts may try to create their own
// style from existing styles
void Awake()
@ -39,6 +47,61 @@ namespace SanAndreasUnity.Behaviours
}
void OnGUI()
{
if (m_isFirstOnGUI)
{
m_isFirstOnGUI = false;
this.SetupGui();
}
}
void SetupGui()
{
if (Application.isMobilePlatform)
{
var skin = GUI.skin;
// make scrollbars wider
var styles = new GUIStyle[]{skin.horizontalScrollbar, skin.horizontalScrollbarLeftButton, skin.horizontalScrollbarRightButton, skin.horizontalScrollbarThumb};
foreach (var style in styles)
{
//Debug.LogFormat("style: {0}, height: {1}", style.name, style.fixedHeight);
style.fixedHeight *= m_scrollbarSizeMultiplierOnMobile;
}
styles = new GUIStyle[]{skin.verticalScrollbar, skin.verticalScrollbarDownButton, skin.verticalScrollbarThumb, skin.verticalScrollbarUpButton};
foreach (var style in styles)
{
//Debug.LogFormat("style: {0}, width: {1}", style.name, style.fixedWidth);
style.fixedWidth *= m_scrollbarSizeMultiplierOnMobile;
}
// set font size for styles
SetStylesFontSize(m_defaultFontSizeOnMobile);
}
}
static void SetStylesFontSize(int newFontSize)
{
// change font size for styles
var skin = GUI.skin;
var styles = new GUIStyle[]{skin.button, skin.label, skin.textArea, skin.textField, skin.toggle, skin.window, skin.box};
foreach (var style in styles)
{
//Debug.LogFormat("style: {0}, font size: {1}", style.name, style.fontSize);
style.fontSize = newFontSize;
}
}
}
}