![]() |
Eye of the Nile Docs
Everything you need to know to get started!
|
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
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. | |
void DataManager.AddGodSouls | ( | int | numSouls | ) |
Adds the given amount of god souls. Subscribes to the ObjectHealth.godSoulsDropped event.
void DataManager.AddSouls | ( | int | numSouls | ) |
Adds the given amount of souls. Subscribes to the ObjectHealth.soulsDropped event.
|
private |
Read from the save file and restore those values. If there is no save file, load the default values.
|
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.
string DataManager.GetAnubisDeathMessage | ( | ) |
Returns the joke Anubis will tell when the player dies.
int DataManager.GetCurrSceneIndex | ( | ) |
Returns the index of the current scene.
string DataManager.GetCurrSceneName | ( | ) |
Returns the name of the current scene.
int DataManager.GetGodSouls | ( | ) |
Returns number of god souls the player has.
int DataManager.GetHealthPotionCount | ( | ) |
Returns the current number of health potions the player has.
float DataManager.GetMasterVolume | ( | ) |
Returns the current master volume setting.
float DataManager.GetMusicVolume | ( | ) |
Returns the current music volume setting.
int DataManager.GetPlayerHealth | ( | ) |
Returns the player's health.
int DataManager.GetPrevSceneIndex | ( | ) |
Returns the index of the previous scene.
string DataManager.GetPrevSceneName | ( | ) |
Returns the name of the previous scene.
Vector2 DataManager.GetRespawnPoint | ( | ) |
Returns the name of the scene with the player's respawn point.
string DataManager.GetRespawnSceneName | ( | ) |
Returns the name of the scene with the player's respawn point.
float DataManager.GetSFXVolume | ( | ) |
Returns the current SFX volume setting.
int DataManager.GetSouls | ( | ) |
Returns number of souls the player has.
|
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).
|
private |
Read from the save file and restore those values. If there is no save file, load the default values.
|
private |
Unsubscribe from all events when this object or script is disabled.
|
private |
Subscribe all functions that need to monitor other functionality to the corresponding events.
|
private |
Read from the save file and restore those values. If there is no save file, load the default values.
void DataManager.SetSkyhubToOpening | ( | ) |
Tells the Skyhub that the player should return to the opening scene instead of the usual player's respawn position.
void DataManager.SetTimeOfDay | ( | TimeOfDay | newTime | ) |
Set the time of day to be either Day, Night, Eclipse, or BloodMoon. (Eclipse and BloodMoon not yet implemented).
|
private |
Start the autosave loop and update the volume levels.
void DataManager.SubtractGodSouls | ( | int | numSouls | ) |
Subtracts the given amount of god souls.
void DataManager.SubtractSouls | ( | int | numSouls | ) |
Subtracts the given amount of souls.
void DataManager.UnlockAbilities | ( | ) |
Unlocks the ability hotbar. (This depends on a scene reload)
void DataManager.UnlockSkyhub | ( | ) |
Unlocks the Skyhub.
void DataManager.UnsetSkyhubToOpening | ( | ) |
Tells the DataManager to stop making the Skyhub lead to the opening scene.
|
private |
Sets the joke Anubis will tell to the given string. Subscribes to the PlayerHealth.deathMessageChange event.
newDeathMessage | Joke that Anubis will tell. |
|
private |
Updates the DataManager’s record of player health. Subscribed to the onPlayerHealthChange event.
|
private |
Updates the DataManager’s record of player health. Subscribed to the onPlayerHealthChange event.
void DataManager.UpdateRespawnPoint | ( | Vector2 | newRespawnPoint | ) |
Sets the player’s respawn point the given position in the current scene.
newRespawnPoint | The coordinates in the respawn scene the respawn point is located. |
|
private |
If the currSceneIndex no longer matches the index of the actual current scene, update currSceneIndex and prevSceneIndex.
|
private |
If the currSceneName no longer matches the index of the actual current scene, update currSceneName and prevSceneName.
|
private |
Write various values to the save file.
AbilityInventory DataManager.abilityInventory |
Reference to the AbilityInventory object.
ActiveAbilityData DataManager.activeAbilityData |
Reference to the ActiveAbilityData object.
|
private |
Controls whether or not autosaving is enabled. Can be disabled mid-play in the Unity Editor, but not restarted.
|
private |
How often the game should run the autosave function.
|
staticprivate |
Time of day that should be restored when a new scene is loaded.
|
private |
Default time of day when the game is first loaded.
|
private |
Class used to read and write data to a file.
|
private |
Current amount of god souls.
|
private |
The amount of health potions the player currently has.
|
static |
To make the object persistent, it needs a reference to itself.
bool DataManager.maatTalked = false |
If Ma'at has never been talked to before, the welcome message should be displayed.
float DataManager.masterVolumeSetting = 1f |
The master volume gets multiplied by this values in AudioManager.cs (values ranging from 0 to 1).
float DataManager.musicVolumeSetting = 1f |
The music volume gets multiplied by this values in AudioManager.cs (values ranging from 0 to 1).
|
private |
Reference to the player itself. Used to set the initial respawn point to the player’s position.
|
private |
Player health that should be restored when a new scene is loaded.
|
private |
True if the saving system is enabled at all (false when any scene other than the MainMenu is loaded)
|
private |
Name of the file to save the game to, and load the game from.
float DataManager.sfxVolumeSetting = 1f |
The SFX volume gets multiplied by this values in AudioManager.cs (values ranging from 0 to 1).
bool DataManager.skyhubExited = false |
If the player has ever exited the Skyhub.
|
private |
Current amount of souls.
|
private |
Reference to the TimeOfDayController. Used to update the time of day after a scene reload.
|
getprivate set |
Whether the ability hotbar is unlocked yet or not.
|
staticgetprivate set |
The joke Anubis will tell when the player dies.
|
staticgetprivate set |
The index of the scene that is currently loaded.
|
staticgetprivate set |
The name of the scene that is currently loaded.
|
getprivate set |
True if no save file was found.
|
staticgetprivate set |
The index of the scene that was previously loaded.
|
staticgetprivate set |
The name of the scene that was previously loaded.
|
getprivate set |
The coordinates of the player’s respawn point.
|
staticgetprivate set |
The name of the scene the player’s respawn point is in.
|
getprivate set |
Set to true and the Skyhub will spawn the player back at the Opening scene.
|
getprivate set |
True if warp obelisks should allow the player to warp to the Skyhub. Unlocks after Geb is defeated.
|
static |
When the amount of god souls the player has changes, this event is invoked.
|
static |
When the amount of souls the player has changes, this event is invoked.