Records

Records are easily modifiably values that can be accessed from anywhere. A simple example of this would be an integer value for GoldSpent by a player. We will use this example in the examples below.

Records are divided into categories. This way it is easy to group certain records together. If you do not plan to use categories I suggest using a default value like "General" as category.

Scene Setup

In order for the Records to be saved and loaded correctly, the RecordManager needs to be added to your scene. Just add an empty GameObject anywhere in your scene and add the RecordManager script to it.

Basic Records

Creating/Updating a basic Record

// Creates a new entry if it does not exist. If it exists it overrides the value with a new one
RecordManager.Instance.CreateOrUpdateEntry("MyCategory", "GoldSpent", 5);

Getting a value for a basic record

// Gets a value for a record. Change the int type to whatever value your record is supposed to be.
var value = RecordManager.Instance.GetEntryFromRecord<int>("MyCategory", "GoldSpent");

Resetting all records in a category

RecordManager.Instance.Reset("MyCategory");

History Records

While basic records can be handy, there are a lot of usecases where you want to keep track of when things happend. If we want to keep track when the player spent his gold, and keep the transactions, we can use History Records to retrieve values.

Creating/Updating a history Record

// Creates a new entry if it does not exist. If it exists it adds a new transaction to the list
RecordManager.Instance.CreateOrUpdateHistoryEntry("MyCategory", "GoldSpent", 5);

Getting a value for a history record

// Gets a value for a history record. Change the int type to whatever value your singular record entry is supposed to be.
// This method return a list of transactions
var value = RecordManager.Instance.GetHistoryEntryFromRecord<int>("MyCategory", "GoldSpent");

This page was last edited on 2024-03-09 11:41

Powered by Wiki|Docs

This page was last edited on 2024-03-09 11:41

BiteMe Games
2024

Powered by Wiki|Docs