-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveSystem.cs
More file actions
77 lines (65 loc) · 1.66 KB
/
Copy pathSaveSystem.cs
File metadata and controls
77 lines (65 loc) · 1.66 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class SaveSystem : MonoBehaviour
{
public SaveConfiguration saveConfiguration;
private void Awake()
{
Load();
}
private void Start()
{
StartCoroutine(SaveTimer());
}
public void Load()
{
if (File.Exists(Application.persistentDataPath + "{YourGameName}.txt"))
{
string textFile = File.ReadAllText(Application.persistentDataPath + "{YourGameName}.txt");
string[] textFileArray;
textFileArray = textFile.Split(' ');
saveConfiguration.floatData = StringArray(textFileArray);
}
}
public void Save()
{
File.WriteAllText(Application.persistentDataPath + "{YourGameName}.txt", FloatArray(saveConfiguration.floatData));
}
public string FloatArray(float[] data)
{
int i = 0;
string finalText = string.Empty;
while (i < data.Length)
{
finalText += data[i].ToString();
if (i < data.Length - 1)
{
i++;
finalText += " ";
}
else
break;
}
return finalText;
}
public float[] StringArray(string[] text)
{
int i = 0;
float[] finalFloat = new float[text.Length];
while (i < text.Length)
{
finalFloat[i] = float.Parse(text[i]);
i++;
}
return finalFloat;
}
IEnumerator SaveTimer()
{
yield return new WaitForSeconds(60);
Save();
StartCoroutine(SaveTimer());
}
}