top of page


namespace - XGI.Tools

This is an encapsulation of all the necessary features required for saving and loading game data. It makes the processes easier and compact.

It is an abstract class, so you need to derive it to the data container class in order to use it. The container class will then have all the features of DataFileManager class.

The process of doing so is as follows -

using System;
using XGI.Tools;

public class GameData : DataFileManager
    ⋮   //Game Data

    public GameData(string directory) : base(directory){}
    public override object GetInstance() => this;

Once the data container class is set up, all that needs to be done, is creating an object of the class.

The save game directory is to passed along with instantiation of this class.

public GameData gameData;

private void Awake() // Or anywhere appropriate


    gameData = new GameData(Application.persistentDataPath + "data.dat");


Everything is done, now the game can be saved or loaded any time using only one line of code which would be -




gameData = (GameData)gameData.LoadData();


Constructor -

  • DataFileManager(string directory) => The directory where the game is to be saved. Usually it should start with Application.persistentDataPath + ...

Properties -

  • bool IsDataExist => True if save file exist in the said location, false otherwise

Methods -

  • void SaveData() => Save the data

  • object LoadData() => Returns boxed saved data, it must be casted to the type of its serializable data container class

bottom of page