-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomainSaverLoader.cs
More file actions
36 lines (33 loc) · 1.11 KB
/
DomainSaverLoader.cs
File metadata and controls
36 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System.IO;
using UnityEngine;
public static class DomainSaverLoader
{
private static string GetFilePath(string fileName)
{
return Path.Combine(Application.persistentDataPath, fileName);
}
public static void SaveData(int[] array, string fileName)
{
IntArrayData data = new IntArrayData { myArray = array };
string json = JsonUtility.ToJson(data);
string filePath = GetFilePath(fileName);
File.WriteAllText(filePath, json);
Debug.Log("Saved data to " + filePath);
}
public static int[] LoadData(string fileName)
{
string filePath = GetFilePath(fileName);
if (File.Exists(filePath))
{
string json = File.ReadAllText(filePath);
IntArrayData data = JsonUtility.FromJson<IntArrayData>(json);
Debug.Log("Loaded data from " + filePath);
return data.myArray;
}
else
{
Debug.LogError("File not found: " + filePath);
return null; // or return an empty array depending on your needs
}
}
}