Example #1
0
    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]);
        }
    }