Open-sourced some code
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable()]
|
||||
public class ConfigurationManager {
|
||||
//singleton members
|
||||
private static ConfigurationManager singletonObject = null;
|
||||
public static ConfigurationManager Instance {
|
||||
get {
|
||||
if (singletonObject == null) {
|
||||
string fname = Path.Combine(Application.persistentDataPath, "configuration.json");
|
||||
new ConfigurationManager(fname); //NOTE: singleton object assigned elsewhere
|
||||
}
|
||||
return singletonObject;
|
||||
}
|
||||
}
|
||||
|
||||
//serializable fields (these can be null, so handle that elsewhere)
|
||||
public string textSpeed;
|
||||
public float volume;
|
||||
|
||||
//private internal members
|
||||
static bool initialized = false; //BUGFIX: stack overflow
|
||||
static string dataPath;
|
||||
|
||||
//methods
|
||||
private ConfigurationManager(string fname) {
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
LoadData(fname);
|
||||
dataPath = fname;
|
||||
}
|
||||
}
|
||||
|
||||
public void CleanUp() {
|
||||
SaveData(Instance, dataPath);
|
||||
}
|
||||
|
||||
void LoadData(string fname) {
|
||||
if (!File.Exists(fname)) {
|
||||
singletonObject = JsonUtility.FromJson<ConfigurationManager> ("{}");
|
||||
return;
|
||||
}
|
||||
|
||||
StreamReader streamReader = File.OpenText(fname);
|
||||
string jsonString = streamReader.ReadToEnd();
|
||||
streamReader.Close();
|
||||
singletonObject = JsonUtility.FromJson<ConfigurationManager> (jsonString);
|
||||
|
||||
//reset statics
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void SaveData(ConfigurationManager configMgr, string fname) {
|
||||
string jsonString = JsonUtility.ToJson(configMgr);
|
||||
StreamWriter streamWriter = File.CreateText(fname);
|
||||
streamWriter.Write(jsonString);
|
||||
streamWriter.Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PauseManager {
|
||||
//singleton members
|
||||
private static PauseManager singletonObject = null;
|
||||
public static PauseManager Instance {
|
||||
get {
|
||||
if (singletonObject != null) {
|
||||
return singletonObject;
|
||||
} else {
|
||||
return singletonObject = new PauseManager();
|
||||
}
|
||||
}
|
||||
set {
|
||||
singletonObject = value;
|
||||
}
|
||||
}
|
||||
|
||||
//paused controller
|
||||
bool paused = false;
|
||||
public bool Paused {
|
||||
get {
|
||||
return paused;
|
||||
}
|
||||
set {
|
||||
paused = value;
|
||||
TriggerLists();
|
||||
}
|
||||
}
|
||||
|
||||
public delegate void CallbackHandler();
|
||||
|
||||
List<CallbackHandler> onPausedList = new List<CallbackHandler>();
|
||||
List<CallbackHandler> onResumeList = new List<CallbackHandler>();
|
||||
|
||||
private PauseManager() {}
|
||||
|
||||
public void PushOnPaused(CallbackHandler callback) {
|
||||
onPausedList.Add(callback);
|
||||
}
|
||||
|
||||
public void PushOnResume(CallbackHandler callback) {
|
||||
onResumeList.Add(callback);
|
||||
}
|
||||
|
||||
public void PurgeLists() {
|
||||
onPausedList.Clear();
|
||||
onResumeList.Clear();
|
||||
}
|
||||
|
||||
void TriggerLists() {
|
||||
if (Paused) {
|
||||
foreach(CallbackHandler callback in onPausedList) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
else {
|
||||
foreach(CallbackHandler callback in onResumeList) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
public class SaveFileManager {
|
||||
//public structures
|
||||
[Serializable()]
|
||||
public class SaveSlot {
|
||||
//serializable fields (these can be null, so handle that elsewhere)
|
||||
public string currentLocation; //name of the pedestal
|
||||
public float secondsPlaying;
|
||||
public string awardImage; //TODO: award image
|
||||
|
||||
//abilities
|
||||
public bool flameBody;
|
||||
public bool chargeSwipe;
|
||||
public bool wallSlide;
|
||||
public bool flameProjectile;
|
||||
public bool flameWings;
|
||||
}
|
||||
|
||||
//singleton members
|
||||
private static SaveFileManager singletonObject = null;
|
||||
public static SaveFileManager Instance {
|
||||
get {
|
||||
if (singletonObject == null) {
|
||||
singletonObject = new SaveFileManager();
|
||||
}
|
||||
return singletonObject;
|
||||
}
|
||||
}
|
||||
|
||||
//private internal members
|
||||
//
|
||||
|
||||
private SaveFileManager() {
|
||||
//
|
||||
}
|
||||
|
||||
//public members
|
||||
public static string saveSlotFileName; //NOT part of the save structure; only one can be loaded into the game at a time
|
||||
public static SaveSlot LoadedSaveSlot { get; set; }
|
||||
|
||||
//methods
|
||||
public static SaveSlot LoadData(string fname) {
|
||||
if (!File.Exists(fname)) {
|
||||
return JsonUtility.FromJson<SaveSlot> ("{}");
|
||||
}
|
||||
|
||||
StreamReader streamReader = File.OpenText(fname);
|
||||
string jsonString = streamReader.ReadToEnd();
|
||||
streamReader.Close();
|
||||
|
||||
return JsonUtility.FromJson<SaveSlot> (jsonString);
|
||||
}
|
||||
|
||||
public static void SaveData(SaveSlot save, string fname) {
|
||||
string jsonString = JsonUtility.ToJson(save);
|
||||
|
||||
StreamWriter streamWriter = File.CreateText(fname);
|
||||
streamWriter.Write(jsonString);
|
||||
streamWriter.Close();
|
||||
}
|
||||
|
||||
public static SaveSlot CreateBlankSaveSlot() {
|
||||
SaveSlot saveSlot = new SaveSlot();
|
||||
|
||||
saveSlot.currentLocation = "Start";
|
||||
saveSlot.secondsPlaying = 0f;
|
||||
saveSlot.awardImage = "";
|
||||
|
||||
saveSlot.flameBody = false;
|
||||
saveSlot.chargeSwipe = false;
|
||||
saveSlot.wallSlide = false;
|
||||
saveSlot.flameProjectile = false;
|
||||
saveSlot.flameWings = false;
|
||||
|
||||
return saveSlot;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user