chenxin
2020-11-26 9af3e3dbede79e70262ff9d206299dcca363c1bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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;
 
        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>((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;
 
            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();
            MMVibrationManager.Haptic(HapticTypes.HeavyImpact);
 
            if (CurrentHP == 0)
                EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessHeartAllLose);
        }
    }
}