/// <summary> /// Accepts a list of units to add to the scrollview. /// For each unit, creates a unit tile to represent the unit. /// Accepts an optional function parameter that can be attached to each /// tile so that the tiles can be made clickable. /// </summary> public void SetContent(List <Unit> units, TileCallback callback = null) { /// Removes any existing content foreach (GameObject tile in unitTiles) { Destroy(tile); } unitTiles.Clear(); this.units = units; /// Defaults the callback to an empty one if no /// callback is provided. TileCallback unitCallback; if (callback == null) { unitCallback = (Unit u) => {}; } else { unitCallback = callback; } /// Create and add a new label for each unit. foreach (Unit unit in units) { GameObject unitTile = Instantiate(this.unitTile, content.GetComponent <RectTransform>(), false); unitTiles.Add(unitTile); unitTile.GetComponentInChildren <Text>().text = unit.unitName; unitTile.GetComponent <Clickable>().SetCallbackDelegate(() => { unitCallback(unit); }); unitTile.transform.SetParent(content.GetComponent <RectTransform>()); } }
/// <summary> /// Accepts a list of units to add to the scrollview. /// For each unit, creates a unit tile to represent the unit. /// Accepts an optional function parameter that can be attached to each /// tile so that the tiles can be made clickable. /// </summary> public void SetContent(List <TravellingUnit> tUnits, TileCallback callback = null) { /// Removes any existing content foreach (TravellingUnitTile tile in tUnitTiles) { Destroy(tile.gameObject); } tUnitTiles.Clear(); /// Defaults the callback to an empty one if no /// callback is provided. TileCallback unitCallback; if (callback == null) { unitCallback = (Unit u) => {}; } else { unitCallback = callback; } /// Create and add a new label for each unit. foreach (TravellingUnit tUnit in tUnits) { TravellingUnitTile tUnitTile = Instantiate(this.unitTile, content.GetComponent <RectTransform>(), false); tUnitTiles.Add(tUnitTile); tUnitTile.Initialize(tUnit); tUnitTile.transform.SetParent(content.GetComponent <RectTransform>()); } }
public DestructibleTile(double x, double y, GamePlane gp) : base("D", x, y) { parentGamePlane = gp; destructionCallback += new TileCallback(gp.DestroyTile); }