2025-11-20 20:02:38 +08:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using DG.Tweening;
|
|
|
|
|
using TMPro.EditorUtilities;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.Android;
|
|
|
|
|
using UnityEngine.Splines;
|
|
|
|
|
|
|
|
|
|
public class CardManager2 : MonoBehaviour
|
|
|
|
|
{
|
2025-11-22 23:24:51 +08:00
|
|
|
// ======== serializeField ========
|
|
|
|
|
[SerializeField] private int defaultDeckNumber = 21; // 默认牌组数量
|
|
|
|
|
[SerializeField] private int defaultCardNumber = 5; // 默认手牌数量
|
|
|
|
|
|
|
|
|
|
// [SerializeField] private int maxCardNumber = 9; // 最大卡牌数量
|
|
|
|
|
[SerializeField] private List<GameObject> cardPrefabs;
|
|
|
|
|
[SerializeField] private SplineContainer splineContainer;
|
|
|
|
|
[SerializeField] private RectTransform dealCardPlace;
|
|
|
|
|
[SerializeField] private Camera mainCamera;
|
|
|
|
|
[SerializeField] private Transform cardContainer;
|
|
|
|
|
[SerializeField] private float cardShuffleDuration = 0.25f;
|
|
|
|
|
[SerializeField] private float cardDropDuration = 0.2f;
|
|
|
|
|
|
|
|
|
|
// ======== private ========
|
|
|
|
|
// private readonly List<CardHandler> hand_card_list = new List<CardHandler>();
|
|
|
|
|
private readonly List<Card> handCardList = new();
|
|
|
|
|
private Vector3 deal_card_point_world_position;
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
RectTransformUtility.ScreenPointToWorldPointInRectangle(
|
|
|
|
|
rect: dealCardPlace,
|
|
|
|
|
screenPoint: dealCardPlace.position,
|
|
|
|
|
cam: mainCamera,
|
|
|
|
|
out deal_card_point_world_position);
|
|
|
|
|
REGISTER_EVENT_SELF_TURN_START();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void REGISTER_EVENT_SELF_TURN_START() // 系统开始乙方回合
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(coroutine());
|
|
|
|
|
|
|
|
|
|
IEnumerator coroutine()
|
|
|
|
|
{
|
|
|
|
|
for (var i = 0; i < defaultCardNumber; i++)
|
|
|
|
|
{
|
|
|
|
|
create_a_card(0.25f);
|
|
|
|
|
yield return new WaitForSeconds(0.25f);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void create_a_card(float duration)
|
|
|
|
|
{
|
|
|
|
|
GameObject _card = Instantiate<GameObject>(
|
|
|
|
|
cardPrefabs[UnityEngine.Random.Range(0, cardPrefabs.Count)],
|
|
|
|
|
position: deal_card_point_world_position,
|
|
|
|
|
rotation: Quaternion.identity,
|
|
|
|
|
parent: cardContainer);
|
|
|
|
|
_card.SetActive(true);
|
|
|
|
|
_card.gameObject.name = $"Card_{handCardList.Count}";
|
|
|
|
|
Card cardComponent = _card.GetComponent<Card>();
|
|
|
|
|
handCardList.Add(cardComponent);
|
|
|
|
|
draw_a_card(duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void draw_a_card(float duration)
|
|
|
|
|
{
|
|
|
|
|
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; // 获取第一个卡牌的位置
|
|
|
|
|
Spline spline = splineContainer.Spline; // 获取曲线
|
|
|
|
|
draw_card();
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
void draw_card()
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < handCardListCount; 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);
|
|
|
|
|
handCardList[i].GetComponent<Card>().GetTweenMoveCardGoHand(movePosition: cardWorldPosition, doRotation: rotation,
|
|
|
|
|
doDuration: duration, doLayerSortOrder: i + 1, cardContainer: cardContainer);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-20 20:02:38 +08:00
|
|
|
}
|