using UnityEngine;
using System.Collections;
using System.IO;
//------------------------------------------------------------------------
//Perlin Noise Agents v1.0 - Write Settings Class
//--Class controls the writing of settings to a text file, different than export, here we are listing the variable names and values--Class lives in the Game Controller Game Object--
//Mode Lab - Written by Luis Quinones
//------------------------------------------------------------------------
public class WriteSettings : MonoBehaviour
{
public Controller control;
StreamWriter sw;
string pathSetting = "Assets/Files/";
string settingfilename = "AgentSettings.txt";
string longPath = "Assets/Files/AgentSettings.txt";
private string newfilename;
void Start()
{
//Check to see if directory and files exist
if(!Directory.Exists(pathSetting))
Directory.CreateDirectory(pathSetting);
else
{
if(!File.Exists(settingfilename))
File.Create(pathSetting+settingfilename);
}
}
void Update(){
if (Input.GetKey ("f7")) { //Use the f7 key to capture screenshot with UI and export the text file with settings
string theTime = System.DateTime.Now.ToString("hh.mm.ss");
string theDate = System.DateTime.Now.ToString("MM-dd-yyyy");
Application.CaptureScreenshot("ScreenshotSettings_" + theTime.ToString() + "_" + theDate.ToString() + ".png",4);
Debug.Log ("Took ScreenShot with UI and Exported Agent Settings");
newfilename = "AgentSettings_" + theTime.ToString() + "_" + theDate.ToString() + ".txt";
WriteToFile(pathSetting+newfilename);
}
if (Input.GetKey ("f10")) {
if(Directory.Exists(pathSetting)){
print ("Directory Exists");
if(File.Exists(longPath)){
print ("file exists");
}
}
}
}
public void WriteToFile(string file)
{
sw = new StreamWriter(file);
sw.Write ("Strength Slider Value = " + control.strengthSlider.value.ToString ());
sw.WriteLine();
sw.Write ("Scale Slider Value = " + control.scaleSlider.value.ToString ());
sw.WriteLine();
sw.Write ("Speed Slider Value = " + control.speedSlider.value.ToString ());
sw.WriteLine();
sw.Write ("Multiplier Slider Value = " + control.multiplierSlider.value.ToString ());
sw.WriteLine();
sw.Write ("Agent Count Slider Value = " + control.agentCountSlider.value.ToString ());
sw.WriteLine();
if (control.dynamicAgentSpawnScrollBar.value == 0) {
sw.Write ("Dynamic Spawn Scroll Bar Value Value = Static");
sw.WriteLine();
} else {
sw.Write ("Dynamic Spawn Scroll Bar Value Value = Dynamic");
sw.WriteLine();
}
if (control.spawnScrollBar.value == 0) {
sw.Write ("Spawn Scroll Bar Value Value = Constant");
sw.WriteLine();
} else {
sw.Write ("Spawn Scroll Bar Value Value = DieOff");
sw.WriteLine();
}
if (control.dimensionScrollBar.value == 0) {
sw.Write ("Dimension = 2D");
sw.WriteLine();
} else {
sw.Write ("Dimension = 3D");
sw.WriteLine();
}
if (control.physicsScrollBar.value == 0) {
sw.Write ("Environment = Behavior");
sw.WriteLine();
} else {
sw.Write ("Environment = Physics");
sw.WriteLine();
}
sw.Write ("Trail Time Value = " + control.trailTimeSlider.value.ToString ());
sw.WriteLine();
sw.Write ("Trail StartWidth Value = " + control.trailStartWSlider.value.ToString ());
sw.WriteLine();
sw.Write ("Trail EndWidth Value = " + control.trailEndWSlider.value.ToString ());
sw.WriteLine();
sw.Close ();
}
}
Update