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
|
{
|
/// <summary>
|
/// 总血量
|
/// </summary>
|
public int TotalHP { get; private set; }
|
|
/// <summary>
|
/// 当前血量
|
/// </summary>
|
public int CurrentHP { get; private set; }
|
|
/// <summary>
|
/// 爱心列表
|
/// </summary>
|
public List<GameObject> HeartList;
|
|
// Start is called before the first frame update
|
private void Start()
|
{
|
CurrentHP = TotalHP = HeartList.Count;
|
EventCenter.Ins.Add<int>((int)KTGMGemClient.EventType.EndlessLoseHeart, LoseHeart);
|
}
|
|
// Update is called once per frame
|
private void Update()
|
{
|
|
}
|
|
/// <summary>
|
/// 减少爱心
|
/// </summary>
|
/// <param name="count">一次减少的数量</param>
|
private void LoseHeart(int count)
|
{
|
if (CurrentHP == 0) return;
|
|
int preHP = CurrentHP;
|
int i = TotalHP - CurrentHP;
|
CurrentHP = Mathf.Max(0, CurrentHP - count);
|
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;
|
}
|
|
ViewPortAdj.instance.cachedCamera.DOShakePosition(0.25f, 1.5f, 4);
|
MMVibrationManager.Haptic(HapticTypes.HeavyImpact);
|
|
if (CurrentHP == 0)
|
EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessHeartAllLose);
|
}
|
}
|
}
|