liuzhiwei
2020-11-04 78e14d93c46238881339f33a56c81275c55d5089
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
using Core.Utilities;
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class HealthHeartState : Singleton<HealthHeartState>
{
    public List<Image> selfHeartList;
    public List<Image> oppoHeartList;
 
    public Sprite heartBreakImg;
 
 
    protected bool[] selfHeartState;
    protected bool[] oppoHeartState;
 
    // Start is called before the first frame update
    void Start()
    {
        selfHeartState = new bool[selfHeartList.Count];
        oppoHeartState = new bool[oppoHeartList.Count];
        for( int ti = 0;ti<selfHeartList.Count;ti ++ )
        {
            selfHeartState[ti] = true;
            oppoHeartState[ti] = true;
        }
    }
 
    // Update is called once per frame
    void Update()
    {
        
    }
 
    /// <summary>
    /// 删除一个对应的红心.
    /// </summary>
    /// <param name="opponent"></param>
    public void killHeart( bool opponent)
    {
        if (opponent)
        {
            for( int ti = 0;ti< oppoHeartState.Length;ti ++)
            {
                if( oppoHeartState[ti])
                {
                    if (this.heartBreakImg)
                        oppoHeartList[ti].sprite = heartBreakImg;
                    else
                        oppoHeartList[ti].gameObject.SetActive(false);
                    oppoHeartState[ti] = false;
                    return;
                }
            }
        }
        else
        {
            for (int ti = 0; ti < selfHeartState.Length; ti++)
            {
                if( selfHeartState[ti])
                {
                    if (this.heartBreakImg)
                        selfHeartList[ti].sprite = heartBreakImg;
                    else
                        selfHeartList[ti].gameObject.SetActive(false);
                    selfHeartState[ti] = false;
                    return;
                }
            }
        }
    }
}