A set of flexible abstract classes that you can implement to integrate seamlessly with example UIView components such as Main Menu and Save/Load .
An example implementation that you can use as a starting point. You can refer to the demo game samples to see it in action.
Copy public class GameSaveManagerExample : GameSaveManager < GameSaveDataExample >
{
[ MultiLineHeader ( "This is a mockup. The save system is not included." )]
[ SerializeField ] private int _mockSaveAmount = 50 ;
private Dictionary < string , GameSaveDataExample > _saveMockUp = new Dictionary < string , GameSaveDataExample >();
public Dictionary < string , GameSaveDataExample > SaveMockUp => _saveMockUp;
protected override void Awake ()
{
base.Awake();
for ( int saveSlot = 0 ; saveSlot < _mockSaveAmount; saveSlot ++ )
{
string fileName = GetSaveFileName(saveSlot);
GameSaveDataExample data = new GameSaveDataExample ();
data . Gold = UnityEngine . Random .Range( 100 , 1000 );
_saveMockUp .Add(fileName , data);
}
}
protected override GameSaveDataExample GetNewSave ()
{
return new GameSaveDataExample ();
}
protected override List < string > GetAllFileNames ()
{
return _saveMockUp . Keys .ToList();
}
protected override void OnDeleteRequest ( string fileName)
{
_saveMockUp .Remove(fileName);
}
protected override void OnSaveRequest ( string fileName , GameSaveDataExample data)
{
_saveMockUp .Add(fileName , data);
}
protected override string GetFileExtenstion ()
{
return "save" ;
}
}
Copy [ Serializable ]
public class GameSaveDataExample : GameSaveData
{
public int Gold;
public NotificationHistory NotificationHistory;
public GameSaveDataExample () : base()
{
// New Save
Gold = 500 ; // Starting gold
NotificationHistory = new ();
}
public override void Load ( string fileName , int number)
{
GameSaveManagerExample saveManager = ( GameSaveManagerExample ) GameSaveManagerExample . Instance ;
if (saveManager != null )
{
GameSaveDataExample loaded = saveManager . SaveMockUp [fileName];
SaveDate = loaded . SaveDate ;
Gold = loaded . Gold ;
NotificationHistory = loaded . NotificationHistory ;
}
else
{
Debug .LogError( "GameSaveManagerExample not found" );
}
}
}
Copy [ CreateAssetMenu (fileName = "GameSaveDataSO" , menuName = "CupkekGames/Samples/Standart/GameSaveData" )]
public class GameSaveDataSOExample : GameSaveDataSO < GameSaveDataExample >
{
// Empty class body, just for implementing generic class
}