177 lines
6.0 KiB
C#
177 lines
6.0 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
public class LobbyCenterProfileUI : MonoBehaviour
|
|
{
|
|
public ProfileCard[] arr_profileCard;
|
|
|
|
int curGirl = 0;
|
|
bool isAnimating = false;
|
|
|
|
// 위치 프리셋 (UI 좌표)
|
|
Vector2 posLeft = new Vector2(-772, 178.3f);
|
|
Vector2 posCenter = new Vector2(0, 178.3f);
|
|
Vector2 posRight = new Vector2(772, 178.3f);
|
|
float scaleCenter = 1f;
|
|
float scaleSide = 0.7f;
|
|
|
|
public float animDuration = 0.3f;
|
|
|
|
public void Set()
|
|
{
|
|
if (curGirl == 0) curGirl = SaveMgr.Ins.Get_SelectGirlID();
|
|
else
|
|
{
|
|
if (arr_profileCard[1].IsObtain())
|
|
SaveMgr.Ins.Set_SelectGirlID(curGirl);
|
|
}
|
|
|
|
var pre_girl = curGirl - 1;
|
|
if (pre_girl <= 0) pre_girl = 8;
|
|
arr_profileCard[0].Set(pre_girl);
|
|
|
|
arr_profileCard[1].Set(curGirl);
|
|
|
|
var next_girl = curGirl + 1;
|
|
if (next_girl > 8) next_girl = 1;
|
|
arr_profileCard[2].Set(next_girl);
|
|
}
|
|
|
|
public void OnClick_Arrow(int dir)
|
|
{
|
|
if (isAnimating) return;
|
|
StartCoroutine(Co_MoveCard(dir));
|
|
}
|
|
|
|
IEnumerator Co_MoveCard(int dir)
|
|
{
|
|
isAnimating = true;
|
|
|
|
float elapsed = 0f;
|
|
|
|
RectTransform left = arr_profileCard[0].rect;
|
|
RectTransform center = arr_profileCard[1].rect;
|
|
RectTransform right = arr_profileCard[2].rect;
|
|
|
|
ProfileCard newCard = null;
|
|
RectTransform movingRect = null;
|
|
|
|
if (dir == 1) // 오른쪽으로 이동
|
|
{
|
|
newCard = arr_profileCard[0];
|
|
movingRect = newCard.rect;
|
|
movingRect.anchoredPosition = posRight + new Vector2(500, 0);
|
|
movingRect.localScale = Vector3.one * scaleSide;
|
|
|
|
Vector2 startPosNew = movingRect.anchoredPosition;
|
|
Vector2 startPosC = center.anchoredPosition;
|
|
Vector2 startPosR = right.anchoredPosition;
|
|
|
|
Vector2 targetPosNew = posRight;
|
|
Vector2 targetPosC = posLeft;
|
|
Vector2 targetPosR = posCenter;
|
|
|
|
Vector3 startScaleNew = movingRect.localScale;
|
|
Vector3 startScaleC = center.localScale;
|
|
Vector3 startScaleR = right.localScale;
|
|
|
|
Vector3 targetScaleNew = Vector3.one * scaleSide;
|
|
Vector3 targetScaleC = Vector3.one * scaleSide;
|
|
Vector3 targetScaleR = Vector3.one * scaleCenter;
|
|
|
|
while (elapsed < animDuration)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
float t = Mathf.Clamp01(elapsed / animDuration);
|
|
|
|
movingRect.anchoredPosition = Vector2.Lerp(startPosNew, targetPosNew, t);
|
|
center.anchoredPosition = Vector2.Lerp(startPosC, targetPosC, t);
|
|
right.anchoredPosition = Vector2.Lerp(startPosR, targetPosR, t);
|
|
|
|
movingRect.localScale = Vector3.Lerp(startScaleNew, targetScaleNew, t);
|
|
center.localScale = Vector3.Lerp(startScaleC, targetScaleC, t);
|
|
right.localScale = Vector3.Lerp(startScaleR, targetScaleR, t);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
// 보정
|
|
movingRect.anchoredPosition = targetPosNew;
|
|
center.anchoredPosition = targetPosC;
|
|
right.anchoredPosition = targetPosR;
|
|
|
|
movingRect.localScale = targetScaleNew;
|
|
center.localScale = targetScaleC;
|
|
right.localScale = targetScaleR;
|
|
|
|
// 배열 회전 (0→1, 1→2, 2→0)
|
|
var temp = arr_profileCard[0];
|
|
arr_profileCard[0] = arr_profileCard[1];
|
|
arr_profileCard[1] = arr_profileCard[2];
|
|
arr_profileCard[2] = temp;
|
|
|
|
curGirl = curGirl + 1;
|
|
if (curGirl > 8) curGirl = 1;
|
|
}
|
|
else if (dir == -1) // 왼쪽으로 이동
|
|
{
|
|
newCard = arr_profileCard[2];
|
|
movingRect = newCard.rect;
|
|
movingRect.anchoredPosition = posLeft + new Vector2(-500, 0);
|
|
movingRect.localScale = Vector3.one * scaleSide;
|
|
|
|
Vector2 startPosNew = movingRect.anchoredPosition;
|
|
Vector2 startPosL = left.anchoredPosition;
|
|
Vector2 startPosC = center.anchoredPosition;
|
|
|
|
Vector2 targetPosNew = posLeft;
|
|
Vector2 targetPosL = posCenter;
|
|
Vector2 targetPosC = posRight;
|
|
|
|
Vector3 startScaleNew = movingRect.localScale;
|
|
Vector3 startScaleL = left.localScale;
|
|
Vector3 startScaleC = center.localScale;
|
|
|
|
Vector3 targetScaleNew = Vector3.one * scaleSide;
|
|
Vector3 targetScaleL = Vector3.one * scaleCenter;
|
|
Vector3 targetScaleC = Vector3.one * scaleSide;
|
|
|
|
while (elapsed < animDuration)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
float t = Mathf.Clamp01(elapsed / animDuration);
|
|
|
|
movingRect.anchoredPosition = Vector2.Lerp(startPosNew, targetPosNew, t);
|
|
left.anchoredPosition = Vector2.Lerp(startPosL, targetPosL, t);
|
|
center.anchoredPosition = Vector2.Lerp(startPosC, targetPosC, t);
|
|
|
|
movingRect.localScale = Vector3.Lerp(startScaleNew, targetScaleNew, t);
|
|
left.localScale = Vector3.Lerp(startScaleL, targetScaleL, t);
|
|
center.localScale = Vector3.Lerp(startScaleC, targetScaleC, t);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
// 보정
|
|
movingRect.anchoredPosition = targetPosNew;
|
|
left.anchoredPosition = targetPosL;
|
|
center.anchoredPosition = targetPosC;
|
|
|
|
movingRect.localScale = targetScaleNew;
|
|
left.localScale = targetScaleL;
|
|
center.localScale = targetScaleC;
|
|
|
|
// 배열 회전 (0→2, 1→0, 2→1)
|
|
var temp = arr_profileCard[2];
|
|
arr_profileCard[2] = arr_profileCard[1];
|
|
arr_profileCard[1] = arr_profileCard[0];
|
|
arr_profileCard[0] = temp;
|
|
|
|
curGirl = curGirl - 1;
|
|
if (curGirl <= 0) curGirl = 8;
|
|
}
|
|
|
|
Set();
|
|
isAnimating = false;
|
|
}
|
|
} |