Eye of the Nile Docs
Everything you need to know to get started!
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Pages
DataManager Class Reference

Detailed Description

This is the script on the DataManager prefab, which is responsible for storing critical data that needs to persist across scene reloads. Additionally, when the game is run through the Main Menu scene, the DataManager will load values from a file rather than using defaults. It will also save these values back to the file while the game is running, and when the application quits. The DataManager is persistent - it can never be destroyed, and there can only be one. This way, if the player loads a new scene by going through a door, the player object can get its health from the DataManager, thus “remembering what health it had.”

Documentation updated 2/3/2025

Author
Stephen Nuttall

Reference Variables

These are references to other objects this script needs to get information from.

static DataManager Instance
 
ActiveAbilityData activeAbilityData
 Reference to the ActiveAbilityData object.
 
AbilityInventory abilityInventory
 Reference to the AbilityInventory object.
 
TimeOfDayController ToDController
 Reference to the TimeOfDayController. Used to update the time of day after a scene reload.
 
GameObject player
 Reference to the player itself. Used to set the initial respawn point to the player’s position.
 

General Data

Data related to the player, time of day, soul counts, and more.

bool maatTalked = false
 If Ma'at has never been talked to before, the welcome message should be displayed.
 
bool skyhubExited = false
 If the player has ever exited the Skyhub.
 
int playerHealth = 100
 
int healthPotionCount = 0
 The amount of health potions the player currently has.
 
TimeOfDay defaultTimeOfDay = TimeOfDay.Day
 Default time of day when the game is first loaded.
 
int souls = 0
 Current amount of souls.
 
int godSouls = 0
 Current amount of god souls.
 
static string anubisDeathMessage [get, private set]
 The joke Anubis will tell when the player dies.
 
bool abilitiesUnlocked = false [get, private set]
 Whether the ability hotbar is unlocked yet or not.
 
bool skyhubUnlocked = false [get, private set]
 True if warp obelisks should allow the player to warp to the Skyhub. Unlocks after Geb is defeated.
 
bool skyhubLeadsToOpening = false [get, private set]
 Set to true and the Skyhub will spawn the player back at the Opening scene.
 
static TimeOfDay currTimeOfDay
 Time of day that should be restored when a new scene is loaded.
 

Volume Settings

The volume gets multiplied by these values in AudioManager.cs (values ranging from 0 to 1, accessible from the settings menu).

float masterVolumeSetting = 1f
 
float musicVolumeSetting = 1f
 The music volume gets multiplied by this values in AudioManager.cs (values ranging from 0 to 1).
 
float sfxVolumeSetting = 1f
 The SFX volume gets multiplied by this values in AudioManager.cs (values ranging from 0 to 1).
 

I/O attributes

Variables and objects used to save and load the game from a file.

string saveFileName
 
bool autosaveEnabled = true
 Controls whether or not autosaving is enabled. Can be disabled mid-play in the Unity Editor, but not restarted.
 
float autosaveFrequency = 3f
 How often the game should run the autosave function.
 
FileReadWrite fileReadWrite
 Class used to read and write data to a file.
 
bool readWriteEnabled = false
 True if the saving system is enabled at all (false when any scene other than the MainMenu is loaded)
 
bool noSaveFileFound [get, private set]
 True if no save file was found.
 

Scene Data

Details about the current scene, previous scene, and the respawn scene.

static int currSceneIndex [get, private set]
 
static int prevSceneIndex [get, private set]
 The index of the scene that was previously loaded.
 
static string currSceneName [get, private set]
 The name of the scene that is currently loaded.
 
static string prevSceneName [get, private set]
 The name of the scene that was previously loaded.
 
static string respawnSceneName [get, private set]
 The name of the scene the player’s respawn point is in.
 
Vector2 respawnPoint [get, private set]
 The coordinates of the player’s respawn point.
 

Events

Events that trigger when certain values are updated.

static Action< int > newSoulTotal
 
static Action< int > newGodSoulTotal
 When the amount of god souls the player has changes, this event is invoked.
 

Internal Functionality

These functions handle the inner workings of the data manager, ensuring all the data is recorded and restored correctly after a scene reload.

void OnEnable ()
 Subscribe all functions that need to monitor other functionality to the corresponding events.
 
void OnDisable ()
 Unsubscribe from all events when this object or script is disabled.
 
void Awake ()
 This is where most of the functionality of the DataManager happens, since Awake() is called right as the scene loads. Here are the steps that run when Awake() is called: First, we make sure this DataManager is the only DataManager, and it will not be destroyed in the next scene reload. If we're in the main menu scene (build index 0), enable the read/write system and read the save from file. Otherwise, start by finding the references for the reference variables listed above. Finally, these values are restored in their respective objects. We also check if respawnSceneName or respawnPoint are null. If so, they default to currentScene and the player’s current position.
 
void Start ()
 Start the autosave loop and update the volume levels.
 
void invokeEvents ()
 Invokes all events the DataManager has. Usually used when a new scene loads and all these values are updated. Right now, DataManager only has events related to the soul counts, which the display uses to know what number to put on the screen (that’s why it needs to be called when loading a new scene).
 

Saving and Loading

These functions are used to save and load the game from a file.

void readSaveFile ()
 Read from the save file and restore those values. If there is no save file, load the default values.
 
void writeSaveFile ()
 Write various values to the save file.
 
IEnumerator autosaveLoop ()
 Read from the save file and restore those values. If there is no save file, load the default values.
 
void OnApplicationQuit ()
 Read from the save file and restore those values. If there is no save file, load the default values.
 

Private Update Functions

These functions are helper functions that update data when called by Awake().

void updatePlayerHealth (int newHealth)
 Updates the DataManager’s record of player health. Subscribed to the onPlayerHealthChange event.
 
void updateSceneIndex ()
 If the currSceneIndex no longer matches the index of the actual current scene, update currSceneIndex and prevSceneIndex.
 
void updateSceneName ()
 If the currSceneName no longer matches the index of the actual current scene, update currSceneName and prevSceneName.
 
void updatePotionCount (int potionCount)
 Updates the DataManager’s record of player health. Subscribed to the onPlayerHealthChange event.
 
void updateAnubisDeathMessage (string newDeathMessage)
 

Public Getters

These functions allow other scripts to access (but not change) the data stored in the data manager.

TimeOfDay GetTimeOfDay ()
 Returns current time of day as a TimeOfDay enum.
 
int GetPlayerHealth ()
 Returns the player's health.
 
int GetSouls ()
 Returns number of souls the player has.
 
int GetGodSouls ()
 Returns number of god souls the player has.
 
int GetPrevSceneIndex ()
 Returns the index of the previous scene.
 
int GetCurrSceneIndex ()
 Returns the index of the current scene.
 
string GetPrevSceneName ()
 Returns the name of the previous scene.
 
string GetCurrSceneName ()
 Returns the name of the current scene.
 
string GetRespawnSceneName ()
 Returns the name of the scene with the player's respawn point.
 
Vector2 GetRespawnPoint ()
 Returns the name of the scene with the player's respawn point.
 
string GetAnubisDeathMessage ()
 Returns the joke Anubis will tell when the player dies.
 
float GetMasterVolume ()
 Returns the current master volume setting.
 
float GetMusicVolume ()
 Returns the current music volume setting.
 
float GetSFXVolume ()
 Returns the current SFX volume setting.
 
int GetHealthPotionCount ()
 Returns the current number of health potions the player has.
 

Public Update Functions

These functions allow other scripts to update data stored in the data manager.

void SetTimeOfDay (TimeOfDay newTime)
 Set the time of day to be either Day, Night, Eclipse, or BloodMoon. (Eclipse and BloodMoon not yet implemented).
 
void UpdateRespawnPoint (Vector2 newRespawnPoint)
 
void AddSouls (int numSouls)
 Adds the given amount of souls. Subscribes to the ObjectHealth.soulsDropped event.
 
void SubtractSouls (int numSouls)
 Subtracts the given amount of souls.
 
void AddGodSouls (int numSouls)
 Adds the given amount of god souls. Subscribes to the ObjectHealth.godSoulsDropped event.
 
void SubtractGodSouls (int numSouls)
 Subtracts the given amount of god souls.
 
void UnlockAbilities ()
 Unlocks the ability hotbar. (This depends on a scene reload)
 
void UnlockSkyhub ()
 Unlocks the Skyhub.
 
void SetSkyhubToOpening ()
 Tells the Skyhub that the player should return to the opening scene instead of the usual player's respawn position.
 
void UnsetSkyhubToOpening ()
 Tells the DataManager to stop making the Skyhub lead to the opening scene.
 

Member Function Documentation

◆ AddGodSouls()

void DataManager.AddGodSouls ( int numSouls)

Adds the given amount of god souls. Subscribes to the ObjectHealth.godSoulsDropped event.

◆ AddSouls()

void DataManager.AddSouls ( int numSouls)

Adds the given amount of souls. Subscribes to the ObjectHealth.soulsDropped event.

◆ autosaveLoop()

IEnumerator DataManager.autosaveLoop ( )
private

Read from the save file and restore those values. If there is no save file, load the default values.

◆ Awake()

void DataManager.Awake ( )
private

This is where most of the functionality of the DataManager happens, since Awake() is called right as the scene loads. Here are the steps that run when Awake() is called: First, we make sure this DataManager is the only DataManager, and it will not be destroyed in the next scene reload. If we're in the main menu scene (build index 0), enable the read/write system and read the save from file. Otherwise, start by finding the references for the reference variables listed above. Finally, these values are restored in their respective objects. We also check if respawnSceneName or respawnPoint are null. If so, they default to currentScene and the player’s current position.

◆ GetAnubisDeathMessage()

string DataManager.GetAnubisDeathMessage ( )

Returns the joke Anubis will tell when the player dies.

◆ GetCurrSceneIndex()

int DataManager.GetCurrSceneIndex ( )

Returns the index of the current scene.

◆ GetCurrSceneName()

string DataManager.GetCurrSceneName ( )

Returns the name of the current scene.

◆ GetGodSouls()

int DataManager.GetGodSouls ( )

Returns number of god souls the player has.

◆ GetHealthPotionCount()

int DataManager.GetHealthPotionCount ( )

Returns the current number of health potions the player has.

◆ GetMasterVolume()

float DataManager.GetMasterVolume ( )

Returns the current master volume setting.

◆ GetMusicVolume()

float DataManager.GetMusicVolume ( )

Returns the current music volume setting.

◆ GetPlayerHealth()

int DataManager.GetPlayerHealth ( )

Returns the player's health.

◆ GetPrevSceneIndex()

int DataManager.GetPrevSceneIndex ( )

Returns the index of the previous scene.

◆ GetPrevSceneName()

string DataManager.GetPrevSceneName ( )

Returns the name of the previous scene.

◆ GetRespawnPoint()

Vector2 DataManager.GetRespawnPoint ( )

Returns the name of the scene with the player's respawn point.

◆ GetRespawnSceneName()

string DataManager.GetRespawnSceneName ( )

Returns the name of the scene with the player's respawn point.

◆ GetSFXVolume()

float DataManager.GetSFXVolume ( )

Returns the current SFX volume setting.

◆ GetSouls()

int DataManager.GetSouls ( )

Returns number of souls the player has.

◆ GetTimeOfDay()

TimeOfDay DataManager.GetTimeOfDay ( )

Returns current time of day as a TimeOfDay enum.

◆ invokeEvents()

void DataManager.invokeEvents ( )
private

Invokes all events the DataManager has. Usually used when a new scene loads and all these values are updated. Right now, DataManager only has events related to the soul counts, which the display uses to know what number to put on the screen (that’s why it needs to be called when loading a new scene).

◆ OnApplicationQuit()

void DataManager.OnApplicationQuit ( )
private

Read from the save file and restore those values. If there is no save file, load the default values.

◆ OnDisable()

void DataManager.OnDisable ( )
private

Unsubscribe from all events when this object or script is disabled.

◆ OnEnable()

void DataManager.OnEnable ( )
private

Subscribe all functions that need to monitor other functionality to the corresponding events.

◆ readSaveFile()

void DataManager.readSaveFile ( )
private

Read from the save file and restore those values. If there is no save file, load the default values.

◆ SetSkyhubToOpening()

void DataManager.SetSkyhubToOpening ( )

Tells the Skyhub that the player should return to the opening scene instead of the usual player's respawn position.

◆ SetTimeOfDay()

void DataManager.SetTimeOfDay ( TimeOfDay newTime)

Set the time of day to be either Day, Night, Eclipse, or BloodMoon. (Eclipse and BloodMoon not yet implemented).

◆ Start()

void DataManager.Start ( )
private

Start the autosave loop and update the volume levels.

◆ SubtractGodSouls()

void DataManager.SubtractGodSouls ( int numSouls)

Subtracts the given amount of god souls.

◆ SubtractSouls()

void DataManager.SubtractSouls ( int numSouls)

Subtracts the given amount of souls.

◆ UnlockAbilities()

void DataManager.UnlockAbilities ( )

Unlocks the ability hotbar. (This depends on a scene reload)

◆ UnlockSkyhub()

void DataManager.UnlockSkyhub ( )

Unlocks the Skyhub.

◆ UnsetSkyhubToOpening()

void DataManager.UnsetSkyhubToOpening ( )

Tells the DataManager to stop making the Skyhub lead to the opening scene.

◆ updateAnubisDeathMessage()

void DataManager.updateAnubisDeathMessage ( string newDeathMessage)
private

Sets the joke Anubis will tell to the given string. Subscribes to the PlayerHealth.deathMessageChange event.

Parameters
newDeathMessageJoke that Anubis will tell.

◆ updatePlayerHealth()

void DataManager.updatePlayerHealth ( int newHealth)
private

Updates the DataManager’s record of player health. Subscribed to the onPlayerHealthChange event.

◆ updatePotionCount()

void DataManager.updatePotionCount ( int potionCount)
private

Updates the DataManager’s record of player health. Subscribed to the onPlayerHealthChange event.

◆ UpdateRespawnPoint()

void DataManager.UpdateRespawnPoint ( Vector2 newRespawnPoint)

Sets the player’s respawn point the given position in the current scene.

Parameters
newRespawnPointThe coordinates in the respawn scene the respawn point is located.

◆ updateSceneIndex()

void DataManager.updateSceneIndex ( )
private

If the currSceneIndex no longer matches the index of the actual current scene, update currSceneIndex and prevSceneIndex.

◆ updateSceneName()

void DataManager.updateSceneName ( )
private

If the currSceneName no longer matches the index of the actual current scene, update currSceneName and prevSceneName.

◆ writeSaveFile()

void DataManager.writeSaveFile ( )
private

Write various values to the save file.

Member Data Documentation

◆ abilityInventory

AbilityInventory DataManager.abilityInventory

Reference to the AbilityInventory object.

◆ activeAbilityData

ActiveAbilityData DataManager.activeAbilityData

Reference to the ActiveAbilityData object.

◆ autosaveEnabled

bool DataManager.autosaveEnabled = true
private

Controls whether or not autosaving is enabled. Can be disabled mid-play in the Unity Editor, but not restarted.

◆ autosaveFrequency

float DataManager.autosaveFrequency = 3f
private

How often the game should run the autosave function.

◆ currTimeOfDay

TimeOfDay DataManager.currTimeOfDay
staticprivate

Time of day that should be restored when a new scene is loaded.

◆ defaultTimeOfDay

TimeOfDay DataManager.defaultTimeOfDay = TimeOfDay.Day
private

Default time of day when the game is first loaded.

◆ fileReadWrite

FileReadWrite DataManager.fileReadWrite
private

Class used to read and write data to a file.

◆ godSouls

int DataManager.godSouls = 0
private

Current amount of god souls.

◆ healthPotionCount

int DataManager.healthPotionCount = 0
private

The amount of health potions the player currently has.

◆ Instance

DataManager DataManager.Instance
static

To make the object persistent, it needs a reference to itself.

◆ maatTalked

bool DataManager.maatTalked = false

If Ma'at has never been talked to before, the welcome message should be displayed.

◆ masterVolumeSetting

float DataManager.masterVolumeSetting = 1f

The master volume gets multiplied by this values in AudioManager.cs (values ranging from 0 to 1).

◆ musicVolumeSetting

float DataManager.musicVolumeSetting = 1f

The music volume gets multiplied by this values in AudioManager.cs (values ranging from 0 to 1).

◆ player

GameObject DataManager.player
private

Reference to the player itself. Used to set the initial respawn point to the player’s position.

◆ playerHealth

int DataManager.playerHealth = 100
private

Player health that should be restored when a new scene is loaded.

◆ readWriteEnabled

bool DataManager.readWriteEnabled = false
private

True if the saving system is enabled at all (false when any scene other than the MainMenu is loaded)

◆ saveFileName

string DataManager.saveFileName
private

Name of the file to save the game to, and load the game from.

◆ sfxVolumeSetting

float DataManager.sfxVolumeSetting = 1f

The SFX volume gets multiplied by this values in AudioManager.cs (values ranging from 0 to 1).

◆ skyhubExited

bool DataManager.skyhubExited = false

If the player has ever exited the Skyhub.

◆ souls

int DataManager.souls = 0
private

Current amount of souls.

◆ ToDController

TimeOfDayController DataManager.ToDController
private

Reference to the TimeOfDayController. Used to update the time of day after a scene reload.

Property Documentation

◆ abilitiesUnlocked

bool DataManager.abilitiesUnlocked = false
getprivate set

Whether the ability hotbar is unlocked yet or not.

◆ anubisDeathMessage

string DataManager.anubisDeathMessage
staticgetprivate set

The joke Anubis will tell when the player dies.

◆ currSceneIndex

int DataManager.currSceneIndex
staticgetprivate set

The index of the scene that is currently loaded.

◆ currSceneName

string DataManager.currSceneName
staticgetprivate set

The name of the scene that is currently loaded.

◆ noSaveFileFound

bool DataManager.noSaveFileFound
getprivate set

True if no save file was found.

◆ prevSceneIndex

int DataManager.prevSceneIndex
staticgetprivate set

The index of the scene that was previously loaded.

◆ prevSceneName

string DataManager.prevSceneName
staticgetprivate set

The name of the scene that was previously loaded.

◆ respawnPoint

Vector2 DataManager.respawnPoint
getprivate set

The coordinates of the player’s respawn point.

◆ respawnSceneName

string DataManager.respawnSceneName
staticgetprivate set

The name of the scene the player’s respawn point is in.

◆ skyhubLeadsToOpening

bool DataManager.skyhubLeadsToOpening = false
getprivate set

Set to true and the Skyhub will spawn the player back at the Opening scene.

◆ skyhubUnlocked

bool DataManager.skyhubUnlocked = false
getprivate set

True if warp obelisks should allow the player to warp to the Skyhub. Unlocks after Geb is defeated.

Event Documentation

◆ newGodSoulTotal

Action<int> DataManager.newGodSoulTotal
static

When the amount of god souls the player has changes, this event is invoked.

◆ newSoulTotal

Action<int> DataManager.newSoulTotal
static

When the amount of souls the player has changes, this event is invoked.


The documentation for this class was generated from the following file: