Files
Gazuaa/Assets/Scripts/Alignment.cs
2026-05-01 04:03:39 +09:00

30 lines
952 B
C#

using UnityEngine;
using UnityEngine.UI;
public class NewMonoBehaviourScript : MonoBehaviour
{
private GridLayoutGroup _gridLayoutGroup;
private RectTransform _rectTransform;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_gridLayoutGroup = GetComponent<GridLayoutGroup>();
_rectTransform = GetComponent<RectTransform>();
}
// Update is called once per frame
void Update()
{
var max =
(_rectTransform.rect.width / (_gridLayoutGroup.cellSize.x+_gridLayoutGroup.spacing.x)) *
(_rectTransform.rect.height / _gridLayoutGroup.cellSize.y+_gridLayoutGroup.spacing.y);
var current = transform.childCount;
if (current / max >= 0.8f)
{
_gridLayoutGroup.cellSize = new Vector2(_gridLayoutGroup.cellSize.x * 0.9f, _gridLayoutGroup.cellSize.y * 0.9f);
}
}
}