using UnityEngine; using System.Collections; using UnityEngine.UI; using System.Collections.Generic; using System; using System.IO; //------------------------------------------------------------------------ //Perlin Noise Agents v1.0 - Settings Import Class //--Class Controls the importing of settings from a text file--Class lives inside the GameController Game Object--The Import Settings button lives in this class //Mode Lab - Written by Luis Quinones //------------------------------------------------------------------------ public class SettingsImport : MonoBehaviour { public Button ImportSettingsButton; public Controller control; public DataPreserve dp; public string path; public bool runIt; //ORDER OF TEXT DATA //strengthSlider | scaleSlider | speedSlider | multiplierslider | agentcountslider | dynamicagentspawnscrollbar | spawnscrollbar | dimensionscrollbar | physicsscrollbar | trailtimeslider | trailstartwidth | trailendwidth void Start(){ if (runIt) { runIt = false; List<dynamic> valueList = new List<dynamic> (); valueList.Add (control.strengthSlider); valueList.Add (control.scaleSlider); valueList.Add (control.speedSlider); valueList.Add (control.multiplierSlider); valueList.Add (control.agentCountSlider); valueList.Add (control.dynamicAgentSpawnScrollBar); valueList.Add (control.spawnScrollBar); valueList.Add (control.dimensionScrollBar); valueList.Add (control.physicsScrollBar); valueList.Add (control.trailTimeSlider); valueList.Add (control.trailStartWSlider); valueList.Add (control.trailEndWSlider); if (path.Length != 0) { StreamReader sr = new StreamReader (path); //Set a new path to the streamreader var fileContents = sr.ReadToEnd (); //Read the file sr.Close (); var lines = fileContents.Split ("\n" [0]); //Split the lines we are using a workaround in Unity Script because unity doesnt have character literals. we are using a string //and taking the first character [0] as the splitting delimiter. int count = 0; foreach (var line in lines) { //For each line that is read we are assigning the line value which is converted to a float to the corresponding values in the Controller Class print("LINE = " + line); if (count == 0) { control.strengthSlider.value = float.Parse (line); } if (count == 1) { control.scaleSlider.value = float.Parse (line); } if (count == 2) { control.speedSlider.value = float.Parse (line); } if (count == 3) { control.multiplierSlider.value = float.Parse (line); } if (count == 4) { control.agentCountSlider.value = float.Parse (line); } if (count == 5) { control.dynamicAgentSpawnScrollBar.value = float.Parse (line); } if (count == 6) { control.spawnScrollBar.value = float.Parse (line); } if (count == 7) { control.dimensionScrollBar.value = float.Parse (line); } if (count == 8) { control.physicsScrollBar.value = float.Parse (line); } if (count == 9) { control.trailTimeSlider.value = float.Parse (line); } if (count == 10) { control.trailStartWSlider.value = float.Parse (line); } if (count == 11) { control.trailEndWSlider.value = float.Parse (line); } count ++; } GameObject[] test = GameObject.FindGameObjectsWithTag ("AGENTDUDE"); foreach (GameObject t in test) { Destroy (t); //Kill all agents } control.reboot.GetComponent<DataPreserve> ().fireUp = true; //Pass the reset flag to the Controller } else { return; } } } void Update(){ if (runIt) { Start(); } } } Update