Game.Simulation.Loan
Assembly:
Namespace: Game.Simulation
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a loan component used by the simulation. Stores the current loan amount and a last-modified timestamp. Implements custom serialization/deserialization with version-aware compatibility handling for legacy save formats (it discards legacy fields when reading older versions and conditionally reads/writes the last-modified timestamp depending on the save version).
Fields
-
public int m_Amount
Holds the loan amount (integer currency value). This is the primary value serialized and used by the simulation to track outstanding debt. -
public uint m_LastModified
A last-modified timestamp/counter (unsigned int). Recorded and serialized to indicate when the loan was last changed. Only read from older saves when the save version supports it (see Deserialize behavior).
Properties
- (none)
This struct exposes only public fields and does not define C# properties.
Constructors
public Loan()
The default parameterless constructor is used (implicitly provided). Create instances by using object initializer syntax to set m_Amount and m_LastModified as needed.
Methods
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component data from a reader with version-aware logic:- Always reads an int into m_Amount.
- If reader.context.version < Version.noAutoPaybackLoans, it reads and discards two legacy values (a float and an int) that existed in older save formats.
-
If reader.context.version > Version.loanLastModified, it reads a uint into m_LastModified. The method uses ref locals for direct assignment into the struct fields when reading.
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data to a writer: - Writes m_Amount (int).
- Writes m_LastModified (uint). Serialization always writes these two values (the code does not branch on version when writing).
Usage Example
// Create and assign a Loan component to an entity (EntityManager or similar API)
var loan = new Loan {
m_Amount = 250000, // loan amount in game currency
m_LastModified = (uint)SimFrame // example: set to current simulation frame/tick
};
// Assuming you have an EntityManager and an entity:
entityManager.AddComponentData(entity, loan);
// The component will be serialized/deserialized by the game's save system.
// Deserialize handles older save versions by discarding legacy values when necessary.
Notes: - Deserialize checks Version.noAutoPaybackLoans and Version.loanLastModified to maintain backward compatibility with older saves; these Version constants are defined elsewhere in the codebase. - The struct implements IComponentData and IQueryTypeParameter so it can be stored on ECS entities and used in queries.