74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
public class Card : MonoBehaviour
|
|
{
|
|
// ========= serializeField ========
|
|
[SerializeField] private int ID;
|
|
[SerializeField] private int instanceID;
|
|
|
|
// ========= private =========
|
|
private Collider2D areaCollider2D;
|
|
private TurnManagerSingleton turnSingleton;
|
|
private SpriteRenderer spriteRender;
|
|
private Canvas canvas;
|
|
private SpriteRenderer cardBackgroundUI;
|
|
private CardTransformFromHand cardTransformFromHand = new CardTransformFromHand();
|
|
|
|
private struct CardTransformFromHand // 存储卡牌处于手中时的位置信息
|
|
{
|
|
public Vector3 POSITION;
|
|
public Quaternion ROTATION;
|
|
public Vector3 SCALE;
|
|
public int LAYER_SORT_ORDER;
|
|
}
|
|
|
|
public void SetAreaCollider2D(Collider2D collider2) => areaCollider2D = collider2;
|
|
public void UnSetAreaCollider2D() => areaCollider2D = null;
|
|
|
|
public void SetupCard(int id)
|
|
{
|
|
if (!turnSingleton) turnSingleton = TurnManagerSingleton.Instance;
|
|
if (!spriteRender) spriteRender = GetComponent<SpriteRenderer>();
|
|
if (!cardBackgroundUI) cardBackgroundUI = transform.GetChild(0).GetComponent<SpriteRenderer>();
|
|
if (!canvas) canvas = transform.GetChild(1).GetComponent<Canvas>();
|
|
cardTransformFromHand.SCALE = transform.localScale;
|
|
instanceID = id;
|
|
}
|
|
|
|
public Sequence GetTweenMoveCardGoDeck(Vector3 doGoPosition, Quaternion doGoRotation, Vector3 doGoScale, float doGoDuration)
|
|
{
|
|
transform.localScale = Vector3.zero;
|
|
gameObject.SetActive(true);
|
|
Sequence seq = DOTween.Sequence();
|
|
seq.Pause();
|
|
seq.Join(transform.DOMove(doGoPosition, doGoDuration));
|
|
seq.Join(transform.DOScale(doGoScale, doGoDuration));
|
|
seq.Join(transform.DORotateQuaternion(doGoRotation, doGoDuration));
|
|
return seq;
|
|
}
|
|
|
|
|
|
public Sequence GetTweenMoveCardGoHand(Vector3 movePosition, Quaternion doRotation, float doDuration, int doLayerSortOrder)
|
|
{
|
|
movePosition.z = -doLayerSortOrder * 0.5f;
|
|
spriteRender.sortingOrder = doLayerSortOrder * 3;
|
|
cardBackgroundUI.sortingOrder = doLayerSortOrder * 3 - 1;
|
|
canvas.sortingOrder = doLayerSortOrder * 3 + 1;
|
|
Sequence seq = DOTween.Sequence();
|
|
seq.Pause();
|
|
seq.Join(transform.DOMove(movePosition, doDuration));
|
|
// seq.Join(transform.DOScale(doScale, duration));
|
|
seq.Join(transform.DORotateQuaternion(doRotation, doDuration));
|
|
seq.OnComplete(() => // 记录默认数值
|
|
{
|
|
cardTransformFromHand.POSITION = movePosition;
|
|
cardTransformFromHand.ROTATION = doRotation;
|
|
cardTransformFromHand.LAYER_SORT_ORDER = doLayerSortOrder;
|
|
});
|
|
return seq;
|
|
}
|
|
} |