public static string ReadTextUserData(string filename) { #if UNITY_XBOXONE && !UNITY_EDITOR byte [] bytes = XboxOneConnectedStorage.GetData(filename); if (bytes == null) { return(null); } else { return(new string(Encoding.ASCII.GetChars(bytes))); } #elif UNITY_PS4 && !UNITY_EDITOR byte [] bytes = PS4Manager.ReadData(filename); if (bytes == null) { return(null); } else { return(new string(Encoding.ASCII.GetChars(bytes))); } #else try { return(File.ReadAllText(Path.Combine(persistentDataPath, filename))); } catch { return(null); } #endif }
public static string[] GetUserDataList(string extension) { #if UNITY_XBOXONE && !UNITY_EDITOR return(XboxOneConnectedStorage.GetListOfBlobNamesThatMatchExtension(extension).ToArray()); #elif UNITY_PS4 && !UNITY_EDITOR return(PS4Manager.GetFileList(extension)); #else return(Directory.GetFiles(persistentDataPath, "*" + extension)); #endif }
//Write a string to the per-user storage public static void WriteTextUserData(string filename, string text) { #if UNITY_XBOXONE && !UNITY_EDITOR XboxOneConnectedStorage.SaveData(filename, Encoding.ASCII.GetBytes(text)); #elif UNITY_PS4 PS4Manager.WriteData(filename, Encoding.ASCII.GetBytes(text)); #else File.WriteAllText(Path.Combine(persistentDataPath, filename), text); #endif }
//Write a chunk of data to the per-user storage public static void WriteBinaryUserData(string filename, byte[] data) { #if UNITY_XBOXONE && !UNITY_EDITOR XboxOneConnectedStorage.SaveData(filename, data); #elif UNITY_PS4 PS4Manager.WriteData(filename, data); #else File.WriteAllBytes(Path.Combine(persistentDataPath, filename), data); #endif }
public static void DeleteUserData(string filename) { #if UNITY_XBOXONE && !UNITY_EDITOR XboxOneConnectedStorage.DeleteData(filename); #elif UNITY_PS4 && !UNITY_EDITOR throw new Exception("Cannot delete file on PS4"); #else string filepath = Path.Combine(persistentDataPath, filename); if (File.Exists(filepath)) { File.Delete(filepath); } #endif }
//Read a chunk of data from the per-user storage public static byte[] ReadBinaryUserData(string filename) { #if UNITY_XBOXONE && !UNITY_EDITOR return(XboxOneConnectedStorage.GetData(filename)); #elif UNITY_PS4 && !UNITY_EDITOR return(PS4Manager.ReadData(filename)); #else try { return(File.ReadAllBytes(Path.Combine(persistentDataPath, filename))); } catch { return(null); } #endif }