using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Core.Utilities; using DG.Tweening; using MoreMountains.NiceVibrations; /** * 无尽模式玩家基地血量管理器 * @Author: chenxin * @Date: 2020-11-05 15:33:11 */ namespace KTGMGemClient { public class EndlessHomeBaseHPManager : MonoBehaviour { /// /// 总血量 /// public int TotalHP { get; private set; } /// /// 当前血量 /// public int CurrentHP { get; private set; } /// /// 爱心列表 /// public List HeartList; public Text hpTxt; public ParticleSystem ps; // Start is called before the first frame update private void Start() { CurrentHP = TotalHP = HeartList.Count; hpTxt.text = "x" + CurrentHP.ToString(); EventCenter.Ins.Add((int)KTGMGemClient.EventType.EndlessLoseHeart, LoseHeart); } // Update is called once per frame private void Update() { } /// /// 减少爱心 /// /// 一次减少的数量 private void LoseHeart(int count) { if (CurrentHP == 0) return; 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(); // 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(); // ps.Play(); // ++i; // } hpTxt.text = "x" + CurrentHP.ToString(); //ps.Play(); ViewPortAdj.instance.cachedCamera.DOShakePosition(0.25f, 1.5f, 4);//这里只可以震动3D场景中的东西 MMVibrationManager.Haptic(HapticTypes.HeavyImpact); if (CurrentHP == 0) EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessHeartAllLose); } } }