Created
September 14, 2015 18:10
-
-
Save SnugglePilot/cd353bbcfef4082b850e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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