Created
May 6, 2020 10:29
-
-
Save JonathanMCarter/481011dc05df336ede6b2eacedab4a90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using System.IO; | |
using System.Runtime.Serialization.Formatters.Binary; | |
namespace Arcade.Saving | |
{ | |
public static class SaveManager | |
{ | |
#region Save Methods | |
/// <summary> | |
/// Saves Settings Data | |
/// </summary> | |
/// <param name="Settings">Settings Script With the data to save</param> | |
public static void SaveArcadeSettings(Menu.SettingsScript Settings) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
string SavePath = Application.persistentDataPath + "/settings.microarcade"; | |
FileStream Stream = new FileStream(SavePath, FileMode.Create); | |
ArcadeData Data = new ArcadeData(Settings); | |
Formatter.Serialize(Stream, Data); | |
Stream.Close(); | |
} | |
/// <summary> | |
/// Saves Control Scheme | |
/// </summary> | |
/// <param name="Scheme">The supported controller setting to save</param> | |
public static void SaveArcadeControlScheme(SupportedControllers Scheme) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
string SavePath = Application.persistentDataPath + "/controlconfig.microarcade"; | |
FileStream Stream = new FileStream(SavePath, FileMode.Create); | |
ArcadeData Data = new ArcadeData(Scheme); | |
Formatter.Serialize(Stream, Data); | |
Stream.Close(); | |
} | |
/// <summary> | |
/// Save Operation Starshine Ship Selections | |
/// </summary> | |
/// <param name="Selection">Ship Selection Script to get the data from</param> | |
public static void SaveOperationStarshine(Starshine.ShipSelection Selection) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
string SavePath = Application.persistentDataPath + "/starshine.microarcade"; | |
FileStream Stream = new FileStream(SavePath, FileMode.Create); | |
OperationStarshineData Data = new OperationStarshineData(Selection); | |
Formatter.Serialize(Stream, Data); | |
Stream.Close(); | |
} | |
public static void SaveOperationStarshine(Leaderboard.StarshineLeaderboardData LeaderboardData) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
string SavePath = Application.persistentDataPath + "/starshine-leaderboard.microarcade"; | |
FileStream Stream = new FileStream(SavePath, FileMode.Create); | |
Formatter.Serialize(Stream, LeaderboardData); | |
Stream.Close(); | |
} | |
public static void SaveUltimatePinballGamemode(int Gamemode = 0, int Increment = 0, int LastValue = 0) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
string SavePath = Application.persistentDataPath + "/pinball.microarcade"; | |
FileStream Stream = new FileStream(SavePath, FileMode.Create); | |
UltimatePinballData Data = new UltimatePinballData(); | |
Data.LastGameTypeSelected = Gamemode; | |
Data.LastGameTypeIncrement = Increment; | |
Data.LastGameTypeAmountSelected = LastValue; | |
Formatter.Serialize(Stream, Data); | |
Stream.Close(); | |
} | |
public static void SaveUltimatePinballSession(string Player1Name, int Player1Score, string Player2Name, int Player2Score, int Player1Health = 0, int Player2Health = 0) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
string SavePath = Application.persistentDataPath + "/pinballsession.microarcade"; | |
FileStream Stream = new FileStream(SavePath, FileMode.Create); | |
UltimatePinballSessionData Data = new UltimatePinballSessionData(); | |
Data.Player1Name = Player1Name; | |
Data.Player1Score = Player1Score; | |
Data.Player1Health = Player1Health; | |
Data.Player2Name = Player2Name; | |
Data.Player2Score = Player2Score; | |
Data.Player2Health = Player2Health; | |
Formatter.Serialize(Stream, Data); | |
Stream.Close(); | |
} | |
public static void SaveUltimatePinballSession(Pinball.GameManager.BG_PlayerStats Player1Stats, Pinball.GameManager.BG_PlayerStats Player2Stats) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
string SavePath = Application.persistentDataPath + "/pinballsession.microarcade"; | |
FileStream Stream = new FileStream(SavePath, FileMode.Create); | |
UltimatePinballSessionData Data = new UltimatePinballSessionData(); | |
Data.Player1Name = Player1Stats.Name; | |
Data.Player1Score = Player1Stats.Score; | |
Data.Player1Health = Player1Stats.Health; | |
Data.Player2Name = Player2Stats.Name; | |
Data.Player2Score = Player2Stats.Score; | |
Data.Player2Health = Player2Stats.Health; | |
Formatter.Serialize(Stream, Data); | |
Stream.Close(); | |
} | |
public static void SaveUltimatePinballSession(UltimatePinballSessionData Input) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
string SavePath = Application.persistentDataPath + "/pinballsession.microarcade"; | |
FileStream Stream = new FileStream(SavePath, FileMode.Create); | |
UltimatePinballSessionData Data = new UltimatePinballSessionData(); | |
Data = Input; | |
Formatter.Serialize(Stream, Data); | |
Stream.Close(); | |
} | |
#endregion | |
#region Load Methods | |
/// <summary> | |
/// Loads the Arcade settings data and returns it | |
/// </summary> | |
/// <returns>ArcadeData with Settings</returns> | |
public static ArcadeData LoadArcadeSettings() | |
{ | |
string SavePath = Application.persistentDataPath + "/settings.microarcade"; | |
if (File.Exists(SavePath)) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
FileStream Stream = new FileStream(SavePath, FileMode.Open); | |
ArcadeData Data = Formatter.Deserialize(Stream) as ArcadeData; | |
Stream.Close(); | |
return Data; | |
} | |
else | |
{ | |
Debug.LogError("Save file not found! (Arcade Settings - Load)"); | |
return null; | |
} | |
} | |
/// <summary> | |
/// Loads the Arcade control scheme | |
/// </summary> | |
/// <returns>ArcadeData with Control Scheme</returns> | |
public static ArcadeData LoadArcadeControlScheme() | |
{ | |
string SavePath = Application.persistentDataPath + "/controlconfig.microarcade"; | |
if (File.Exists(SavePath)) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
FileStream Stream = new FileStream(SavePath, FileMode.Open); | |
ArcadeData Data = Formatter.Deserialize(Stream) as ArcadeData; | |
Stream.Close(); | |
return Data; | |
} | |
else | |
{ | |
Debug.LogError("Save file not found! (Arcade Control Scheme - Load)"); | |
return null; | |
} | |
} | |
/// <summary> | |
/// Loads the data for operation starshine | |
/// </summary> | |
/// <returns>Loaded OperationStarshineData</returns> | |
public static OperationStarshineData LoadOperationStarshine() | |
{ | |
string SavePath = Application.persistentDataPath + "/starshine.microarcade"; | |
if (File.Exists(SavePath)) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
FileStream Stream = new FileStream(SavePath, FileMode.Open); | |
OperationStarshineData Data = Formatter.Deserialize(Stream) as OperationStarshineData; | |
Stream.Close(); | |
return Data; | |
} | |
else | |
{ | |
Debug.LogError("Save file not found! (OP:SS - Load)"); | |
return null; | |
} | |
} | |
public static UltimatePinballData LoadUltimatePinball() | |
{ | |
string SavePath = Application.persistentDataPath + "/pinball.microarcade"; | |
if (File.Exists(SavePath)) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
FileStream Stream = new FileStream(SavePath, FileMode.Open); | |
UltimatePinballData Data = Formatter.Deserialize(Stream) as UltimatePinballData; | |
Stream.Close(); | |
return Data; | |
} | |
else | |
{ | |
Debug.LogError("Save file not found! (Ultimate Pinball - Load)"); | |
return null; | |
} | |
} | |
public static UltimatePinballSessionData LoadLastUltimatePinballSession() | |
{ | |
string SavePath = Application.persistentDataPath + "/pinballsession.microarcade"; | |
if (File.Exists(SavePath)) | |
{ | |
BinaryFormatter Formatter = new BinaryFormatter(); | |
FileStream Stream = new FileStream(SavePath, FileMode.Open); | |
UltimatePinballSessionData Data = Formatter.Deserialize(Stream) as UltimatePinballSessionData; | |
Stream.Close(); | |
return Data; | |
} | |
else | |
{ | |
Debug.LogError("Save file not found! (Ultimate Pinball Session - Load)"); | |
return null; | |
} | |
} | |
#endregion | |
public static void Reset() | |
{ | |
string PinballDataSavePath = Application.persistentDataPath + "/pinballsession.microarcade"; | |
string PinballSavePath = Application.persistentDataPath + "/pinball.microarcade"; | |
string StarshineDataSavePath = Application.persistentDataPath + "/starshine.microarcade"; | |
string ControllerConfigPath = Application.persistentDataPath + "/controlconfig.microarcade"; | |
string SettingsSavePath = Application.persistentDataPath + "/settings.microarcade"; | |
if (File.Exists(PinballDataSavePath)) | |
{ | |
File.Delete(PinballDataSavePath); | |
} | |
if (File.Exists(PinballSavePath)) | |
{ | |
File.Delete(PinballSavePath); | |
} | |
if (File.Exists(StarshineDataSavePath)) | |
{ | |
File.Delete(StarshineDataSavePath); | |
} | |
if (File.Exists(ControllerConfigPath)) | |
{ | |
File.Delete(ControllerConfigPath); | |
} | |
if (File.Exists(SettingsSavePath)) | |
{ | |
File.Delete(SettingsSavePath); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment