Skip to content

Instantly share code, notes, and snippets.

@SnugglePilot
Created September 14, 2015 18:10
Show Gist options
  • Save SnugglePilot/cd353bbcfef4082b850e to your computer and use it in GitHub Desktop.
Save SnugglePilot/cd353bbcfef4082b850e to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.IO;
public class SaveFormToDisk : MonoBehaviour {
public InputField textReference;
public string saveDir;
public void SaveToFile(string text, string subDir) {
string path = FileManager.dataPath+"/"+subDir+"/";
if (!Directory.Exists(path)) {
var info = Directory.CreateDirectory(path);
if (!info.Exists) {
Debug.LogWarning ("Failed to create path: "+path);
return;
}
}
System.DateTime epochStart = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
int cur_time = (int)(System.DateTime.UtcNow - epochStart).TotalSeconds;
path += cur_time+".txt";
File.WriteAllText(path, text);
}
public void Activate() {
SaveToFile(textReference.text, saveDir);
textReference.text = "";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment