Example #1
0
    public void Load <T>(String path) where T : ISaveable
    {
        T loadedObject = default;

        try {
            string     destination = Application.persistentDataPath + String.Format("/{0}.dat", path);
            FileStream file;

            if (File.Exists(destination))
            {
                file = File.OpenRead(destination);
            }
            else
            {
                throw (new NoPathExeption(String.Format("Path {0} does not exisit, but load attempted.", path)));
            }

            BinaryFormatter bf   = new BinaryFormatter();
            string          json = (String)bf.Deserialize(file);
            file.Close();

            loadedObject = jsonTraslator.TranslateToObject <T>(json);
            loadedObject.RecoverIfNeeded();
        } catch (Exception e) {
            Debug.Log($"error on path {path}: {e.Message}");
        }

        gameState.LoadData(loadedObject);
    }