100 lines
2.7 KiB
C#
100 lines
2.7 KiB
C#
using DG.Tweening;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
|
||
public class cardBox : Base
|
||
{
|
||
public static cardBox instance;
|
||
[HideInInspector] public int mengyaoNumber = 0;//萌妖数量
|
||
[HideInInspector] public int inPlaceNumber = 0;
|
||
[Header("开始按钮obj")] public GameObject btnObj;
|
||
|
||
[Header("怪物信息提示按钮obj")] public GameObject IconTipObj;
|
||
|
||
// [Header("萌妖卡数据列表")] public List<MengyaoCardData> mengyaoCardDataList = new List<MengyaoCardData>();
|
||
|
||
[Header("萌妖卡生成父节点")] public Transform parentPos;
|
||
|
||
public float scaleUpDuration = 0.5f; // 缩放动画时长
|
||
public float fadeInDuration = 0.5f; // 淡入动画时长
|
||
|
||
// ID到萌妖卡预制体的映射字典
|
||
private Dictionary<string, GameObject> IDTomangyaoPrefab = new Dictionary<string, GameObject>();
|
||
|
||
|
||
//public Dictionary<string,>
|
||
|
||
|
||
[HideInInspector] public List<GameObject> card = new List<GameObject>();
|
||
private void Awake()
|
||
{
|
||
instance = this;
|
||
|
||
|
||
}
|
||
|
||
void Start()
|
||
{
|
||
if (btnObj == null)
|
||
{
|
||
Debug.LogError("btnObj==null");
|
||
return;
|
||
}
|
||
|
||
btnObj.SetActive(false);
|
||
Init();
|
||
mengyaoNumber = Base.GlobalObj.GetComponent<gameGlobal>().CarryCardId.Count;
|
||
}
|
||
|
||
public void ChangeInPlaceNumber(int number)
|
||
{
|
||
inPlaceNumber += number;
|
||
if (inPlaceNumber == mengyaoNumber)
|
||
{
|
||
gameGlobal.GameStart();
|
||
//Debug.Log("布置完成");
|
||
btnObj.SetActive(true);
|
||
btnObj.GetComponent<Button>().onClick.AddListener(() =>
|
||
{
|
||
IconTipObj.gameObject.SetActive(true);
|
||
btnObj.SetActive(false);
|
||
|
||
});
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 根据CarryCardId列表生成对应的萌妖卡牌
|
||
/// </summary>
|
||
void Init()
|
||
{
|
||
// 获取 CarryCardId 列表
|
||
List<string> carryCardIdList = Base.GlobalObj.GetComponent<gameGlobal>().CarryCardId;
|
||
|
||
foreach (string id in carryCardIdList)
|
||
{
|
||
mengyaoInfo info= MY_Infos.instane.GetMY(id);
|
||
if (info != null)
|
||
{
|
||
|
||
// 实例化预制体,设置父节点为 parentPos
|
||
GameObject card = Instantiate(info.cardprefab, parentPos);
|
||
//card.GetComponent<enemy>().enemyId = id;
|
||
//this.card.Add(card);
|
||
// 确保卡牌的缩放为0,准备进行放大动画
|
||
card.transform.localScale = Vector3.zero;
|
||
|
||
// 确保卡牌的位置为父节点的本地位置
|
||
card.transform.localPosition = Vector3.zero;
|
||
// 播放放大动画
|
||
card.transform.DOScale(Vector3.one, scaleUpDuration).SetEase(Ease.OutBack);
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|