46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public class CacheController : MonoBehaviour
|
|
{
|
|
|
|
public static CacheController instance;
|
|
public string path;
|
|
BinaryFormatter bf = new BinaryFormatter();
|
|
private void Start()
|
|
{
|
|
instance = this;
|
|
path = Application.persistentDataPath;
|
|
}
|
|
|
|
public bool HasFile(string file)
|
|
{
|
|
if (File.Exists(path + "/" + file))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void SaveCache(List<ClassContents> info, string filePath)
|
|
{
|
|
FileStream file = File.Create(path + "/" + filePath);
|
|
bf.Serialize(file, info);
|
|
file.Close();
|
|
}
|
|
|
|
public List<ClassContents> LoadCache(string filePath)
|
|
{
|
|
FileStream file = File.Open(path + "/" + filePath, FileMode.Open);
|
|
List<ClassContents> cc = (List<ClassContents>)bf.Deserialize(file);
|
|
file.Close();
|
|
return cc;
|
|
}
|
|
}
|