feat():大改前的提交,这个版本保存了所有冗余的代码
This commit is contained in:
114
Assets/Script/Gameplay/Player/PlayerCardsController.cs
Normal file
114
Assets/Script/Gameplay/Player/PlayerCardsController.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
using UnityEngine;
|
||||
using Quaternion = UnityEngine.Quaternion;
|
||||
using Vector3 = UnityEngine.Vector3;
|
||||
|
||||
namespace Gameplay.Player
|
||||
{
|
||||
public class PlayerCardsController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float radius = 2f; // 卡牌围绕玩家旋转的半径
|
||||
[SerializeField] private float rotationSpeed = 50f; // 卡牌旋转
|
||||
[SerializeField] private float highOffset = 1f; // 卡牌高度偏移
|
||||
public bool IsRotating = true; // 是否旋转卡牌
|
||||
[SerializeField] private GameObject cardPrefab; // 卡牌预制体
|
||||
|
||||
public List<CardViewer> Cards;
|
||||
private Transform playerTransform;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Cards != null)
|
||||
{
|
||||
//RotateCards();
|
||||
}
|
||||
}
|
||||
|
||||
// 生成卡牌实体
|
||||
// 生成的卡牌实体围绕着玩家旋转
|
||||
public void GenerateCards(List<Card> cards)
|
||||
{
|
||||
playerTransform = this.transform;
|
||||
Cards = new List<CardViewer>();
|
||||
for (int i = 0; i < cards.Count; i++)
|
||||
{
|
||||
float angle = i * (360f / cards.Count);
|
||||
float rad = angle * Mathf.Deg2Rad;
|
||||
Vector3 cardPosition = new Vector3(
|
||||
playerTransform.position.x + radius * Mathf.Cos(rad),
|
||||
playerTransform.position.y + highOffset,
|
||||
playerTransform.position.z + radius * Mathf.Sin(rad)
|
||||
);
|
||||
|
||||
GameObject cardObject = Instantiate(cardPrefab, cardPosition, Quaternion.identity);
|
||||
|
||||
Vector3 playerPosition = new Vector3(
|
||||
playerTransform.position.x,
|
||||
playerTransform.position.y + highOffset,
|
||||
playerTransform.position.z
|
||||
);
|
||||
Cards[i].transform.LookAt(playerPosition);
|
||||
|
||||
CardViewer cardViewer = cardObject.GetComponent<CardViewer>();
|
||||
cardViewer.SetCard(cards[i]);
|
||||
Cards.Add(cardViewer);
|
||||
}
|
||||
}
|
||||
|
||||
// 旋转已经生成的卡牌实体
|
||||
public void RotateCards()
|
||||
{
|
||||
if (!IsRotating) return;
|
||||
for (int i = 0; i < Cards.Count; i++)
|
||||
{
|
||||
float angle = i * (360f / Cards.Count) + Time.time * rotationSpeed;
|
||||
float rad = angle * Mathf.Deg2Rad;
|
||||
Vector3 cardPosition = new Vector3(
|
||||
playerTransform.position.x + radius * Mathf.Cos(rad),
|
||||
playerTransform.position.y + highOffset,
|
||||
playerTransform.position.z + radius * Mathf.Sin(rad)
|
||||
);
|
||||
Cards[i].transform.position = cardPosition;
|
||||
|
||||
Vector3 playerPosition = new Vector3(
|
||||
playerTransform.position.x,
|
||||
playerTransform.position.y + highOffset,
|
||||
playerTransform.position.z
|
||||
);
|
||||
|
||||
Cards[i].transform.LookAt(playerPosition);
|
||||
// 卡牌绕着y轴旋转180度,从而让卡牌正面朝向玩家
|
||||
Cards[i].transform.Rotate(0, 180, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void StopRotatingCards()
|
||||
{
|
||||
IsRotating = false;
|
||||
}
|
||||
|
||||
public void StartRotatingCards()
|
||||
{
|
||||
IsRotating = true;
|
||||
}
|
||||
|
||||
// 删除卡牌实体
|
||||
public void DeleteCards(CardViewer card)
|
||||
{
|
||||
Cards.Remove(card);
|
||||
Destroy(card.gameObject);
|
||||
}
|
||||
|
||||
public void ClearCards()
|
||||
{
|
||||
foreach (var card in Cards)
|
||||
{
|
||||
Destroy(card.gameObject);
|
||||
}
|
||||
|
||||
Cards.Clear();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user