SaveLoadGrid

Updated on August 3, 2022

public static void SaveCurrentGrid (GridSquare gridSquare)

Saves the given gridSquare to disk under

string path = $"{Application.persistentDataPath}/{SceneManager.GetActiveScene().name}";

The file name will contain the gridSquare.name plus its id.

Note. This save path is relevent only to the user. Any save files shipped with the product will be redundent as Application.persistantDataPath is different for each OS. To save a file that can be shipped, see SavePreconfiguration.

All placed object data is saved using the GridObject class along with the GridData class and is converted to binary.

Being a static class this can be called from anywhere without reference.

public GridSquare gridSquare;
public Button saveBtn;

void Start() 
{
    saveBtn.onClick.AddListener(() => 
    {
         //Saves the given GridSquare
         SaveLoadGrid.SaveCurrentGrid(gridSquare);
    });
}

public static GridData LoadCurrentGrid(GridSquare gridSquare)

Finds and loads the given gridSquare looking for this file

string filePath = $"{Application.persistentDataPath}/{SceneManager.GetActiveScene().name}/{gridSquare.name.Replace(" ", string.Empty)}-{id}.data";

If no save file is found, this function will also try and look for a preconfig named.

string configFilePath = $"{Application.dataPath}/GolemiteGames/GridBuilder2/PreConfig/{SceneManager.GetActiveScene().name}/{gridSquare.name.Replace(" ", string.Empty)}-{id}.preconfig";

You can load the same way as you saved.

public GridSquare gridSquare;
public Button loadBtn;

void Start() 
{
    loadBtn.onClick.AddListener(() => 
    {
         //Saves the given GridSquare
         SaveLoadGrid.LoadCurrentGrid(gridSquare);
    });
}

If it is confusing which file will load, take a look at the flow chart explaination.

public static void DeleteCurrentGridSaveData(GridSquare gridSquare)

Removes the given gridSquare‘s save file from disk if there is one.

Be careful using this as there is no backup of this file.

public static void SavePreconfiguration(GridSquare gridSquare)

This will save your current preconfiguration to disk under

string path = $"{Application.dataPath}/GolemiteGames/GridBuilder2/PreConfig/{SceneManager.GetActiveScene().name}";

This is used primarily in the GridSquare inspector but can also be called from elsewhere.

Note. The application has to be in Play mode for this method to work.

public static GridData LoadPreconfiguration(GridSquare gridSquare)

Loads the gridSquare preconfig if there is one, looks under

string configFilePath = $"{Application.dataPath}/GolemiteGames/GridBuilder2/PreConfig/{SceneManager.GetActiveScene().name}/{gridSquare.name.Replace(" ", string.Empty)}-{id}.preconfig";

You can set this up easily via the inspector to load the preconfig on start or you can call it yourself.

public GridSquare gridSquare;
void Start() 
{
    SaveLoadGrid.LoadPreconfiguration(gridSquare);
}

If it is confusing which file will load, take a look at the flow chart explaination.

public static void DeletePreconfiguration(GridSquare gridSquare)

Removes the preconfig file for the given gridSquare if one is found.

Be careful using this as there is no backup of this file.

Still need help? Contact support at support@golemitegames.com

Please describe your issue in detail and if possible, provide screenshots to help us understand your problem better and answer your question more effectively.