-
Notifications
You must be signed in to change notification settings - Fork 1
Namespace: WIDVE.IO
Location: WIDVE Unity Scripts/IO
The WIDVE.IO
namespace contains a generic data collection system, as well as helper methods for working with various file types.
A DataFile
is a wrapper for a file on disk. The file can be located in the Assets folder, elsewhere on the local machine, or on a network drive. Files and folders that do not already exist will be created. The DataFile
class contains logic for writing to a backup file if the specified file is inaccessible, for example if a network drive is unavailable.
DataFile
is an abstract class; operations for specific types of files are contained in their own classes. Properties that are common to all files are described below.
Property | Description |
---|---|
Filename |
Name of the file. |
Folder |
Parent folder of the file. Can be an absolute path, or a path relative to one of several Unity data folder. |
FolderType |
Specifies whether Folder is an absolute or relative path, and its location. See the FolderType table. |
Path |
Full path to the file. Created by combining Filename , Folder , and FolderType . |
RelativePath |
Relative path to the file. If FolderType is absolute, will be the same as Path . Otherwise, the path will be relative to whichever data folder is specified by FolderType . |
FileFormat |
Specifies whether the file is a binary or text file. |
Extension |
Extension used by the file. |
WriteMode |
Specifies how the file will be written to. See the WriteMode table. |
FolderType | Description |
---|---|
Absolute |
Folder specifies an absolute path on a local or network drive. |
RelativeToApplicationDataPath |
Folder specifies a relative path in the game data folder. |
RelativeToPersistentDataPath |
Folder specifies a relative path in the persistent data folder. |
RelativeToStreamingAssetsPath |
Folder specifies a relative path in the streaming assets folder. |
WriteMode | Description |
---|---|
AlwaysOverwrite |
Overwrites the file each time it is written to. |
OverwriteThenAppend |
Overwrites the file the first time it is written to during each run of the program. Afterwards, the file will be appended to. |
Append |
Each write will be appended to the end of the file. |
ReadOnly |
Trying to write to the file will do nothing. |
Increment |
If the file already exists, the filename will be incremented. Data will be appended to the incremented file. |
Data file objects can be created from the Create/DataFile/...
menu.
The DataFileText
class is an abstract class that contains logic for writing text-based files.
Function | Description |
---|---|
GetWriter() |
Returns a StreamWriter for the file, with write settings based on the file's current WriteMode . |
GetReader() |
Returns a StreamReader for the file. |
Write(string text) |
Writes the given text to the file. |
Write(string[] text, string separator = "") |
Writes the given sequence of text to the file, with an optional separator between each entry. |
DataFileCSV
and DataFileTSV
enable writing to comma-/tab- separated files.
Function | Description |
---|---|
WriteData(DataContainer[][] buffer) |
Writes the given DataContainers to the file. Each array of DataContainers will be written as a line, with individual entries separated by commas/tabs. |
DataFileTXT
enables writing to generic text files.
The DataFileBinary
class is an abstract class that contains logic for writing binary files.
Function | Description |
---|---|
GetWriter() |
Returns a BinaryWriter for the file, with write settings based on the file's current WriteMode . |
GetReader() |
Returns a BinaryReader for the file. |
GetAllBytes() |
Returns an array of all bytes in the file. |
Write(byte[] bytes) |
Writes the given bytes to the file. |
DataFilePNG
supports reading from and writing to PNG files. Conversion between Texture2D
data and PNG file data is also supported.
Function | Description |
---|---|
Load() |
Returns a Texture2D loaded from the PNG file. |
Save(Texture texture) |
Saves the given Texture to the PNG file. |
Save(Texture2D texture2D) |
Saves the given Texture2D to the PNG file. |
ConvertTextureToTexture2D(Texture texture) |
Performs some very convoluted logic to convert a Texture to a Texture2D . |
A DataContainer
is a struct that holds a single piece of readonly data. DataContainers
are useful for collecting data from multiple sources in a single pipeline. Data is stored when the DataContainer
is created, and is converted into a string when the DataContainer
is written to a file.
The DataWriter
component writes data to files at specified intervals using multithreading. Data is sent to the DataWriter
using DataContainers
. The data writing thread writes data in the buffer to DataFiles
using its own thread.
Property | Description |
---|---|
Files |
Data will be written to these files. |
SleepTime |
Specifies the time interval between each write. |
Function | Description |
---|---|
Add(DataContainer[] data) |
Adds data to the buffer. Data will be written during the next scheduled write. Calling this function can block if the buffer is currently being accessed by the write thread. |