Add project files.

This commit is contained in:
2022-09-30 17:32:21 +08:00
parent df69e65c88
commit e8e36b83bd
561 changed files with 40626 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
using UnityEngine;
using UnityEngine.UI;
namespace Cryville.Common.Unity.UI {
public class LayoutAspectRatioFitter : MonoBehaviour {
[SerializeField]
private float m_aspectRatioPerElement = 1;
public float AspectRatioPerElement {
get { return m_aspectRatioPerElement; }
set { m_aspectRatioPerElement = value; }
}
AspectRatioFitter aspectRatioFitter;
DockAspectRatioLayoutGroup syncTo;
int axis;
#pragma warning disable IDE0051
void Awake() {
aspectRatioFitter = GetComponent<AspectRatioFitter>();
if (aspectRatioFitter == null) {
syncTo = GetComponentInParent<DockAspectRatioLayoutGroup>();
axis = (syncTo.DockSide == DockLayoutGroup.Side.Top || syncTo.DockSide == DockLayoutGroup.Side.Bottom) ? 1 : 0;
}
else axis = aspectRatioFitter.aspectMode == AspectRatioFitter.AspectMode.WidthControlsHeight ? 1 : 0;
OnTransformChildrenChanged();
}
void OnTransformChildrenChanged() {
float r;
switch (axis) {
case 0:
r = AspectRatioPerElement * transform.childCount;
break;
case 1:
r = AspectRatioPerElement / transform.childCount;
break;
default: return;
}
if (aspectRatioFitter != null) aspectRatioFitter.aspectRatio = r;
else syncTo.DockAspectRatio = r;
}
#pragma warning restore IDE0051
}
}