From adbe4370c9ae29ad75577b216946d2ae7b843425 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Sat, 1 Oct 2022 15:48:53 +0800 Subject: [PATCH] Fix AspectRatioLayoutElement to use its own transform. --- .../Unity/UI/AspectRatioLayoutElement.cs | 25 ++++--------------- .../Crtr/Browsing/PropertyCategoryPanel.cs | 6 ++--- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/Assets/Cryville/Common/Unity/UI/AspectRatioLayoutElement.cs b/Assets/Cryville/Common/Unity/UI/AspectRatioLayoutElement.cs index 56e752e..9bc1ee7 100644 --- a/Assets/Cryville/Common/Unity/UI/AspectRatioLayoutElement.cs +++ b/Assets/Cryville/Common/Unity/UI/AspectRatioLayoutElement.cs @@ -1,17 +1,9 @@ -using System; -using UnityEngine; +using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace Cryville.Common.Unity.UI { public class AspectRatioLayoutElement : UIBehaviour, ILayoutElement { - [SerializeField] - private RectTransform m_containerTransform = null; - public RectTransform ContainerTransform { - get { return m_containerTransform; } - set { SetProperty(ref m_containerTransform, value); } - } - [SerializeField] private float m_aspectRatio = 1; public float AspectRatio { @@ -40,8 +32,8 @@ namespace Cryville.Common.Unity.UI { public float minWidth { get { return m_isVertical - ? m_containerTransform.rect.width - : m_containerTransform.rect.height * m_aspectRatio; + ? (transform as RectTransform).rect.width + : (transform as RectTransform).rect.height * m_aspectRatio; } } public float preferredWidth { get { return minWidth; } } @@ -50,8 +42,8 @@ namespace Cryville.Common.Unity.UI { public float minHeight { get { return m_isVertical - ? m_containerTransform.rect.width / m_aspectRatio - : m_containerTransform.rect.height; + ? (transform as RectTransform).rect.width / m_aspectRatio + : (transform as RectTransform).rect.height; } } public float preferredHeight { get { return minHeight; } } @@ -59,13 +51,6 @@ namespace Cryville.Common.Unity.UI { public int layoutPriority { get { return 1; } } - private bool isRootLayoutGroup { - get { - Transform parent = transform.parent; - return parent == null || transform.parent.GetComponent(typeof(ILayoutGroup)) == null; - } - } - public void CalculateLayoutInputHorizontal() { } public void CalculateLayoutInputVertical() { } diff --git a/Assets/Cryville/Crtr/Browsing/PropertyCategoryPanel.cs b/Assets/Cryville/Crtr/Browsing/PropertyCategoryPanel.cs index a4a9685..a152851 100644 --- a/Assets/Cryville/Crtr/Browsing/PropertyCategoryPanel.cs +++ b/Assets/Cryville/Crtr/Browsing/PropertyCategoryPanel.cs @@ -1,9 +1,8 @@ -using System.Collections.Generic; +using Cryville.Common.Unity.UI; +using System.Collections.Generic; using System.Reflection; using UnityEngine; using UnityEngine.UI; -using Cryville.Common.Unity.UI; -using System; namespace Cryville.Crtr.Browsing { public class PropertyCategoryPanel : MonoBehaviour { @@ -37,7 +36,6 @@ namespace Cryville.Crtr.Browsing { var obj = GameObject.Instantiate(m_propertyPrefab); obj.transform.SetParent(transform, false); obj.GetComponent().Load(prop, target); - obj.GetComponent().ContainerTransform = (RectTransform)transform; } }