SaveDataControl
is a Unity component for aggregating IDataContainer
components on the same GameObject and its children, enabling the saving and loading of their data as a single JSON file.
- Component Aggregation: Collects
IDataContainer
components from the GameObject and its children into a list. - File Operations: Facilitates saving, loading, and deleting data based on the specified file and folder names.
- Container Retrieval: Allows for the retrieval of specific
IDataContainer
components by their ID.
Name | Description |
---|---|
_fileName |
The file name used for saving data. |
Name | Function |
---|---|
public Component GetContainer( string id ) |
Retrieves a specific IDataContainer component by its string ID. |
public Component GetContainer( PropertyName id ) |
Retrieves a specific IDataContainer component by its PropertyName ID. |
public bool Exists( string folder ) |
Checks if data exists in the specified folder. |
public void Remove( string folder ) |
Deletes data from the specified folder. |
public void Save( string folder ) |
Saves all IDataContainer components to a file in the specified folder. |
public void Load( string folder ) |
Loads data from a file in the specified folder and updates the IDataContainer components. |
- Attach the
SaveDataControl
component to a GameObject that contains one or moreIDataContainer
components. - Use the
Save
method to persist allIDataContainer
component data into a single file. - Use the
Load
method to restoreIDataContainer
component data from the saved file.
- The
SaveData
struct, used internally, formats the data for saving, containing arrays ofPropertyName
IDs and JSON strings for eachIDataContainer
component. - The
FileName
property ensures that the file name is never empty, defaulting to the GameObject's name if_fileName
is not specified. - This component simplifies the process of persisting complex data structures, making it easier to manage game states or settings across sessions.
SaveDataControl
enhances Unity's game data management capabilities by simplifying the serialization and deserialization processes for multiple data containers, thereby improving the data management workflow in game development projects.