/// <summary> /// Adds the unit to the GUI and underlying data structure. /// If the unit had been previously persistently highlighted, apply it when added back. /// </summary> /// <param name="unit">Unit.</param> /// <param name="orderIndex">Ordering Index.</param> public void AddUnit(Unit unit, TurnOrder turnOrder, int orderIndex = -1) { // Instantiate a new Image game object Image unitImage = Instantiate(imagePrefab); unitImage.sprite = unit.GetPortrait(); unitImage.transform.SetParent(_panel.transform, false); // Associate unit with image TurnOrderImage turnOrderImage = unitImage.GetComponent <TurnOrderImage> (); turnOrderImage.Unit = unit; unitImage.name = string.Format("{0} - {1}", unit.GetFullName(), turnOrderImage.GetInstanceID()); // Add image to list _turnOrderImageCollection.Add(turnOrderImage, turnOrder); // Add unit to turn order list if (orderIndex <= -1) { turnOrder.AddUnit(unit); } else { turnOrder.InsertUnit(unit, orderIndex); if (unit.HasDeferredAbility) { _turnOrderImageCollection.Get(unit, turnOrder).ActivateStatusImage(_statusImage); } } // Handle highlighting if (_highlightOnSpawn) { turnOrderImage.Highlight(false); } _highlightOnSpawn = false; }
public void TestAddUnit() { _turnOrder.AddUnit(_unit1); Assert.AreEqual(1, _turnOrder.GetTurnOrderLength()); }