115 lines
4.5 KiB
C#
115 lines
4.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.Splines;
|
|
|
|
public class CardManager : MonoBehaviour
|
|
{
|
|
[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;
|
|
private readonly Queue<Sequence> moveDeckAnimationQueue = new Queue<Sequence>();
|
|
private bool isMoveDeckAnimationPlaying;
|
|
// private Vector3 dealCardPlaceWorldPosition;
|
|
|
|
private enum CardManagerStateEnum
|
|
{
|
|
WAIT,
|
|
DEAL_CARD,
|
|
DROP_CARD,
|
|
}
|
|
|
|
public void SetupCardManager()
|
|
{
|
|
if (turnSingleton == null) turnSingleton = TurnManagerSingleton.Instance;
|
|
if (mainCamera == null) mainCamera = Camera.main;
|
|
}
|
|
|
|
|
|
private CardManagerStateEnum GetCardManagerState() => cardManagerState;
|
|
private void SetCardManagerState(CardManagerStateEnum state) => cardManagerState = state;
|
|
|
|
public void ShuffleCardToDeck(List<Sequence> ownedCardTweenList)
|
|
{
|
|
if (turnSingleton.GetNeedDebugLog()) turnSingleton.PrintMsg("CardManager", "动作切换", "开始洗牌");
|
|
while (ownedCardTweenList.Count > 0)
|
|
{
|
|
int randomIndex = UnityEngine.Random.Range(0, ownedCardTweenList.Count);
|
|
Sequence moveDeckAnimation = ownedCardTweenList[randomIndex];
|
|
moveDeckAnimationQueue.Enqueue(moveDeckAnimation);
|
|
ownedCardTweenList.Remove(moveDeckAnimation);
|
|
}
|
|
|
|
PlayNextMoveOwnedCardToDeck();
|
|
}
|
|
|
|
private void PlayNextMoveOwnedCardToDeck()
|
|
{
|
|
if (moveDeckAnimationQueue.Count == 0)
|
|
{
|
|
isMoveDeckAnimationPlaying = false;
|
|
return;
|
|
}
|
|
|
|
isMoveDeckAnimationPlaying = true;
|
|
Sequence seq = moveDeckAnimationQueue.Dequeue();
|
|
seq.OnComplete(PlayNextMoveOwnedCardToDeck);
|
|
seq.Play();
|
|
}
|
|
|
|
// 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
|
|
// });
|
|
// }
|
|
// }
|
|
} |