Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class SaveSystem : MonoBehaviour
- {
- #region Instance
- public static SaveSystem Instance;
- public void Awake()
- {
- if (Instance != null)
- Instance = this;
- }
- #endregion
- public Dictionary<int, ObjectData> LevelData = new Dictionary<int, ObjectData>();
- public bool HasObject(int ID)
- {
- return LevelData.ContainsKey(ID);
- }
- public ObjectData GetObject(int ID)
- {
- if (HasObject(ID))
- return LevelData[ID];
- else
- return null;
- }
- public void RegisterObject(int ID, ObjectData data)
- {
- LevelData.Add(ID, data);
- }
- public void UpdateData(int ID, ObjectData newData)
- {
- LevelData[ID] = newData;
- }
- public void OnDestroy() // when we quit the game save
- {
- Save();
- }
- public void Save()
- {
- string json = JsonUtility.ToJson(LevelData);
- //save the json in a file
- }
- public void Load(string json)
- {
- LevelData = JsonUtility.FromJson<Dictionary<int, ObjectData>>(json);
- //TODO create all the objects, again
- }
- }
- public class ObjectData
- {
- public Vector3 Position;
- public Quaternion Rotation;
- public bool Destroied;
- public ObjectData(Vector3 pos, Quaternion rot, bool des)
- {
- this.Position = pos;
- this.Rotation = rot;
- this.Destroied = des;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement