void Start() { //Reguest.GET can be called passing in your ODATA url as a string in the form: //http://{Your Site Name}.azurewebsites.net/tables/{Your Table Name}?zumo-api-version=2.0.0 //The response produce is a JSON string string jsonResponse = Request.GET(_WebsiteURL); //Just in case something went wrong with the request we check the reponse and exit if there is no response. if (string.IsNullOrEmpty(jsonResponse)) { return; } //We can now deserialize into an array of objects - in this case the class we created. The deserializer is smart enough to instantiate all the classes and populate the variables based on column name. Mountain[] mountains = JsonReader.Deserialize <Mountain[]>(jsonResponse); //---------------------- //YOU WILL NEED TO DECLARE SOME VARIABLES HERE SIMILAR TO THE CREATIVE CODING TUTORIAL int i = 0; int totalCubes = mountains.Length; float totalDistance = 2.9f; //---------------------- //We can now loop through the array of objects and access each object individually foreach (Mountain mt in mountains) { //Example of how to use the object Debug.Log("This products name is: " + mt.MountainName); //---------------------- //YOUR CODE TO INSTANTIATE NEW PREFABS GOES HERE //float perc = i / (float)totalCubes; //float sin = Mathf.Sin(perc * Mathf.PI / 2); // float x = mt.X; float y = mt.Y; float z = mt.Z; var newCube = Instantiate(myPrefab, new Vector3(x, y, z), Quaternion.identity); CubeScript cubeScript = newCube.GetComponent <CubeScript>(); cubeScript.mountain = mt; // Use the mountains size to set the scale. cubeScript.SetSize(mt.Size); // if (mt.Symbol == "Sphere") { newCube.GetComponent <MeshFilter>().mesh = cubeScript.sphereMesh; } newCube.transform.Find("New Text").GetComponent <TextMesh>().text = mt.MountainName;//"Hullo Again"; i++; //---------------------- } }
void Start() { string jsonResponse = Request.GET(_WebsiteURL); if (string.IsNullOrEmpty(jsonResponse)) { return; } Assignment3[] lists = JsonReader.Deserialize <Assignment3[]>(jsonResponse); int totalCubes = lists.Length; int i = 0; float totalDistance = 2.9f; //We can now loop through the array of objects and access each object individually foreach (Assignment3 card in lists) { /* njad144 */ float perc = i / (float)totalCubes / 3; float sin = Mathf.Sin(perc * Mathf.PI / 2); float x = 1.8f + sin * totalDistance; float y = Random.Range(3.0f, 7.0f); //5.0f; float z = 3.0f; //njad144 changed so easier to click smaller boxes //njad144 Parse date we get from cards System.DateTime dateAdded = System.DateTime.ParseExact(card.dateAdded.Remove(card.dateAdded.IndexOf("at") - 1), "MMM dd, yyyy", CultureInfo.InvariantCulture); var newCube = (GameObject)Instantiate(myPrefab, new Vector3(x, y, z), Quaternion.identity); CubeScript cubeScript = newCube.GetComponent <CubeScript>(); TextMesh cubeText = newCube.GetComponentInChildren <TextMesh>(); cubeScript.SetData(card); cubeScript.SetSize(.45f * (1.0f - perc)); cubeScript.rotateSpeed = .2f + perc * 4.0f; // perc;// Random.value; //njad144 Set the text of each cube to card details. On click expands information. cubeText.text = dateAdded.ToString("dd/MM/yyyy") + "\n" + card.cardTitle.Substring(0, 10) + "..."; //Depending on which list the card is from, we set the colour of the text accordingly. switch (card.listName) { case "Ass3ToDo": cubeText.color = Color.red; cubeScript.SetColor(Color.red); break; case "Ass3Doing": cubeText.color = Color.yellow; cubeScript.SetColor(Color.yellow); break; case "Ass3Done": cubeText.color = Color.green; cubeScript.SetColor(Color.green); break; default: cubeText.color = Color.white; cubeScript.SetColor(Color.white); break; } /* njad144 */ i++; } }