From 3629fac6f20e93f280a1264847955cde964f23a4 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 30 Sep 2018 15:24:57 +0200 Subject: [PATCH] Implemented second Version of automatically scaling Exhibit title --- .../ObjectCameraRenderTexture.renderTexture | 2 +- Assets/Resources/Materials/UIBaseOpaque.mat | 4 +- Assets/Resources/Prefabs/ExhibitTitle.prefab | 12 ++--- .../Scripts/Exhibition/ExhibitBehaviour.cs | 6 +-- .../Exhibition/ExhibitTitleBehaviour.cs | 50 ++++++------------- Assets/mainScene.unity | 26 +--------- 6 files changed, 29 insertions(+), 71 deletions(-) diff --git a/Assets/Resources/Materials/ObjectCameraRenderTexture.renderTexture b/Assets/Resources/Materials/ObjectCameraRenderTexture.renderTexture index d0b74f3..e87fda1 100644 --- a/Assets/Resources/Materials/ObjectCameraRenderTexture.renderTexture +++ b/Assets/Resources/Materials/ObjectCameraRenderTexture.renderTexture @@ -19,7 +19,7 @@ RenderTexture: m_MipMap: 1 m_GenerateMips: 1 m_SRGB: 1 - m_UseDynamicScale: 1 + m_UseDynamicScale: 0 m_BindMS: 0 m_TextureSettings: serializedVersion: 2 diff --git a/Assets/Resources/Materials/UIBaseOpaque.mat b/Assets/Resources/Materials/UIBaseOpaque.mat index b240d7f..dc2a258 100644 --- a/Assets/Resources/Materials/UIBaseOpaque.mat +++ b/Assets/Resources/Materials/UIBaseOpaque.mat @@ -7,13 +7,13 @@ Material: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_Name: UIBaseOpaque - m_Shader: {fileID: 4800000, guid: 3a1c68c8292caf046bd21158886c5e40, type: 3} + m_Shader: {fileID: 10782, guid: 0000000000000000f000000000000000, type: 0} m_ShaderKeywords: ETC1_EXTERNAL_ALPHA _ALPHAPREMULTIPLY_ON _SPECULARHIGHLIGHTS_OFF _SUNDISK_HIGH_QUALITY m_LightmapFlags: 4 m_EnableInstancingVariants: 0 m_DoubleSidedGI: 0 - m_CustomRenderQueue: 3000 + m_CustomRenderQueue: -1 stringTagMap: {} disabledShaderPasses: [] m_SavedProperties: diff --git a/Assets/Resources/Prefabs/ExhibitTitle.prefab b/Assets/Resources/Prefabs/ExhibitTitle.prefab index 21379b6..346bf0e 100644 --- a/Assets/Resources/Prefabs/ExhibitTitle.prefab +++ b/Assets/Resources/Prefabs/ExhibitTitle.prefab @@ -225,7 +225,7 @@ MonoBehaviour: m_Calls: [] m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null - m_text: THIS IS MY TITLE + m_text: Title m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 715b80e429c437e40867928a4e1fc975, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 715b80e429c437e40867928a4e1fc975, type: 2} @@ -292,10 +292,10 @@ MonoBehaviour: m_margin: {x: 0.02, y: 0.02, z: 0.02, w: 0.02} m_textInfo: textComponent: {fileID: 114580846098669954} - characterCount: 16 + characterCount: 5 spriteCount: 0 - spaceCount: 3 - wordCount: 4 + spaceCount: 0 + wordCount: 1 linkCount: 0 lineCount: 1 pageCount: 1 @@ -330,12 +330,12 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_IgnoreLayout: 0 - m_MinWidth: 1 + m_MinWidth: 0.5 m_MinHeight: -1 m_PreferredWidth: -1 m_PreferredHeight: -1 m_FlexibleWidth: -1 - m_FlexibleHeight: 1000 + m_FlexibleHeight: -1 m_LayoutPriority: 1 --- !u!114 &114807976848859904 MonoBehaviour: diff --git a/Assets/RothenburgAR/Scripts/Exhibition/ExhibitBehaviour.cs b/Assets/RothenburgAR/Scripts/Exhibition/ExhibitBehaviour.cs index a4486b5..79dd500 100644 --- a/Assets/RothenburgAR/Scripts/Exhibition/ExhibitBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/Exhibition/ExhibitBehaviour.cs @@ -40,15 +40,15 @@ namespace RothenburgAR.Exhibition TitleBehaviour.Exhibit = this; } + //TODO remove title rotation if (newTitle.Rotation.HasValue) TitleBehaviour.transform.localEulerAngles = newTitle.Rotation.Value + new Vector3(90, 0, 0); + //TODO remove title position and calculate on the fly? if tracker is on a wall, below is best. if it sits on the ground, what? if (newTitle.Position.HasValue) TitleBehaviour.transform.localPosition = newTitle.Position.Value; - TitleBehaviour.FontSize = newTitle.FontSize; - TitleBehaviour.BoxHeight = newTitle.BoxHeight; - TitleBehaviour.BoxWidth = newTitle.BoxWidth; + //TODO set scale to resize the title relative to tracker size TitleBehaviour.DataText = newTitle.Text; } diff --git a/Assets/RothenburgAR/Scripts/Exhibition/ExhibitTitleBehaviour.cs b/Assets/RothenburgAR/Scripts/Exhibition/ExhibitTitleBehaviour.cs index d1c3b13..f478e99 100644 --- a/Assets/RothenburgAR/Scripts/Exhibition/ExhibitTitleBehaviour.cs +++ b/Assets/RothenburgAR/Scripts/Exhibition/ExhibitTitleBehaviour.cs @@ -4,6 +4,7 @@ using RothenburgAR.UI; using System.Collections; using TMPro; using UnityEngine; +using UnityEngine.UI; namespace RothenburgAR.Exhibition { @@ -32,28 +33,14 @@ namespace RothenburgAR.Exhibition set { this.GuiText.fontSize = value; } } - public float BoxWidth - { - get { return this.GuiRect.rect.width; } - set - { - UpdateRect(value, BoxHeight); - } - } - - public float BoxHeight - { - get { return this.GuiRect.rect.height; } - set - { - UpdateRect(BoxWidth, value); - } - } - public string DisplayText { get { return this.GuiText.text; } - set { this.GuiText.text = value; } + set + { + this.GuiText.text = value; + this.RecalculateSize(); + } } public TextElement DataText @@ -61,23 +48,15 @@ namespace RothenburgAR.Exhibition get; set; } - public void UpdateRect(float width, float height) + void OnEnable() { - return; - this.GuiRect.sizeDelta = new Vector2(width, height); - if (_descriptionPoiBehaviour != null) - { - Background.transform.localScale = new Vector3(width, height, 1.0f); - _descriptionPoiBehaviour.transform.localPosition = new Vector3(-0.4f, 0f, -0.005f); - } - else - { - Background.transform.localScale = new Vector3(width, height, 1.0f); - } + this.RecalculateSize(); } - void Start() + private void RecalculateSize() { + GuiText.GetComponent().enabled = false; + GuiText.GetComponent().enabled = true; StartCoroutine(CreateBorder()); } @@ -124,7 +103,10 @@ namespace RothenburgAR.Exhibition private IEnumerator CreateBorder() { - yield return null; + yield return null; // wait for next frame so the borderContainer layouter has time to recalculate + var oldBorder = Background.GetComponentInChildren(); + if (oldBorder != null) Destroy(oldBorder.gameObject); + var borderContainer = new GameObject("BorderContainer"); borderContainer.transform.SetParent(Background.transform, false); @@ -152,7 +134,7 @@ namespace RothenburgAR.Exhibition outlineRenderer.SetPosition(5, topRight); outlineRenderer.material = UIColorSchemeManager.Instance.GetUIMaterial(UIMaterial.BaseOpaque); - outlineRenderer.enabled = false; + outlineRenderer.enabled = GuiText.GetComponent().enabled; } } } \ No newline at end of file diff --git a/Assets/mainScene.unity b/Assets/mainScene.unity index a488d61..ba52d04 100644 --- a/Assets/mainScene.unity +++ b/Assets/mainScene.unity @@ -337,8 +337,6 @@ GameObject: m_Component: - component: {fileID: 1230455932} - component: {fileID: 1230455931} - - component: {fileID: 1230455930} - - component: {fileID: 1230455929} m_Layer: 0 m_Name: UIObjectCamera m_TagString: Untagged @@ -346,20 +344,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!92 &1230455929 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1230455927} - m_Enabled: 1 ---- !u!124 &1230455930 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1230455927} - m_Enabled: 1 --- !u!20 &1230455931 Camera: m_ObjectHideFlags: 0 @@ -391,7 +375,7 @@ Camera: m_TargetEye: 3 m_HDR: 1 m_AllowMSAA: 1 - m_AllowDynamicResolution: 1 + m_AllowDynamicResolution: 0 m_ForceIntoRT: 0 m_OcclusionCulling: 1 m_StereoConvergence: 10 @@ -649,7 +633,6 @@ GameObject: m_Component: - component: {fileID: 1931338042} - component: {fileID: 1931338041} - - component: {fileID: 1931338039} m_Layer: 0 m_Name: UICamera m_TagString: Untagged @@ -657,13 +640,6 @@ GameObject: m_NavMeshLayer: 0 m_StaticEditorFlags: 0 m_IsActive: 1 ---- !u!92 &1931338039 -Behaviour: - m_ObjectHideFlags: 0 - m_PrefabParentObject: {fileID: 0} - m_PrefabInternal: {fileID: 0} - m_GameObject: {fileID: 1931338037} - m_Enabled: 1 --- !u!20 &1931338041 Camera: m_ObjectHideFlags: 0