using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class GamePanel : BasePanel { //头像 public Button btnHead; //金币提现 public Button btnJBTX; //在线领金币 public Button btnZXLJB; //闯关领金币 public Button btnCGLJB; //邀请领金币 public Button btnYQLJB; //排行榜 public Button btnPHB; //展览 public Button btnEXH; //选择关卡 public Button btnLev; //技能1 public Button btnSkill1; private string hexColor="#6F6F6F"; //技能2 public Button btnSkill2; //人物名字 public Text txtUserName; //人物金币 public Text txtGold; //分数 public Text txtScore2; public int scoreInt = 0; //关卡 public Text txtLev2; //关卡数 public int levInt=1; //提示信息 public Text txtTips; public Text txtSkillTips; public GameObject imgSkill; //显示时间 public float displayDuration = 0.5f; //是否开启下一次按钮 private bool isCanButton = false; public override void Init() { imgSkill.SetActive(false); //获取所有关卡的名字 StartCoroutine(NetMgr.Instance.AllLevGet()); //每次进游戏更新一次玩家的礼包的数量 UpdatePlayerData(); UpdatePanel(GameDataMgr.Instance.player.customLev); btnHead.onClick.AddListener(() => { //显示用户信息界面 UIManager.Instance.ShowPanel(); }); btnJBTX.onClick.AddListener(() => { //显示金币提现界面 UIManager.Instance.ShowPanel(); }); btnZXLJB.onClick.AddListener(() => { //显示在线领金币界面 UIManager.Instance.ShowPanel(); }); btnCGLJB.onClick.AddListener(() => { //显示闯关领金币界面 UIManager.Instance.ShowPanel(); }); btnYQLJB.onClick.AddListener(() => { //显示邀请领金币界面 UIManager.Instance.ShowPanel(); }); btnPHB.onClick.AddListener(() => { //显示排行榜界面 UIManager.Instance.ShowPanel(); }); btnEXH.onClick.AddListener(() => { //显示展览界面 UIManager.Instance.ShowPanel(); btnEXH.gameObject.SetActive(false); }); btnLev.onClick.AddListener(() => { UIManager.Instance.ShowPanel(); }); //技能1点击事件 btnSkill1.onClick.AddListener(() => { if (!isCanButton) { if (GameMgr.Instance.skillOne == 100 && PlayerMain.Instance.isStart) { GameMgr.Instance.SkillOneDelPet(); UpdateColor(btnSkill1, hexColor); } else { ShowHintText("技能1未激活,无法使用"); } } }); //技能2点击事件 btnSkill2.onClick.AddListener(() => { if (!isCanButton) { if (GameMgr.Instance.skillTwo == 200 && PlayerMain.Instance.isStart) { PlayerMain.Instance.isStart = false; PlayerMain.Instance.isSkillTwoStart = true; UpdateColor(btnSkill2, hexColor); } else { ShowHintText("技能2未激活,无法使用"); } } }); } /// /// 更新玩家模型 /// private void UpdatePlayerData() { List playerList; List playerTempList; if (GameDataMgr.Instance.player.inviteGiftOpen.Count 0 && lev < 10) { txtLev2.text = "00" + levInt.ToString(); } else if (lev >= 10 && lev < 100) { txtLev2.text = "0" + levInt.ToString(); } else { txtLev2.text = levInt.ToString(); } txtScore2.text = 0.ToString(); GameMgr.Instance.skillOne = 0; GameMgr.Instance.skillTwo = 0; UpdateColor(btnSkill1,hexColor); UpdateColor(btnSkill2,hexColor); } //改变技能按钮颜色 public void UpdateButon(int skillOne,int skillTwo) { string colorc="#FFFFFF"; if (skillOne==100) { UpdateColor(btnSkill1,colorc); } if (skillTwo==200) { UpdateColor(btnSkill2,colorc); } } //改变单个按钮颜色 private void UpdateColor(Button btn,string colo) { // 定义一个Color变量来存储解析的颜色 Color newColor; // 使用ColorUtility.TryParseHtmlString将十六进制字符串解析为Color if (ColorUtility.TryParseHtmlString(colo, out newColor)) { // 设置Image组件的颜色 btn.image.color = newColor; } } // 显示提示文字并在一段时间后隐藏 void ShowHintText(string message) { isCanButton = true; // 设置提示文字内容并显示 txtSkillTips.text = message; imgSkill.SetActive(true); // 启动协程,在一段时间后隐藏提示文字 StartCoroutine(HideGameObject()); } // 协程:在一定时间后隐藏提示文字 private IEnumerator HideGameObject() { // 等待指定的时间 yield return new WaitForSeconds(displayDuration); // 隐藏提示文字 imgSkill.SetActive(false); isCanButton = false; } }