private static void readData(string input, string name, planetData body) { string[] data = input.Split(','); //Populates the body object with the position data. body.time = data[1]; body.position = new Vector3(float.Parse(data[2]), float.Parse(data[4]), float.Parse(data[3])); body.velocity = new Vector3(float.Parse(data[5]), float.Parse(data[7]), float.Parse(data[6])); body.name = name; }
public static bool planetsHaveValues = false; //Is true when planets should be populated with nonzero values. public void generateData(DateTime time) { //Call this script to generate the planetData objects for every value in ids if (planets.Count < ids.Length) { foreach (int id in ids) //For all ids { planetData body = new planetData(); //Create an object body.id = id; planets.Add(body); //Add the object to the list } } //keep this from adding more bodies to the script. planets.ForEach(p => StartCoroutine(getData(time, p.id, p))); StartCoroutine(updateData()); //When all values are recived from the interwebz, populate the fields in the object }
private static WWW www; //The www object for the horizons database. private IEnumerator getData(DateTime time, int bodyID, planetData body) { //Gets the data from the horizons server and populates the raw data field of the appropriate object UnityWebRequest www = UnityWebRequest.Get(generateURL(DateTime.Now, bodyID)); yield return(www.SendWebRequest()); //Wait for return fromrequest if (www.isNetworkError || www.isHttpError) //If error, output error { Debug.Log(www.error); } else //Else populate rawData { body.rawData = www.downloadHandler.text; body.id = bodyID; } }