115 lines
4.5 KiB
C#
Raw Normal View History

2025-11-21 02:12:50 +08:00
using System;
2025-11-18 02:08:07 +08:00
using System.Collections;
using System.Collections.Generic;
2025-11-21 20:16:36 +08:00
using DG.Tweening;
2025-11-18 02:08:07 +08:00
using UnityEngine;
2025-11-21 02:12:50 +08:00
using UnityEngine.Splines;
2025-11-18 02:08:07 +08:00
public class CardManager : MonoBehaviour
{
2025-11-21 02:12:50 +08:00
[SerializeField] private Camera mainCamera;
// [SerializeField] private RectTransform dealCardPlace;
[SerializeField] private Transform cardContainer;
[SerializeField] private Collider2D areaCollider2D;
[SerializeField] private SplineContainer splineContainer;
private TurnManagerSingleton turnSingleton;
private CardManagerStateEnum cardManagerState;
private readonly List<Card> handCardList = new List<Card>();
private float moveAnimationDuration;
private float dragAnimationDuration;
2025-11-21 20:16:36 +08:00
private readonly Queue<Sequence> moveDeckAnimationQueue = new Queue<Sequence>();
private bool isMoveDeckAnimationPlaying;
2025-11-21 02:12:50 +08:00
// private Vector3 dealCardPlaceWorldPosition;
private enum CardManagerStateEnum
{
WAIT,
DEAL_CARD,
DROP_CARD,
}
2025-11-21 20:16:36 +08:00
public void SetupCardManager()
2025-11-21 02:12:50 +08:00
{
if (turnSingleton == null) turnSingleton = TurnManagerSingleton.Instance;
if (mainCamera == null) mainCamera = Camera.main;
}
2025-11-21 20:16:36 +08:00
2025-11-21 02:12:50 +08:00
private CardManagerStateEnum GetCardManagerState() => cardManagerState;
private void SetCardManagerState(CardManagerStateEnum state) => cardManagerState = state;
2025-11-21 20:16:36 +08:00
public void ShuffleCardToDeck(List<Sequence> ownedCardTweenList)
2025-11-20 20:02:38 +08:00
{
2025-11-21 20:16:36 +08:00
if (turnSingleton.GetNeedDebugLog()) turnSingleton.PrintMsg("CardManager", "动作切换", "开始洗牌");
while (ownedCardTweenList.Count > 0)
2025-11-21 02:12:50 +08:00
{
2025-11-21 20:16:36 +08:00
int randomIndex = UnityEngine.Random.Range(0, ownedCardTweenList.Count);
Sequence moveDeckAnimation = ownedCardTweenList[randomIndex];
moveDeckAnimationQueue.Enqueue(moveDeckAnimation);
ownedCardTweenList.Remove(moveDeckAnimation);
}
PlayNextMoveOwnedCardToDeck();
2025-11-20 20:02:38 +08:00
}
2025-11-21 20:16:36 +08:00
private void PlayNextMoveOwnedCardToDeck()
2025-11-20 20:02:38 +08:00
{
2025-11-21 20:16:36 +08:00
if (moveDeckAnimationQueue.Count == 0)
2025-11-21 02:12:50 +08:00
{
2025-11-21 20:16:36 +08:00
isMoveDeckAnimationPlaying = false;
return;
2025-11-21 02:12:50 +08:00
}
2025-11-21 20:16:36 +08:00
isMoveDeckAnimationPlaying = true;
Sequence seq = moveDeckAnimationQueue.Dequeue();
seq.OnComplete(PlayNextMoveOwnedCardToDeck);
seq.Play();
2025-11-20 20:02:38 +08:00
}
2025-11-21 20:16:36 +08:00
// public Card DealOneCard(List<Card> cardDeckList)
// {
// if (turnSingleton.GetNeedDebugLog()) turnSingleton.PrintMsg("CardManager", "动作切换", "开始发牌");
// SetCardManagerState(CardManagerStateEnum.DEAL_CARD);
// Card takeOutCard = cardDeckList[UnityEngine.Random.Range(0, cardDeckList.Count)];
// // create_a_card(takeOutCard);
// return takeOutCard;
// }
//
// private void ReadjustCardPosition(Card takeOutCard) // 重新调整卡牌位置
// {
// int handCardListCount = handCardList.Count;
// if (handCardListCount == 0) return;
// float cardSpacing = handCardListCount switch // 动态调整卡牌间距
// {
// <= 4 => 0.5f / (handCardListCount + 1),
// <= 5 => 0.75f / (handCardListCount + 1),
// _ => 1f / (handCardListCount + 1)
// };
// float firstCardPosition = 0.5f - (handCardListCount - 1) * cardSpacing / 2; // 获取第一个卡牌的位置
// MoveCard(firstCardPosition, cardSpacing, takeOutCard);
// }
//
// private void MoveCard(float firstCardPosition, float cardSpacing, Card takeOutCard)
// {
// Spline spline = splineContainer.Spline; // 获取曲线
// for (int i = 0; i < handCardList.Count; i++)
// {
// float position = firstCardPosition + i * cardSpacing;
// Vector3 cardWorldPosition = spline.EvaluatePosition(position); // 获取曲线指定位置的坐标
// cardWorldPosition += cardContainer.position;
// Vector3 forward = spline.EvaluateTangent(position); // 获取曲线指定的切线方向
// Vector3 up = spline.EvaluateUpVector(position); // 获取曲线指定的UP向量
// Vector3 upwards = Vector3.Cross(up, forward).normalized; // 切线和向上的夹角计算方向
// Quaternion rotation = Quaternion.LookRotation(up, upwards);
// takeOutCard.MoveCard(new Card.MoveMessage
// {
// GO_POSITION = cardWorldPosition,
// GO_ROTATION = rotation,
// GO_SCALE = Vector3.one,
// GO_LAYER_SORT_ORDER = i + 1,
// DURATION = moveAnimationDuration
// });
// }
// }
2025-11-21 02:12:50 +08:00
}