using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System; using DG.Tweening; /// /// 右上角菜单 /// public class UI_TiliMenu : MonoBehaviour { private static UI_TiliMenu pInit = null; private GameObject btnTiliAdd = null; private GameObject resEffect = null; private Text txt_Tili = null; private const float _spaceTime = 0.5f; private float _curTime = 0; private int lastTili = 0; private int lastCash = 0; private int lastGold = 0; private Text txt_Gem = null; private Text txt_Gold = null; private GameObject btnGemAdd = null; private GameObject btnGoldAdd = null; private GameObject gemEffect = null; private GameObject goldEffect = null; private int MaxTili = 0; /// /// 单例 /// public static UI_TiliMenu Instance { get { return pInit; } } /// /// 创建 /// /// 父Transform public static void Create(Transform parentTran,bool show = false) { if (show == false) { return; } ResourceHelper.Instance.LoadAssetBundle("UI_TiliMenu", (ab) => { if (ab != null) { GameObject uiObj = Instantiate(ab.LoadAsset("UI_TiliMenu"), parentTran); pInit = uiObj.AddComponent(); pInit.Init(); } }); } /// /// 初始化 /// private void Init() { _curTime = _spaceTime; txt_Gem = transform.Find("GemBG/txt_Gem").GetComponent(); txt_Gold = transform.Find("GoldBG/txt_Gold").GetComponent(); txt_Tili = transform.Find("ResBG/txt_Res").GetComponent(); btnGemAdd = transform.Find("GemBG/btn_GemAdd").gameObject; EventTriggerListener.Get(btnGemAdd).onClick = GemAdd_Click; btnGoldAdd = transform.Find("GoldBG/btn_GoldAdd").gameObject; EventTriggerListener.Get(btnGoldAdd).onClick = GoldAdd_Click; btnTiliAdd = transform.Find("ResBG/btn_ResAdd").gameObject; EventTriggerListener.Get(btnTiliAdd).onClick = ResAdd_Click; gemEffect = transform.Find("GemBG/UI_kouchu_saoguang").gameObject; goldEffect = transform.Find("GoldBG/UI_kouchu_saoguang").gameObject; resEffect = transform.Find("ResBG/UI_kouchu_saoguang").gameObject; lastTili = UserProxy.Instance.player.baseInfo.tili; lastCash = UserProxy.Instance.player.baseInfo.cash; lastGold = UserProxy.Instance.player.baseInfo.gold; txt_Gem.text = UserProxy.Instance.player.baseInfo.cash.ToString(); txt_Gold.text = UserProxy.Instance.player.baseInfo.gold.ToString(); MaxTili = int.Parse(GameConfigData.Ins.globalsettings.TiliMaxVal.ToString()); txt_Tili.text = txt_Tili.text = UserProxy.Instance.player.baseInfo.tili.ToString() + " / " + MaxTili; } private void Update() { _curTime -= Time.deltaTime; if (_curTime <= 0) { _curTime = _spaceTime; //// 资源点 if (lastTili != UserProxy.Instance.player.baseInfo.tili) { lastTili = UserProxy.Instance.player.baseInfo.tili; txt_Tili.text = UserProxy.Instance.player.baseInfo.tili.ToString()+ " / "+ MaxTili; resEffect.SetActive(false); resEffect.SetActive(true); } // 宝石 if (lastCash != UserProxy.Instance.player.baseInfo.cash) { lastCash = UserProxy.Instance.player.baseInfo.cash; txt_Gem.text = UserProxy.Instance.player.baseInfo.cash.ToString(); gemEffect.SetActive(false); gemEffect.SetActive(true); } // 金币 if (lastGold != UserProxy.Instance.player.baseInfo.gold) { lastGold = UserProxy.Instance.player.baseInfo.gold; txt_Gold.text = UserProxy.Instance.player.baseInfo.gold.ToString(); goldEffect.SetActive(false); goldEffect.SetActive(true); } } } /// /// 增加资源点 点击 /// /// 按钮对象 private void ResAdd_Click(GameObject go) { PanelHelper.Instance.ShowPanel("UI_NewBuyTiliWindow", (panel) => { //UI_ShopPrizesPanel shopPrize = panel.GetComponent(); //shopPrize.Init(); //shopPrize.Show(lst); }); } /// /// 增加钻石 点击 /// /// 按钮对象 private void GemAdd_Click(GameObject go) { LogHelper.Log("点击增加钻石"); } /// /// 增加金币 点击 /// /// 按钮对象 private void GoldAdd_Click(GameObject go) { LogHelper.Log("点击增加金币"); } }