wangguan
2020-10-26 0e8a4a629f0db7d9dc7b8c3b9795a195c279f7b9
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
using System.Collections;
using System.Collections.Generic;
using TowerDefense.Agents;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UI;
 
public class agentNumUI : MonoBehaviour
{
    /// <summary>
    /// 是否是敌方显示盘。
    /// </summary>
    public bool opponent;
    /// <summary>
    /// 所有可以显示的Agent图片数量.
    /// </summary>
    public List<Image> listAgentImg;
 
    protected int maxAgentImg;
 
    protected List<Agent> agentList = null;
    protected int lastAgNum = 0;
 
    // Start is called before the first frame update
    void Start()
    {
        maxAgentImg = this.listAgentImg.Count;
        for (int ti = 0; ti < maxAgentImg; ti++)
            listAgentImg[ti].enabled = false;
    }
 
    // Update is called once per frame
    void Update()
    {
        if( agentList == null)
        {
            if( opponent)
            {
                agentList = AgentInsManager.instance.oppoAgentList;
            }
            else
            {
                agentList = AgentInsManager.instance.agentList;
            }
        }
 
        // 根据agengList内的agent数目来显示相应的数据
        int agnum = agentList.Count;
        if (agnum > maxAgentImg)
            agnum = maxAgentImg;
        if (agnum == lastAgNum) return;
        if( agnum > lastAgNum)
        {
            for (int ti = lastAgNum; ti < agnum; ti++)
            {
                listAgentImg[ti].enabled = true;
            }
        }
        else
        {
            for( int ti = agnum;ti<lastAgNum;ti++)
            {
                listAgentImg[ti].enabled = false;
            }
        }
        lastAgNum = agnum;
    }
 
 
 
}