So I have been trying to save a string list with xml serialization but unfortunately I couldn’t figure out how it works with my poor knowledge on scripting.
It would be really nice if someone could help me write a script which will load & save my list with this way.
public List Collected = new List();
That’s my code. My list handles the progress of my player on the entire game so it is very important to be able to save it and load it whenever he/she wants. I don’t know how many ways can a list be formatted but I would like to be able to save this list on all mobile platforms (iOS, Android, Windows and blackberry - optional)
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class GameController : MonoBehaviour {
public static GameController Controller;
public int Lives;
public int Wumpas;
public int Health;
// Use this for initialization
void Awake () {
if (Controller == null) {
DontDestroyOnLoad (gameObject);
Controller = this;
}
else if (Controller != null) {
Destroy(gameObject);
}
}
// Update is called once per frame
void Update () {
}
public void Save() {
PlayerPrefs.SetInt ("Wumpas", Wumpas);
PlayerPrefs.SetInt ("Lives", Lives);
PlayerPrefs.SetInt ("Health", Health);
}
public void Load() {
Wumpas = PlayerPrefs.GetInt ("Wumpas");
Lives = PlayerPrefs.GetInt ("Lives");
Health = PlayerPrefs.GetInt ("Health");
}
public List<string> Uncollected = new List<string>();
public List<string> Collected = new List<string>();
public void Earned(string name) {
Uncollected.Remove(name);
Collected.Add(name);
}
}