public static void OnImportSettings(string import)
{
if(!string.IsNullOrEmpty(import)) //check if there is a string at all to work with
{
try //optinoal but i recommend wrappingt he actual method in a try catch block
{
UserSettings sett = Export_Import.Deserialize<UserSettings>(import); //this will create an object of type UserSettings from the import string
Main.mOptionen = sett; //Store the Settings somewhere
}
catch(Exception e)
{
Debug.ShowException(e); //if there is an error show it to the user (optional)
}
}
}
1 Create a method to export our object
Code:
public static void ExportMySettings()
{
try
{
string export = Main.mOptionen.ToExportString(); //This will serialize(convert) mOptionen into a string and store it in "export"
Export_Import.ExportObject("CreatorName","Modname",false, true, export); //The actual exporting happens here
}
catch(Exception e)
{
Debug.ShowException(e);
}
}
2. Creating the Menu
Code:
public static MenuContainer SerializationMenu; //Somewhere in your project
SerializationMenu = new MenuContainer("MenuTitle") //Create a new Menu
3. Adding the Menu options
Code:
MenuGetter ImportSavedSettings = MenuContainer.Presets.CreateFileImportMenu_S3SE("CreatorName", "Modname", OnImportSettings); //Create The Menu to Import Settings
performActionOption ExportSettings = new performActionOption("Export Settings", ExportMySettings); //Create an clickable option that will export your settings
MenuSelectionOption SelectImportSavedSettings = new MenuSelectionOption("Import Settings", ImportSavedSettings ); //Add an option to the main menu that opens our Import Menu
SerializationMenu.AddMenuObject(SelectImportSavedSettings,true,"SelectImportSavedSettings"); // Add the opening of the import menu to our menu
SerializationMenu.AddMenuObject(ExportSettings,true,"ExportSettings"); // Add the exportoption to our menu
4. Opening our Menu
Code:
Battery.UI.Menus.MenuController.Show(SerializationMenu); //This will bring up the menu we created before