From ac77ee67ea3096e2846ac38d5b731b0a2b9dcb41 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 24 Aug 2018 18:19:09 +0200 Subject: [PATCH] Added dpi specific font scaling --- .../Scripts/UI/FontsizeManager.cs | 31 +++++++++++++++ .../Scripts/UI/FontsizeManager.cs.meta | 13 +++++++ .../Scripts/UI/FontsizeSelector.cs | 28 ++++++++++++++ .../Scripts/UI/FontsizeSelector.cs.meta | 13 +++++++ .../Scripts/Updater/UpdaterBehaviour.cs | 2 +- Assets/updaterScene.unity | 38 ++++++++++++++++--- 6 files changed, 118 insertions(+), 7 deletions(-) create mode 100644 Assets/RothenburgAR/Scripts/UI/FontsizeManager.cs create mode 100644 Assets/RothenburgAR/Scripts/UI/FontsizeManager.cs.meta create mode 100644 Assets/RothenburgAR/Scripts/UI/FontsizeSelector.cs create mode 100644 Assets/RothenburgAR/Scripts/UI/FontsizeSelector.cs.meta diff --git a/Assets/RothenburgAR/Scripts/UI/FontsizeManager.cs b/Assets/RothenburgAR/Scripts/UI/FontsizeManager.cs new file mode 100644 index 0000000..347f22a --- /dev/null +++ b/Assets/RothenburgAR/Scripts/UI/FontsizeManager.cs @@ -0,0 +1,31 @@ +using RothenburgAR.Common; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace RothenburgAR.UI +{ + public class FontsizeManager : Singleton + { + private Dictionary factors = new Dictionary + { + { + FontsizeClass.Header, 1f + }, + { + FontsizeClass.Body, 0.4f + } + }; + + public float GetFontsize(FontsizeClass sizeClass) + { + return Screen.dpi * factors[sizeClass]; + } + } + + public enum FontsizeClass + { + Header, + Body + } +} \ No newline at end of file diff --git a/Assets/RothenburgAR/Scripts/UI/FontsizeManager.cs.meta b/Assets/RothenburgAR/Scripts/UI/FontsizeManager.cs.meta new file mode 100644 index 0000000..f7e3257 --- /dev/null +++ b/Assets/RothenburgAR/Scripts/UI/FontsizeManager.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 78b8d14800915e84694580fb0d241681 +timeCreated: 1535122456 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RothenburgAR/Scripts/UI/FontsizeSelector.cs b/Assets/RothenburgAR/Scripts/UI/FontsizeSelector.cs new file mode 100644 index 0000000..78e6a01 --- /dev/null +++ b/Assets/RothenburgAR/Scripts/UI/FontsizeSelector.cs @@ -0,0 +1,28 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace RothenburgAR.UI +{ + public class FontsizeSelector : MonoBehaviour + { + public FontsizeClass SizeClass = FontsizeClass.Body; + + void Start() + { + var tmproText = gameObject.GetComponent(); + if (tmproText != null) + { + tmproText.enableAutoSizing = true; + tmproText.fontSizeMax = FontsizeManager.Instance.GetFontsize(this.SizeClass); + tmproText.fontSizeMin = tmproText.fontSizeMax * 0.8f; + } + } + + void Update() + { + + } + } + +} \ No newline at end of file diff --git a/Assets/RothenburgAR/Scripts/UI/FontsizeSelector.cs.meta b/Assets/RothenburgAR/Scripts/UI/FontsizeSelector.cs.meta new file mode 100644 index 0000000..10d49f2 --- /dev/null +++ b/Assets/RothenburgAR/Scripts/UI/FontsizeSelector.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 8b136c9157840904ba79e96d50f494bc +timeCreated: 1535125739 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs index 8003080..16a0ce3 100644 --- a/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/Updater/UpdaterBehaviour.cs @@ -179,7 +179,7 @@ namespace RothenburgAR.Updater { //TODO check existing file for creation/alteration date to see if download is necessary - var mediaIDs = exhibit.Pois.Select(p => p.MediaId).ToList(); + var mediaIDs = exhibit.Pois.Select(p => p.MediaId).Except(new List { null }).ToList(); foreach (var mediaId in mediaIDs) { diff --git a/Assets/updaterScene.unity b/Assets/updaterScene.unity index a034846..9421071 100644 --- a/Assets/updaterScene.unity +++ b/Assets/updaterScene.unity @@ -699,8 +699,9 @@ GameObject: - component: {fileID: 879338379} - component: {fileID: 879338381} - component: {fileID: 879338380} + - component: {fileID: 879338382} m_Layer: 5 - m_Name: UpdateMessage + m_Name: Text m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -771,8 +772,8 @@ MonoBehaviour: m_outlineColor: serializedVersion: 2 rgba: 4278190080 - m_fontSize: 25.3 - m_fontSizeBase: 10 + m_fontSize: 50.35 + m_fontSizeBase: 38.4 m_fontWeight: 400 m_enableAutoSizing: 1 m_fontSizeMin: 15 @@ -843,6 +844,18 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 879338378} +--- !u!114 &879338382 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 879338378} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8b136c9157840904ba79e96d50f494bc, type: 3} + m_Name: + m_EditorClassIdentifier: + SizeClass: 1 --- !u!1 &1061370337 GameObject: m_ObjectHideFlags: 0 @@ -1069,8 +1082,9 @@ GameObject: - component: {fileID: 1940905981} - component: {fileID: 1940905983} - component: {fileID: 1940905982} + - component: {fileID: 1940905984} m_Layer: 5 - m_Name: HeaderText + m_Name: Text m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1140,8 +1154,8 @@ MonoBehaviour: m_outlineColor: serializedVersion: 2 rgba: 4278190080 - m_fontSize: 74.25 - m_fontSizeBase: 36 + m_fontSize: 185.6 + m_fontSizeBase: 96 m_fontWeight: 400 m_enableAutoSizing: 1 m_fontSizeMin: 18 @@ -1212,6 +1226,18 @@ CanvasRenderer: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1940905980} +--- !u!114 &1940905984 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1940905980} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 8b136c9157840904ba79e96d50f494bc, type: 3} + m_Name: + m_EditorClassIdentifier: + SizeClass: 0 --- !u!1 &1981763282 GameObject: m_ObjectHideFlags: 0