public static void SaveBackpackItem(BackpackScript backpackScript)
    {
        BinaryFormatter binaryFormatter = new BinaryFormatter();
        FileStream      fileStream      = new FileStream(PathForFile(), FileMode.Create);

        BackpackDataScript backpackDataScript = new BackpackDataScript(backpackScript);

        binaryFormatter.Serialize(fileStream, backpackDataScript);
        fileStream.Close();
    }
Ejemplo n.º 2
0
    public void LoadBackpack()
    {
        BackpackDataScript backpackDataScript = SaveLoadBackpackSystemScript.LoadBackpackItem();

        if (transform.childCount > 0)
        {
            itemName   = backpackDataScript.itemInBackpackName;
            itemObject = GameObject.Find(itemName);
        }

        if (itemObject != null)
        {
            itemObject.transform.parent   = transform;
            itemObject.transform.position = transform.position;
        }
    }
    public static BackpackDataScript LoadBackpackItem()
    {
        if (File.Exists(PathForFile()))
        {
            BinaryFormatter binaryFormatter = new BinaryFormatter();
            FileStream      fileStream      = new FileStream(PathForFile(), FileMode.Open);

            BackpackDataScript backpackDataScript = binaryFormatter.Deserialize(fileStream) as BackpackDataScript;
            fileStream.Close();

            return(backpackDataScript);
        }
        else
        {
            Debug.LogError("File not found");
            return(null);
        }
    }