Fix AspectRatioLayoutElement to use its own transform.
This commit is contained in:
@@ -1,17 +1,9 @@
|
|||||||
using System;
|
using UnityEngine;
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
namespace Cryville.Common.Unity.UI {
|
namespace Cryville.Common.Unity.UI {
|
||||||
public class AspectRatioLayoutElement : UIBehaviour, ILayoutElement {
|
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]
|
[SerializeField]
|
||||||
private float m_aspectRatio = 1;
|
private float m_aspectRatio = 1;
|
||||||
public float AspectRatio {
|
public float AspectRatio {
|
||||||
@@ -40,8 +32,8 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
public float minWidth {
|
public float minWidth {
|
||||||
get {
|
get {
|
||||||
return m_isVertical
|
return m_isVertical
|
||||||
? m_containerTransform.rect.width
|
? (transform as RectTransform).rect.width
|
||||||
: m_containerTransform.rect.height * m_aspectRatio;
|
: (transform as RectTransform).rect.height * m_aspectRatio;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public float preferredWidth { get { return minWidth; } }
|
public float preferredWidth { get { return minWidth; } }
|
||||||
@@ -50,8 +42,8 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
public float minHeight {
|
public float minHeight {
|
||||||
get {
|
get {
|
||||||
return m_isVertical
|
return m_isVertical
|
||||||
? m_containerTransform.rect.width / m_aspectRatio
|
? (transform as RectTransform).rect.width / m_aspectRatio
|
||||||
: m_containerTransform.rect.height;
|
: (transform as RectTransform).rect.height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public float preferredHeight { get { return minHeight; } }
|
public float preferredHeight { get { return minHeight; } }
|
||||||
@@ -59,13 +51,6 @@ namespace Cryville.Common.Unity.UI {
|
|||||||
|
|
||||||
public int layoutPriority { get { return 1; } }
|
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 CalculateLayoutInputHorizontal() { }
|
||||||
|
|
||||||
public void CalculateLayoutInputVertical() { }
|
public void CalculateLayoutInputVertical() { }
|
||||||
|
@@ -1,9 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using Cryville.Common.Unity.UI;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Cryville.Common.Unity.UI;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Cryville.Crtr.Browsing {
|
namespace Cryville.Crtr.Browsing {
|
||||||
public class PropertyCategoryPanel : MonoBehaviour {
|
public class PropertyCategoryPanel : MonoBehaviour {
|
||||||
@@ -37,7 +36,6 @@ namespace Cryville.Crtr.Browsing {
|
|||||||
var obj = GameObject.Instantiate<GameObject>(m_propertyPrefab);
|
var obj = GameObject.Instantiate<GameObject>(m_propertyPrefab);
|
||||||
obj.transform.SetParent(transform, false);
|
obj.transform.SetParent(transform, false);
|
||||||
obj.GetComponent<PropertyPanel>().Load(prop, target);
|
obj.GetComponent<PropertyPanel>().Load(prop, target);
|
||||||
obj.GetComponent<AspectRatioLayoutElement>().ContainerTransform = (RectTransform)transform;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user