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.

143 lines
4.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Card : MonoBehaviour
{
#region Card Data
[Header("Card Data")]
[SerializeField]
private CardScriptableObject cardSO;
// Card stats are used internally and can change during game play
// The ScriptableObject holds the base stats and it will not change
// during game play.
private int currentHealth;
private int attackPower;
private int manaCost;
#endregion
#region Card UI
// References to UI elements on the card
[Header("Card Stats UI")]
[Tooltip("Drag UI element for card HEALTH to here ")]
[SerializeField]
private TMP_Text healthText;
[Tooltip("Drag UI element for card ATTACK to here ")]
[SerializeField]
private TMP_Text attackText;
[Tooltip("Drag UI element for card MANA to here ")]
[SerializeField]
private TMP_Text costText;
[Header("Card Description UI")]
[Tooltip("Drag UI element for card NAME to here ")]
[SerializeField]
private TMP_Text nameText;
[Tooltip("Drag UI element for card DESCRIPTION to here ")]
[SerializeField]
private TMP_Text actionDescriptionText;
[Tooltip("Drag UI element for card LORE to here ")]
[SerializeField]
private TMP_Text loreText;
[Header("Card Image UI")]
[SerializeField]
private Image characterArt;
[SerializeField]
private Image bgArt;
#endregion
#region Animation
// Hold location of where this card should display on the game surface.
[Header("Card Animation")]
[SerializeField]
private float moveSpeed = 1.5f;
[SerializeField]
private float rotateSpeed = 540.0f;
public Vector3 currentLocation;
public Quaternion currentRotation;
// Animation will move from current Transform to the values
// contained in these two variables.
private Vector3 movetoLocation;
private Quaternion movetoRotation;
#endregion
public bool inHand;
public int handPosition; // index of where the card is in the hand (brittle architecture here)
#region MonoBehaviors
// Start is called before the first frame update
void Start()
{
SetupCard();
}
// Update is called once per frame
void Update()
{
transform.position = Vector3.Lerp(transform.position, movetoLocation, moveSpeed * Time.deltaTime);
transform.rotation = Quaternion.RotateTowards(transform.rotation, movetoRotation, rotateSpeed * Time.deltaTime);
}
private void OnMouseOver()
{
if(inHand)
{
Vector3 newLocation = currentLocation;
MoveToPoint(newLocation + new Vector3(0.0f, 1.0f, 0.5f), Quaternion.identity);
}
}
private void OnMouseExit()
{
if(inHand)
{
MoveToPoint(currentLocation, currentRotation);
}
}
#endregion
/*****
* This method loads the card data from the referenced ScriptableObject
* and updates properties and display for this card object.
*/
public void SetupCard()
{
// Set the card's initial stats.
currentHealth = cardSO.currentHealth;
attackPower = cardSO.attackPower;
manaCost = cardSO.manaCost;
// Show the card's stats on the card display
healthText.text = currentHealth.ToString();
attackText.text = attackPower.ToString();
costText.text = manaCost.ToString();
// Show the card's description on the card display
nameText.text = cardSO.cardName.ToString();
actionDescriptionText.text = cardSO.actionDescription.ToString();
loreText.text = cardSO.cardLore.ToString();
// Show the card's images on the card display
characterArt.sprite = cardSO.characterSprite;
bgArt.sprite = cardSO.bgSprite;
}
/*****
* This method is used move a card around on the game screen. It will move
* the card from its current location and rotation to the provided location
* and rotation.
*/
public void MoveToPoint(Vector3 moveCardToLocation, Quaternion rotToMatch)
{
movetoLocation = moveCardToLocation;
movetoRotation = rotToMatch;
}
}