123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using DG.Tweening;
- /// <summary>
- /// 右上角菜单
- /// </summary>
- public class UI_RightTopMenu : MonoBehaviour
- {
- private static UI_RightTopMenu pInit = null;
- private GameObject btnGemAdd = null;
- private GameObject btnGoldAdd = null;
- private GameObject btnResAdd = null;
- private GameObject gemEffect = null;
- private GameObject goldEffect = null;
- private GameObject resEffect = null;
- private GameObject btnTaskCard = null;
- GameObject effectTuoWei = null;
- GameObject effectTiShi = null;
- private Text txt_Gem = null;
- private Text txt_Gold = null;
- private Text txt_Res = null;
- private const float _spaceTime = 0;
- private float _curTime = 0.5f;
- private int lastCash = 0;
- private int lastGold = 0;
- private int lastRes = 0;
- /// <summary>
- /// 单例
- /// </summary>
- public static UI_RightTopMenu Instance
- {
- get
- {
- return pInit;
- }
- }
- /// <summary>
- /// 创建
- /// </summary>
- /// <param name="parentTran">父Transform</param>
- public static void Create(Transform parentTran,bool show = false)
- {
- if (show == false)
- {
- return;
- }
- ResourceHelper.Instance.LoadAssetBundle("UI_RightTopMenu", (ab) =>
- {
- if (ab != null)
- {
- GameObject uiObj = Instantiate(ab.LoadAsset<GameObject>("UI_RightTopMenu"), parentTran);
- pInit = uiObj.AddComponent<UI_RightTopMenu>();
- pInit.Init();
- }
- });
- }
- /// <summary>
- /// 初始化
- /// </summary>
- private void Init()
- {
- _curTime = _spaceTime;
- txt_Gem = transform.Find("GemBG/txt_Gem").GetComponent<Text>();
- txt_Gold = transform.Find("GoldBG/txt_Gold").GetComponent<Text>();
- txt_Res = transform.Find("ResBG/txt_Res").GetComponent<Text>();
- 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;
- btnResAdd = transform.Find("ResBG/btn_ResAdd").gameObject;
- EventTriggerListener.Get(btnResAdd).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;
- btnTaskCard = transform.Find("btn_TaskCard").gameObject;
- effectTuoWei = btnTaskCard.transform.Find("UI_kapai_feiru_tuowei").gameObject;
- effectTiShi = btnTaskCard.transform.Find("UI_baoguo_shouqu_tishi").gameObject;
- // 任务卡背包
- EventTriggerListener.Get(btnTaskCard).onClick = (btnObj) =>
- {
- PanelHelper.Instance.ShowPanel("UI_PacketWindow", null, 5);
- // PanelHelper.Instance.ShowPanel("UI_TaskCardWindow");
- };
- lastCash = UserProxy.Instance.player.baseInfo.cash;
- lastGold = UserProxy.Instance.player.baseInfo.gold;
- lastRes = UserProxy.Instance.player.baseInfo.resPoint;
- txt_Gem.text = UserProxy.Instance.player.baseInfo.cash.ToString();
- txt_Gold.text = UserProxy.Instance.player.baseInfo.gold.ToString();
- txt_Res.text = UserProxy.Instance.player.baseInfo.resPoint.ToString();
- }
- private void Update()
- {
- _curTime -= Time.deltaTime;
- if (_curTime <= 0)
- {
- _curTime = _spaceTime;
- // 宝石
- 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);
- }
- //// 资源点
- //if (lastRes != UserProxy.Instance.player.baseInfo.resPoint)
- //{
- // lastRes = UserProxy.Instance.player.baseInfo.resPoint;
- // txt_Res.text = UserProxy.Instance.player.baseInfo.resPoint.ToString();
- // resEffect.SetActive(false);
- // resEffect.SetActive(true);
- //}
- }
- }
- /// <summary>
- /// 显示获得新卡特效
- /// </summary>
- public void ShowNewCardEffect()
- {
- effectTuoWei.SetActive(true);
- float varH = UnityEngine.Random.Range(-500, 500);
- DOTween.To(setter: value =>
- {
- Debug.Log(value);
- effectTuoWei.transform.localPosition = Parabola(new Vector3(-910, -550, 0), Vector3.zero, varH, value);
- }, startValue: 0, endValue: 1, duration: 0.5f)
- .SetEase(Ease.Linear);
- Invoke("LateShowTiShi", 0.5f);
- }
- /// <summary>
- /// 延时显示提示
- /// </summary>
- private void LateShowTiShi()
- {
- effectTuoWei.SetActive(false);
- effectTuoWei.transform.localPosition = new Vector3(-910, -550, 0);
- effectTiShi.gameObject.SetActive(false);
- effectTiShi.gameObject.SetActive(true);
- }
- /// <summary>
- /// 增加钻石 点击
- /// </summary>
- /// <param name="go"> 按钮对象 </param>
- private void GemAdd_Click(GameObject go)
- {
- LogHelper.Log("点击增加钻石");
- }
- /// <summary>
- /// 增加金币 点击
- /// </summary>
- /// <param name="go"> 按钮对象 </param>
- private void GoldAdd_Click(GameObject go)
- {
- LogHelper.Log("点击增加金币");
- }
- /// <summary>
- /// 增加资源点 点击
- /// </summary>
- /// <param name="go"> 按钮对象 </param>
- private void ResAdd_Click(GameObject go)
- {
- LogHelper.Log("点击增加资源点");
- }
- public static Vector3 Parabola(Vector3 start, Vector3 end, float height, float t)
- {
- float Func(float x) => 4 * (-height * x * x + height * x);
- var mid = Vector3.Lerp(start, end, t);
- return new Vector3(mid.x, Func(t) + Mathf.Lerp(start.y, end.y, t), mid.z);
- }
- public static Vector2 Parabola(Vector2 start, Vector2 end, float height, float t)
- {
- float Func(float x) => 4 * (-height * x * x + height * x);
- var mid = Vector2.Lerp(start, end, t);
- return new Vector2(mid.x, Func(t) + Mathf.Lerp(start.y, end.y, t));
- }
- }
|