| | |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using Core.Utilities; |
| | | using DG.Tweening; |
| | | using MoreMountains.NiceVibrations; |
| | | using TMPro; |
| | | using DG.Tweening; |
| | | using Core.Utilities; |
| | | |
| | | /** |
| | | * 无尽模式玩家基地血量管理器 |
| | |
| | | /// </summary> |
| | | public List<GameObject> HeartList; |
| | | |
| | | public Text hpTxt; |
| | | public ParticleSystem ps; |
| | | public TextMeshProUGUI hpTxt; |
| | | |
| | | [SerializeField] |
| | | private GameObject loseHeartPrefab; |
| | | |
| | | private bool isPlayLoseHeartDone = true; |
| | | |
| | | [SerializeField] |
| | | private Image heartImg; |
| | | |
| | | private Timer timer; |
| | | |
| | | // Start is called before the first frame update |
| | | private void Start() |
| | | { |
| | | CurrentHP = TotalHP = HeartList.Count; |
| | | CurrentHP = TotalHP = 5; |
| | | hpTxt.text = "x" + CurrentHP.ToString(); |
| | | EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EndlessLoseHeart, LoseHeart); |
| | | } |
| | | |
| | | // Update is called once per frame |
| | | private void Update() |
| | | public void Update() |
| | | { |
| | | |
| | | if (timer != null) |
| | | timer.Tick(Time.deltaTime); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | if (CurrentHP == 0) return; |
| | | |
| | | FloatLoseHeart(count); |
| | | PlayLoseHeartEffect(); |
| | | CurrentHP = Mathf.Max(0, CurrentHP - count); |
| | | // int preHP = CurrentHP; |
| | | // int i = TotalHP - CurrentHP; |
| | | // int num = preHP - CurrentHP; |
| | | // int end = i + num; |
| | | |
| | | // while (i < end) |
| | | // { |
| | | // Image img = HeartList[i].GetComponent<Image>(); |
| | | // Color c = img.color; |
| | | // c.a = 0.17f; |
| | | // img.color = c; |
| | | |
| | | // GameObject psObj = HeartList[i].transform.GetChild(0).gameObject; |
| | | // ParticleSystem ps = psObj.transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | // ps.Play(); |
| | | // ++i; |
| | | // } |
| | | |
| | | hpTxt.text = "x" + CurrentHP.ToString(); |
| | | //ps.Play(); |
| | | |
| | | //ViewPortAdj.instance.cachedCamera.DOShakePosition(0.25f, 1.5f, 4);//这里只可以震动3D场景中的东西 |
| | | ViewPortAdj.instance.DOShakePosition(); |
| | |
| | | if (CurrentHP == 0) |
| | | EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessHeartAllLose); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 丢失爱心飘字 |
| | | /// </summary> |
| | | /// <param name="count"></param> |
| | | private void FloatLoseHeart(int count) |
| | | { |
| | | GameObject prefab = Resources.Load<GameObject>("UI/DecreaseHeart"); |
| | | GameObject obj = Instantiate(prefab); |
| | | obj.transform.SetParent(GameObject.Find("UICamera/BottomCanvas/Panel/Bottom/CurrencyContainer").transform, false); |
| | | obj.transform.localPosition = new Vector3(91.5f, 48.8f, 0f); |
| | | obj.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); |
| | | TextMeshProUGUI textMeshProUGUI = obj.transform.GetChild(0).GetComponent<TextMeshProUGUI>(); |
| | | textMeshProUGUI.text = $"-{count}"; |
| | | DOTween.To( |
| | | () => obj.transform.localPosition.y, |
| | | (float v) => |
| | | { |
| | | Vector3 pos = obj.transform.localPosition; |
| | | pos.y = v; |
| | | obj.transform.localPosition = pos; |
| | | |
| | | }, 70.9f, 0.3f); |
| | | Destroy(obj, 0.6f); |
| | | } |
| | | |
| | | private void PlayLoseHeartEffect() |
| | | { |
| | | if (!isPlayLoseHeartDone) return; |
| | | |
| | | heartImg.enabled = false; |
| | | GameObject obj = Instantiate(loseHeartPrefab); |
| | | obj.transform.SetParent(GameObject.Find("ParticleSystemObject").transform, false); |
| | | obj.transform.localPosition = new Vector3(-27.93f, 0f, -51.52f); |
| | | obj.transform.localScale = new Vector3(0.9f, 0.9f, 0.9f); |
| | | ParticleSystem ps = obj.transform.GetChild(0).GetComponent<ParticleSystem>(); |
| | | ps?.Play(); |
| | | timer = new Timer(0.6f, SpawnHeart); |
| | | } |
| | | |
| | | private void SpawnHeart() |
| | | { |
| | | timer = null; |
| | | |
| | | if (CurrentHP == 0) return; |
| | | |
| | | heartImg.enabled = true; |
| | | heartImg.transform.localScale = new Vector3(0f, 0f, 0f); |
| | | |
| | | DOTween.To( |
| | | () => heartImg.transform.localScale, |
| | | (Vector3 v) => heartImg.transform.localScale = v, |
| | | new Vector3(1f, 1f, 1f), |
| | | 0.3f |
| | | ).SetEase((Ease.OutBack)) |
| | | .OnComplete(() => { isPlayLoseHeartDone = true; }); |
| | | } |
| | | } |
| | | } |