Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- By: Nathan Rumsey
- Engineer 3d llc
- 2022
- */
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.IO;
- public static class JsonManager
- {
- public static string directory = "/JasonSave/";
- public static string fileName = "saveFile.json";
- //string dataType =
- private static string GetFullDataPath()
- {
- return Application.dataPath + directory + fileName;//dataPath persistentDataPath streamingAssetsPath
- }
- public static bool SaveCheck()
- {
- string dir = GetFullDataPath();
- //Debug.Log(File.Exists(dir));
- //Debug.Log(Directory.Exists(dir));
- if (File.Exists(dir))
- {
- //Debug.Log("file is there");
- return true;
- }
- else
- {
- //Debug.Log("file not there");
- return false;
- }
- }
- public static void Save(GameData sd)
- {
- //Debug.Log(sd);
- string dir = Application.dataPath + directory;
- if (!Directory.Exists(dir))
- Directory.CreateDirectory(dir);
- string json = JsonUtility.ToJson(sd, true);
- File.WriteAllText(dir + fileName, json);
- //Debug.Log("Save Action Finished");
- }
- public static GameData Load()
- {
- string fullPath = GetFullDataPath();
- GameData so;
- string json = File.ReadAllText(fullPath);
- so = JsonUtility.FromJson<GameData>(json);
- //Debug.Log("File Loaded");
- //return null;
- return so;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement