Hello, looking for some advice on a good way to save data between scenes.
What needs to be saved: (Other stuff as well, but most concerned about these):
Booleans (doesn’t necessarily need to be in Array)
Weapon Objects (preferably a List or Array, See below)
using UnityEngine;
using System.Collections;
public class Weapon
{
// INSTANCE FIELDS
private string weaponType;
private string weaponName;
private Texture weaponImage;
private AudioClip weaponSound;
private float damage;
private int clipSize;
private float range;
private float rateOfFire;
private int currentClip;
private float reloadTime;
private bool isAutomatic;
// CONSTRUCTOR
public Weapon(string weaponTypeIn, string weaponNameIn, Texture weaponImageIn, AudioClip weaponSoundIn, float damageIn, int clipSizeIn, float rangeIn, float rateOfFireIn, float reloadTimeIn, bool isAutomaticIn)
{
weaponType = weaponTypeIn;
weaponName = weaponNameIn;
weaponImage = weaponImageIn;
weaponSound = weaponSoundIn;
damage = damageIn;
clipSize = clipSizeIn;
range = rangeIn;
rateOfFire = rateOfFireIn;
reloadTime = reloadTimeIn;
isAutomatic = isAutomaticIn;
currentClip = clipSize;
}
}
Game Structure
2 Primary Scenes : Scene A - > Scene B - > Scene A
The Current Plan
Have a dontdestroy gameobject called tempSave in scene A store all the changes. These changes would affect the game, but wouldn’t be permanently stored on the HD. This object would persist until, when in Scene B, the user chooses to return to Scene A. Then all the information would be serialised, and stored on the HD. When Scene A begins, the data would be retreived and a new tempSave object would be created and populated with the info. Does this approach make sense? Are there any problems with it?
Additional Question
I understand there are 2 options for serialising data in unity, one using XML, the other a mono class. Which would be best for my purposes?
Sorry for the long post, and thanks for reading and your help!