/// <summary> /// Init all button with AgentSelected Helps and update them /// </summary> private void InitMenu() { //catch Agent selected in AngentSelector and set button AgentSelector agentSelector = AgentSelector.Instance; if (agentSelector != null) { for (int i = 0; i < agentSelector.selectedAgents.Count; i++) { Unit m_unit = AgentSelector.Instance.selectedAgents[i].GetComponent <Unit>(); UnitButton unitButton = unitButtonList[i]; unitButton.unitIcon.sprite = m_unit.icon; unitButton.UnitCostText.text = m_unit.cost.ToString(); unitButton.cdFillText.enabled = false; unitButton.agentSelectorIndex = i; unitButton.unit = m_unit; m_unit.isInCD = false; } if (agentSelector.selectedAgents.Count < unitButtonList.Count) { RemoveEmptyFromList(); } UpdateButtons(); } }
private void Awake() { if (Instance != null) { Destroy(this); } Instance = this; }
private void Awake() { poolManager = PoolManager.Instance; agentSelector = AgentSelector.Instance; for (int i = 0; i < AgentSelector.Instance.selectedAgents.Count; i++) { agentButtonsImageList[i].sprite = AgentSelector.Instance.selectedAgents[i].GetComponent <Unite>().icon; CDList.Add(AgentSelector.Instance.selectedAgents[i].GetComponent <Unite>().CDBetweenSpawns); priceList.Add(AgentSelector.Instance.selectedAgents[i].GetComponent <Unite>().price); onCDList.Add(false); } }
public void AgentSelector_TestGetNextAgent() { Constant a1 = new Constant("agent", "a1"); Constant a2 = new Constant("agent", "a2"); Constant a3 = new Constant("agent", "a3"); Constant a4 = new Constant("agent", "a4"); AgentSelector agentSelector = new AgentSelector(new List <Constant>() { a1, a2, a3, a4 }, null); Assert.AreEqual(agentSelector.GetNextAgent(), a1); Assert.AreEqual(agentSelector.GetNextAgent(), a2); Assert.AreEqual(agentSelector.GetNextAgent(), a3); Assert.AreEqual(agentSelector.GetNextAgent(), a4); }
/// <summary> /// Remove empty button from unitButtonList /// </summary> private void RemoveEmptyFromList() { AgentSelector agentSelector = AgentSelector.Instance; List <int> empty = new List <int>(); for (int i = agentSelector.selectedAgents.Count; i < unitButtonList.Count; i++) { empty.Add(i); } for (int i = empty.Count - 1; i >= 0; i--) { UnitButton unitButton = unitButtonList[empty[i]]; unitButtonList.RemoveAt(empty[i]); Destroy(unitButton.gameObject); } }
private void Awake() { Instance = this; }
// Start is called before the first frame update void Start() { agentSelector = GetComponent <AgentSelector>(); agentSelector.OnAgentSelected += OnAgentSelected; agentSelector.OnAgentDeselected += OnAgentDeselected; }