Okay, I’ve looked around but can’t find anything that helps me out with this issue:
I have a list, containing several custom classes, identical in layout to the example below which is a snippet from one single file, OldSystem.cs :
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
[Serializable]
public enum DriveType {
Floppy,
HDD,
SSD,
Optical
}
[Serializable]
public class File {
public string fileName;
public int fileSize;
public List<string> contents = new List<string>();
public File(string fName, int fSize)
{
fileName = fName;
fileSize = fSize;
}
}
[Serializable]
public class Drive {
public string letter;
[SerializeField]
public DriveType driveType;
[SerializeField]
public List<File> files = new List<File>();
public Drive(string assignedLetter, DriveType type)
{
letter = assignedLetter;
driveType = type;
}
}
[RequireComponent(typeof(AudioSource))]
public class OldSystem : MonoBehaviour {
[SerializeField]
public Drive[] drives;
// Rest of main script code here
....
}
I would like to be able to save the drives list from the OldSystem.cs MonoBehaviour somehow, as it is modified at runtime (either in the Editor or in the standalone build - but mostly the Editor at the moment) so that when I go back to the Editor, the changes are persistant.
As you can see, I’ve used a scattergun loaded with [Serializable] statements on the script, but to be honest I don’t really understand what they do or how serialization works.
I would be more than happy if someone can point me in the direction of a script or tutorial or some guidance on how to save the drives list to an XML file or other type of file in the Assets folder, perhaps - so long as that approach would work with a standalone build as well.
Otherwise, any help or suggestions would be gratefully received. I’m certainly not a beginner at programming, but I’m very inexperienced at this particular sort of thing (serialization, getting Unity to save data etc.)
Have I even declared the DriveType enum, File class or Drive class in the right places?
Thanks! ![]()