using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using System.IO;
//------------------------------------------------------------------------
//Perlin Noise Agents v1.0 - Settings Export Class
//--Class Controls the exporting of settings to a text file--Class lives inside the GameController Game Object--The Export Settings button lives in this class
//Mode Lab - Written by Luis Quinones
//------------------------------------------------------------------------
public class SettingsExport : MonoBehaviour {
public Button ExportSettingsButton;
public Controller control; //Reference the contoller
StreamWriter sw; //Implements a textwriter for writing characters to a stream in a particular encoding
private string newfilename;
private bool writeFile;
public string pathSpecified;
public bool runIt;
void Start(){
if (runIt) {
runIt = false;
if (pathSpecified.Length != 0) {
print ("Exported Settings");
writeFile = true;
} else {
return; //Exit if the user hits cancel or does not specify a name for the file
}
}
}
void Update(){
if (runIt) {
Start();
}
if (writeFile) {
WriteToFile(pathSpecified); //Call the write to file function and pass the path
writeFile = false; //Set the flag to false after we do it once since its in the update function
}
}
public void WriteToFile(string file)
{
sw = new StreamWriter(file);
//Write all the values, use the sw.WriteLine to begin a new line after the value is written
sw.Write (control.strengthSlider.value.ToString ());
sw.WriteLine();
sw.Write (control.scaleSlider.value.ToString ());
sw.WriteLine();
sw.Write (control.speedSlider.value.ToString ());
sw.WriteLine();
sw.Write (control.multiplierSlider.value.ToString ());
sw.WriteLine();
sw.Write (control.agentCountSlider.value.ToString ());
sw.WriteLine();
sw.Write (control.dynamicAgentSpawnScrollBar.value.ToString ());
sw.WriteLine ();
sw.Write (control.spawnScrollBar.value.ToString ());
sw.WriteLine ();
sw.Write (control.dimensionScrollBar.value.ToString ());
sw.WriteLine ();
sw.Write (control.physicsScrollBar.value.ToString ());
sw.WriteLine ();
sw.Write (control.trailTimeSlider.value.ToString ());
sw.WriteLine();
sw.Write (control.trailStartWSlider.value.ToString ());
sw.WriteLine();
sw.Write (control.trailEndWSlider.value.ToString ());
sw.Close ();
}
}
Update