I have this basic script that will convert a basic File and turn it into a .txt file and back again. My problem is that in my Save and Load methods, I want to be able to put any file reference into it without having to make several copies of that same script.
using UnityEngine;
using System.IO;
[System.Serializable]
public class SaveLoadSystem
{
public string FileLocation;
public string Filename;
public void GetPath()
{
FileLocation = Path.Combine(Application.dataPath + "/" + FileLocation, Filename + ".txt");
}
public void Save(MonoBehaviour Data)
{
string DataInfo = JsonUtility.ToJson(Data);
File.WriteAllText(FileLocation, DataInfo);
}
public void Load(ScriptableObject Data)
{
string DataInfo = File.ReadAllText(FileLocation);
JsonUtility.FromJsonOverwrite(DataInfo, Data);
}
}
I want to be able to put this into another script and say, save Obj1 file, but not have to put (Obj1 Data) in the save and load methods. I want to make them universal~ So I can say Save Obj2 file from one script and then maybe say save Obj3 file from another one, but not have a separated script for each Obj I want to save.