멀티플레이 제작 끝

This commit is contained in:
김도환
2026-05-01 07:06:29 +09:00
parent a36270f77a
commit ad7caf1e71
23 changed files with 2212 additions and 96 deletions

View File

@@ -1,29 +1,42 @@
using UnityEngine;
using UnityEngine.UI;
public class NewMonoBehaviourScript : MonoBehaviour
public class Alignment : 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 (transform.childCount == 0) return;
// 1. 가로, 세로에 각각 '온전히' 몇 개가 들어갈 수 있는지 계산 (내림 처리)
// (괄호 위치를 정확히 맞추었습니다!)
float cols = Mathf.Floor(_rectTransform.rect.width / (_gridLayoutGroup.cellSize.x + _gridLayoutGroup.spacing.x));
float rows = Mathf.Floor(_rectTransform.rect.height / (_gridLayoutGroup.cellSize.y + _gridLayoutGroup.spacing.y));
// 최소 1줄은 보장되도록 안전장치
if (cols < 1) cols = 1;
if (rows < 1) rows = 1;
// 2. 현재 화면에 들어갈 수 있는 최대 아바타 개수
float max = cols * rows;
float current = transform.childCount;
// 3. 꽉 차기 직전(80% 이상)이면 셀 사이즈를 10%씩 축소
if (current / max >= 0.8f)
{
_gridLayoutGroup.cellSize = new Vector2(_gridLayoutGroup.cellSize.x * 0.9f, _gridLayoutGroup.cellSize.y * 0.9f);
_gridLayoutGroup.cellSize = new Vector2(
_gridLayoutGroup.cellSize.x * 0.9f,
_gridLayoutGroup.cellSize.y * 0.9f
);
}
}
}
}