Skip to content
Simon edited this page Apr 22, 2021 · 3 revisions

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.

Scriptable Objects

DataFile

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.

Data file objects can be created from the Create/DataFile/... menu.

PropertyDescription
FilenameName of the file.
FolderParent folder of the file. Can be an absolute path, or a path relative to one of several Unity data folder.
FolderTypeSpecifies whether Folder is an absolute or relative path, and its location. See the FolderType table.
PathFull path to the file. Created by combining Filename, Folder, and FolderType.
RelativePathRelative 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.
FileFormatSpecifies whether the file is a binary or text file.
ExtensionExtension used by the file.
WriteModeSpecifies how the file will be written to. See the WriteMode table.
FolderTypeDescription
AbsoluteFolder specifies an absolute path on a local or network drive.
RelativeToApplicationDataPathFolder specifies a relative path in the game data folder.
RelativeToPersistentDataPathFolder specifies a relative path in the persistent data folder.
RelativeToStreamingAssetsPathFolder specifies a relative path in the streaming assets folder.
WriteModeDescription
AlwaysOverwriteOverwrites the file each time it is written to.
OverwriteThenAppendOverwrites the file the first time it is written to during each run of the program. Afterwards, the file will be appended to.
AppendEach write will be appended to the end of the file.
ReadOnlyTrying to write to the file will do nothing.
IncrementIf the file already exists, the filename will be incremented. Data will be appended to the incremented file.

DataFileText

The DataFileText class is an abstract class that contains logic for writing text-based files.

FunctionDescription
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/DataFileTSV

DataFileCSV and DataFileTSV enable writing to comma-/tab- separated files.

FunctionDescription
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

DataFileTXT enables writing to generic text files.

DataFileBinary

The DataFileBinary class is an abstract class that contains logic for writing binary files.

FunctionDescription
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

DataFilePNG supports reading from and writing to PNG files. Conversion between Texture2D data and PNG file data is also supported.

FunctionDescription
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.

DataContainer

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.

Components

DataWriter

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.

PropertyDescription
FilesData will be written to these files.
SleepTimeSpecifies the time interval between each write.
FunctionDescription
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.

Clone this wiki locally