IEnumerator LoadShipAsync(string ship, int index) { ShipsJsonFactory shipFactory = new ShipsJsonFactory(this); string baseUrl = "https://api.spacexdata.com/v3/ships/"; ShipList shipList = listParent.shipList; shipList.listItems = new List <ShipListItem>(); shipFactory.FetchJson(baseUrl + ship); yield return(new WaitUntil(() => shipFactory.IsDone)); if (!shipFactory.IsError) { Ships shipsRoot = shipFactory.GetRootObject(); ShipListItem item = new ShipListItem(); item.homePort = shipsRoot.ship.home_port; item.imageUrl = shipsRoot.ship.image; item.numMissions = shipsRoot.ship.missions.Length; item.shipName = shipsRoot.ship.ship_name; item.shipType = shipsRoot.ship.ship_type; shipList.listItems.Add(item); } shipList.SpawnList(); if (index > 0 && index < coroutines.Count) { activeCoroutines.RemoveAll(value => value == coroutines[index]); } }
#pragma warning restore 0649 public override void SpawnList() { shipsPopup.infoText.gameObject.SetActive(false); foreach (ShipListItem listItem in listItems) { ShipListItem item = listItem; GameObject panel = pool.RequestAnObject(); panel.transform.SetParent(contentPanel); ShipItem shipItem = panel.GetComponent <ShipItem>(); shipItem.Init(item); } }
void TargetUpdateDockedShipList(NetworkConnection target, SerializablePortShipList shipList) { // Delete all items currently in the ship list foreach (ShipListItem menuItem in contentPanel.GetComponentsInChildren <ShipListItem>()) { Destroy(menuItem.gameObject); } // Make ShipListItem prefabs from the serializable list and put them in the ship menu for (int i = 0; i < shipList.shipNames.Length; i++) { GameObject newListItem = Instantiate(listItemPrefab) as GameObject; ShipListItem item = newListItem.GetComponent <ShipListItem> (); item.name.text = shipList.shipNames [i]; item.type.text = shipList.shipTypes [i]; item.crew.text = "Crew: " + shipList.shipCrewCounts [i] + "/" + shipList.shipCrewMaxes [i]; newListItem.transform.parent = contentPanel.transform; newListItem.transform.localScale = Vector3.one; } }