一款基于卡牌的塔防游戏,类似于 Supercell 的《皇室战争》的游戏玩法(简化形式), 可以与“非智能”AI 进行比赛。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

56 行
1.6 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;
namespace UnityRoyale
{
public class Card : MonoBehaviour, IDragHandler, IPointerUpHandler, IPointerDownHandler
{
public UnityAction<int, Vector2> OnDragAction;
public UnityAction<int> OnTapDownAction, OnTapReleaseAction;
[HideInInspector] public int cardId;
[HideInInspector] public CardData cardData;
public Image portraitImage; //Inspector-set reference
private CanvasGroup canvasGroup;
private void Awake()
{
canvasGroup = GetComponent<CanvasGroup>();
}
//called by CardManager, it feeds CardData so this card can display the placeable's portrait
public void InitialiseWithData(CardData cData)
{
cardData = cData;
portraitImage.sprite = cardData.cardImage;
}
public void OnPointerDown(PointerEventData pointerEvent)
{
if(OnTapDownAction != null)
OnTapDownAction(cardId);
}
public void OnDrag(PointerEventData pointerEvent)
{
if(OnDragAction != null)
OnDragAction(cardId, pointerEvent.delta);
}
public void OnPointerUp(PointerEventData pointerEvent)
{
if(OnTapReleaseAction != null)
OnTapReleaseAction(cardId);
}
public void ChangeActiveState(bool isActive)
{
canvasGroup.alpha = (isActive) ? .05f : 1f;
}
}
}