Skip to content

Commit

Permalink
save and load with P and L
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidBrot committed Feb 11, 2021
1 parent e0bb1d8 commit 64b08c0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Assets/Scripts/Data/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,15 @@ protected virtual void OnHintChanged(Hint newHint, Hint oldHint)
HintChanged?.Invoke(this, new ItemChangedEventArgs<Hint>(newHint, oldHint));
}

void saveStateToFile(string filename)
public void saveStateToFile(string filename)
{
string serializedGame = GameSerializer.serialize(this);
System.IO.File.WriteAllText(
Path.Combine(Application.persistentDataPath, filename),
serializedGame, Encoding.UTF8);
}

void restoreStateFromFile(string filename)
public void restoreStateFromFile(string filename)
{
string serializedGame =
System.IO.File.ReadAllText(Path.Combine(Application.persistentDataPath, filename), Encoding.UTF8);
Expand Down
24 changes: 24 additions & 0 deletions Assets/Scripts/DevTools/SaveAndLoadKeyListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Assets.Scripts.Data;
using UnityEngine;

namespace Assets.Scripts.DevTools
{
public class SaveAndLoadKeyListener : MonoBehaviour
{
public void Update()
{
if (Input.GetKeyDown(KeyCode.P))
{
// Save to file
Game.Instance.saveStateToFile("test_save.sav");
}

if (Input.GetKeyDown(KeyCode.L))
{
// Load from file
Game.Instance.restoreStateFromFile("test_save.sav");
}
}
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/DevTools/SaveAndLoadKeyListener.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 64b08c0

Please sign in to comment.