CutePet/Assets/Scripts/GameScene/Object/LevItem2.cs
2024-10-25 11:10:04 +08:00

83 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;
/// <summary>
/// 关卡信息,关卡状态
/// </summary>
public class LevItem2 : MonoBehaviour
{
//按钮本身
public Button btnSelf;
//名字
public Text txtName;
//关卡id
private int levId;
//按钮锁
public Image imgLock;
//本关是否通关
private bool isLock=false;
void Start()
{
btnSelf.onClick.AddListener(() =>
{
if (isLock)
{
GameDataMgr.Instance.levRankMsg.openId = GameDataMgr.Instance.player.openId;
GameDataMgr.Instance.levRankMsg.id = levId;
StartCoroutine(NetMgr.Instance.LevPetInfoPost(GameDataMgr.Instance.levRankMsg));
//更新游戏界面数据
UIManager.Instance.GetPanel<GamePanel>().UpdatePanel(levId);
}
});
}
/// <summary>
/// 初始化方法 用于 更新按钮显示相关
/// </summary>
/// <param name="lev">关卡状态信息</param>
public void InitInfo(AllLevData lev)
{
//记录当前关卡id
levId = lev.levId;
if (levId==1)
{
isLock=true;
}
else
{
if (levId<=GameDataMgr.Instance.player.customLev+1)
{
isLock = true;
}
else
{
isLock = false;
}
}
//更新按钮上的信息
txtName.text = levId.ToString();
//加载图集
SpriteAtlas sa = Resources.Load<SpriteAtlas>("Atlas/AllLevPanel");
if (!isLock)
{
btnSelf.image.sprite = sa.GetSprite("icn_taxoff");
imgLock.gameObject.SetActive(true);
}
else
{
btnSelf.image.sprite = sa.GetSprite("icn_taxon");
imgLock.gameObject.SetActive(false);
}
}
}