CSVRecord
Namespace: Canley.Utility.CSV.Standard
Base Class: ScriptableObject
Overview
The CSVRecord class is a ScriptableObject representing a single row of data within your CSV table. It serves a dual purpose in your game architecture: acting as a strongly-typed live C# data class for runtime logic, while maintaining a background Shadow Dictionary (rawValues) to ensure 100% data preservation.
By bridging the gap between raw spreadsheet strings and high-level Unity objects, it allows developers to handle complex assets, custom formats, and unmapped columns without risking data loss during round-trip saves.
Property Reference
| Class | Member (Syntax) | Description |
|---|---|---|
| CSVRecord | id | The unique integer identifier used for high-performance lookups. |
| CSVRecord | recordLabel | The human-friendly string slug used for identification and deterministic ID generation. |
| CSVRecord | rawValues | The internal Shadow Dictionary storing raw string data for unmapped columns. |
| CSVRecord | this[string fieldName] | Indexer providing direct read/write access to the Shadow Dictionary. |
Method Reference
| Class | Member (Syntax) | Description |
|---|---|---|
| CSVRecord | GetRaw(string fieldName) | Returns the raw string value for any specified column, returning null if missing. |
| CSVRecord | Initialize(string label, int explicitId) | Manually sets the record identity, generating a deterministic hash if the ID is zero. |
| CSVRecord | OnImportField(string fieldName, string rawValue) | Virtual inbound hook for intercepting and transforming raw strings during hydration (e.g., loading Sprites). |
| CSVRecord | OnExportField(string fieldName, string currentValue) | Virtual outbound hook for sanitising or formatting data right before writing back to disk. |
Key Features
- Shadow Dictionary Preservation: Any column present in your spreadsheet that lacks a matching public variable in your C# class is safely retained in the background, preventing data destruction during table saves.
- Asset Bridging: Using the
OnImportFieldoverride, you can easily map string identifiers (like filenames) to heavy Unity assets such as Sprites or AudioClips viaResources.Load. - Flexible Identification: Supports both deterministic hash-based integer IDs derived from your record slug and randomized UUID configurations.
NOTE
Always ensure that your custom CSV record classes inherit from
CSVRecordand are marked with the[Serializable]attribute so the reflection engine can properly map your public fields.