-
Notifications
You must be signed in to change notification settings - Fork 0
/
SaveLoad.cs
60 lines (38 loc) · 1.25 KB
/
SaveLoad.cs
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class SaveLoad : MonoBehaviour {
public Vector3 Lastposition = Vector3.zero;
public Quaternion Lastrotation = Quaternion.identity;
public Transform trans = null;
void SaveProject()
{
string Outputpath = Application.persistentDataPath + @"\Objectposition.json";
Lastposition = trans.position;
Lastrotation = trans.rotation;
StreamWriter writer = new StreamWriter(Outputpath);
writer.WriteLine(JsonUtility.ToJson(this));
writer.Close();
Debug.Log(Outputpath);
}
void LoadProject()
{
string Inputpath = Application.persistentDataPath + @"\Objectposition.json";
StreamReader read = new StreamReader(Inputpath);
string JSONstring = read.ReadToEnd();
Debug.Log(JSONstring);
JsonUtility.FromJsonOverwrite(JSONstring, this);
read.Close();
trans.position = Lastposition;
trans.rotation = Lastrotation;
}
void Awake () {
trans = GetComponent<Transform>();
}
void Start()
{
LoadProject();
SaveProject();
}
}