SaveData.cs
/// <summary>
/// Load data using a string identifier
/// </summary>
/// <typeparam name="T">Type of object to load</typeparam>
/// <param name="key">String identifier for the data to load</param>
/// <returns></returns>
Load data using a string identifier
Load data using a string identifier
public static T Load<T>(string key)
    {
        string path = Application.persistentDataPath + "/saves/";
        BinaryFormatter formatter = new BinaryFormatter();
        FileStream fileStream = new FileStream(path + key + ".txt", FileMode.Open);
        T returnValue = default(T);
        try
        {
            returnValue = (T)formatter.Deserialize(fileStream);
        }
        catch (SerializationException exception)
        {
            Debug.Log("Load failed. Error: " + exception.Message);
        }
        finally
        {
            fileStream.Close();
        }
        return returnValue;
    }
public static T Load < T > ( string key ) { string path = Application . persistentDataPath + " " ; BinaryFormatter formatter = new BinaryFormatter ( ) ; FileStream fileStream = new FileStream ( path + key + " " , FileMode . Open ) ; T returnValue = default ( T ) ; try { returnValue = ( T ) formatter . Deserialize ( fileStream ) ; } catch ( SerializationException exception ) { Debug . Log ( " " + exception . Message ) ; } finally { fileStream . Close ( ) ; } return returnValue ; }
Load data using a string identifier
Load data using a string identifier
// Set the path to the persistent data path (works on most devices by default) // Grab an instance of the BinaryFormatter that will handle serializing our data // Open up a filestream, combining the path and object key // Initialize a variable with the default value of whatever type we're using /* 
         * Try/Catch/Finally block that will attempt to deserialize the data
         * If we fail to successfully deserialize the data, we'll just return the default value for Type
         */
None
key
string
String identifier for the data to load
String identifier for the data to load
typeparam
Type of object to load
Type of object to load