Cute_demon_attacks/meng_yao/Assets/script/A_Fight/cardBox.cs
2025-01-06 16:13:39 +08:00

100 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}
}
}