어떻게든 부채꼴 모양으로 카드 배열을 하려 하는데 마지막 5장이 일렬로 만들어지고,
그 이후 생성된 카드도 계속 가로로만 배치됨....
원하는 상태가 중점을 기준으로 계속 부채꼴로 늘어나가는 형식인데 안되네;;
코드를 안썼구나;; 수정
public class CharacterDeckManager : MonoBehaviour
{
[Header("References")]
public Transform deckParent; // 자기 자신을 할당
public GameObject cardPrefab;
public List<GameObject> cardsInHand = new List<GameObject>();
void Start()
{
// 시작할 때 테스트 카드 5개 생성
for (int i = 0; i < 5; i++)
{
GameObject newCard = Instantiate(cardPrefab, deckParent);
cardsInHand.Add(newCard);
}
LayoutCards();
}
void LayoutCards()
{
Debug.Log("+ LayoutCards 실행됨! 카드 개수: " + cardsInHand.Count);
int count = cardsInHand.Count;
if (count == 0) return;
// 카드 간격과 곡선 높이 증가 (더 둥글게 배치)
float spacing = Mathf.Lerp(100f, 140f, 1f / (count * 0.3f + 1f));
float fanAngle = 25f; // 회전 각도 증가
float arcHeight = Mathf.Lerp(80f, 150f, count / 10f); // 높이 증가
for (int i = 0; i < count; i++)
{
float normalizedPos = count > 1 ? (i / (float)(count - 1) * 2 - 1) : 0;
float xPos = normalizedPos * (spacing * count / 2);
float yPos = -Mathf.Pow(normalizedPos, 2) * arcHeight;
float angle = normalizedPos * fanAngle;
RectTransform rt = cardsInHand[i].GetComponent<RectTransform>();
rt.anchoredPosition = new Vector2(xPos, yPos);
rt.localRotation = Quaternion.Euler(0, 0, angle);
// 중앙 카드가 가장 앞쪽에 오도록 정렬
int sortOrder = Mathf.RoundToInt((1 - Mathf.Abs(normalizedPos)) * count);
cardsInHand[i].transform.SetSiblingIndex(count - sortOrder); // ⭐ 수정된 부분
Debug.Log($"+ {i}번 카드 | X: {xPos}, Y: {yPos}, 회전: {angle}, 정렬순서: {count - sortOrder}");
}
}
void Update()
{
// L 키를 눌러 수동으로 카드 정렬 실행 (테스트용)
if (Input.GetKeyDown(KeyCode.L))
{
LayoutCards();
Debug.Log("+ 수동으로 LayoutCards() 실행됨!");
}
}
}
}
n각형 정점 위치에 카드를 올린다고 생각해봐
확실히 좋은 생각인거같아. 가로로 쭉 배치되는걸 해결하면 그렇게 해볼게. 고마워!
댓글 답변도 gpt한테 물어본것같냐왜 ㅋㅋㅋㅋㅋ