You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.5 KiB
80 lines
1.5 KiB
using UnityEngine;
|
|
using System;
|
|
using System.IO;
|
|
using System.Runtime.Serialization.Formatters.Binary;
|
|
|
|
[Serializable]
|
|
public class Settings {
|
|
|
|
public Audio audio;
|
|
|
|
public static string fileName;
|
|
|
|
public static Settings CreateDefault() {
|
|
return new Settings {
|
|
audio = Audio.CreateDefault()
|
|
};
|
|
}
|
|
|
|
public Settings() {
|
|
}
|
|
|
|
|
|
[Serializable]
|
|
public class Audio {
|
|
public float SfxVolume {
|
|
get; set;
|
|
}
|
|
public float MusicsVolume {
|
|
get; set;
|
|
}
|
|
public static Audio CreateDefault() {
|
|
return new Audio() {
|
|
MusicsVolume = 0,
|
|
SfxVolume = 0
|
|
};
|
|
}
|
|
public Audio() {
|
|
}
|
|
}
|
|
public enum AudioType {
|
|
Default
|
|
}
|
|
|
|
|
|
public static void Save(Settings settings, string path) {
|
|
|
|
BinaryFormatter bf = new BinaryFormatter();
|
|
FileStream file = File.Create(path);
|
|
|
|
bf.Serialize(file, settings);
|
|
file.Close();
|
|
|
|
Debug.Log("Successfully saved settings to " + fileName);
|
|
}
|
|
|
|
public static Settings Load(string path) {
|
|
if (File.Exists(path)) {
|
|
|
|
Debug.Log(fileName + " does exist. Starting loading settings.");
|
|
|
|
BinaryFormatter bf = new BinaryFormatter();
|
|
FileStream file = File.Open(path, FileMode.Open);
|
|
Settings settings = (Settings)bf.Deserialize(file);
|
|
file.Close();
|
|
|
|
Debug.Log("Settings successfully loaded from " + fileName + " : " + settings);
|
|
|
|
return settings;
|
|
}
|
|
else {
|
|
Debug.Log(fileName + " was not found. Creating default settings.");
|
|
|
|
Settings settings = CreateDefault();
|
|
|
|
Debug.Log("Default settings created: " + settings);
|
|
|
|
return settings;
|
|
}
|
|
}
|
|
}
|
|
|