Game.Vehicles.LoadingResources
Assembly:
Assembly-CSharp (Cities: Skylines 2 modding assemblies)
Namespace:
Game.Vehicles
Type:
struct
Base:
System.ValueType, Unity.Entities.IBufferElementData, Colossal.Serialization.Entities.ISerializable
Summary:
A dynamic buffer element used by vehicle entities to represent a single resource being loaded (or transported) and the associated amount. The struct is marked with [InternalBufferCapacity(0)], indicating it is intended for dynamic per-entity buffers with no inline capacity. It implements custom binary serialization via ISerializable so buffer contents can be written to and read from saved game data or network streams. Serialization writes the resource as a signed byte index (using EconomyUtils) followed by the integer amount.
Fields
-
public Resource m_Resource
Represents the type of resource (an enum or value represented by the game's Economy system) that this buffer element refers to. During serialization this is converted to/from a small numeric index via EconomyUtils.GetResourceIndex / EconomyUtils.GetResource. -
public int m_Amount
The quantity of the resource being loaded or carried by the vehicle. Serialized as a 32-bit integer after the resource index.
Note: The struct class-level attribute [InternalBufferCapacity(0)]
indicates the buffer has no inline storage and each element is stored out-of-line by the EntityManager's dynamic buffer implementation.
Properties
- This type exposes no properties. It only contains public fields and the serialization methods required by ISerializable.
Constructors
public LoadingResources()
Default value-type constructor provided by the runtime. Initializes m_Resource to its default value and m_Amount to 0. No custom constructors are defined in the source; instances are typically created via object initializers or by adding to an Entity's dynamic buffer.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the element into a writer. Behavior:- Calls EconomyUtils.GetResourceIndex(m_Resource) and casts the result to sbyte, then writes that sbyte to the writer. This encodes the resource as a small signed byte index.
- Writes m_Amount as a 32-bit integer.
-
Be aware that using sbyte limits the encoded domain to the -128..127 range; the EconomyUtils resource indexing must be compatible with this storage format.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes the element from a reader. Behavior: - Reads an sbyte resource index from the reader.
- Reads an int amount from the reader into m_Amount.
- Converts the sbyte resource index back into a Resource via EconomyUtils.GetResource(value) and assigns it to m_Resource.
- After deserialization the struct will reflect the saved resource type and amount.
Usage Example
// Add a LoadingResources element to a vehicle entity's dynamic buffer:
var buffer = entityManager.AddBuffer<Game.Vehicles.LoadingResources>(vehicleEntity);
buffer.Add(new Game.Vehicles.LoadingResources {
m_Resource = Resource.Food,
m_Amount = 50
});
// When saving/loading, the engine will invoke Serialize/Deserialize on each buffer element.
// You can also manually create and populate instances when constructing entity state.