You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HandController : MonoBehaviour
{
[Header("Cards In Hand")]
public List<Card> heldCards = new List<Card>();
[Header("Card Placement in Game Space")]
[SerializeField]
[Tooltip("Drag a transform element to here that will be the start point for placing cards")]
public Transform minPos;
[SerializeField]
[Tooltip("Drag a transform element to here that will be the end point for placing cards")]
private Transform maxPos;
// This should be done better by either using a getter or by not referencing this from the outside.
private List<Vector3> cardPositions = new List<Vector3>();
#region MonoBehaviors
// Start is called before the first frame update
void Start()
{
SetCardPositionsInHand();
}
// Update is called once per frame
void Update()
{
}
#endregion
/*****
* The purpose of this method is to place the cards that are in the
* player's hand down on the desktop. It first figures out how far
* apart each card should be based on the number of cards in hand.
* Then it places the cards on the desktop that distance apart. The
* rotation of the minPos element makes the card overlap look nice.
*
* minPos: Where on the screen to start placing cards
* maxPos: Where on the screen to stop placing cards
*/
public void SetCardPositionsInHand()
{
cardPositions.Clear();
// Calculate how far apart each card will be based on number of cards.
Vector3 distanceBetweenPoints = Vector3.zero;
if(heldCards.Count > 1 )
{
distanceBetweenPoints = (maxPos.position - minPos.position) / (heldCards.Count - 1);
}
// Place each card on the game surface
for(int i =0; i < heldCards.Count; i++)
{
cardPositions.Add(minPos.position + (distanceBetweenPoints * i));
heldCards[i].currentLocation = cardPositions[i];
heldCards[i].currentRotation = minPos.rotation;
heldCards[i].MoveToPoint(cardPositions[i], minPos.rotation);
heldCards[i].inHand = true;
heldCards[i].handPosition = i;
}
}
}