wangguan
2020-11-06 9abbdf408daf5bc140ffd039125f6ac54f2774b9
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Core.Utilities;
 
/**
 * 无尽模式玩家基地血量管理器
 * @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<Image> 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)
            {
                Color c = HeartList[i].color;
                c.a = 0.27f;
                HeartList[i].color = c;
                ++i;
            }
 
            if (CurrentHP == 0)
                EventCenter.Ins.BroadCast((int)KTGMGemClient.EventType.EndlessHeartAllLose);
        }
    }
}