Game.Prefabs.ServiceUpgradeData
Assembly: Game
Namespace: Game.Prefabs
Type: struct
Base: IComponentData, IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary:
Value-type ECS component that stores configuration for a service upgrade (cost, XP reward and placement constraints). Designed for use in the game's entity-component system and supports custom serialization via the ISerializable pattern. Note: only m_UpgradeCost and m_XPReward are serialized in the implementation; placement-related fields are present at runtime but not written/read by the provided Serialize/Deserialize methods.
Fields
-
public uint m_UpgradeCost
Holds the upgrade cost as an unsigned integer. This field is written/read by the Serialize/Deserialize methods. -
public int m_XPReward
Holds the XP reward (integer) for applying the upgrade. This field is written/read by the Serialize/Deserialize methods. -
public int m_MaxPlacementOffset
Integer describing a placement offset limit for upgraded service objects. Present for runtime logic but not serialized by the current implementation. -
public float m_MaxPlacementDistance
Floating-point maximum placement distance for upgraded service objects. Present for runtime logic but not serialized by the current implementation.
Properties
- (none)
This struct exposes no C# properties; it only contains public fields and implements interfaces.
Constructors
public ServiceUpgradeData()
Implicit default value-type constructor. You can initialize fields directly when creating the struct, e.g.:
var data = new ServiceUpgradeData {
m_UpgradeCost = 500u,
m_XPReward = 10,
m_MaxPlacementOffset = 2,
m_MaxPlacementDistance = 15f
};
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the serializable fields to the provided writer. Implementation writesm_UpgradeCost
(uint) followed bym_XPReward
(int). The method is generic and constrained to types implementing IWriter from Colossal.Serialization.Entities. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads fields from the provided reader into the struct's fields. Implementation reads intom_UpgradeCost
andm_XPReward
. The method is generic and constrained to types implementing IReader from Colossal.Serialization.Entities.
Usage Example
// Create and initialize the component for an entity
var upgradeData = new Game.Prefabs.ServiceUpgradeData {
m_UpgradeCost = 1200u,
m_XPReward = 25,
m_MaxPlacementOffset = 3,
m_MaxPlacementDistance = 20f
};
// Example: serialization (normally handled by the game's serialization framework)
// using a hypothetical writer that implements IWriter:
writer.Write(upgradeData.m_UpgradeCost);
writer.Write(upgradeData.m_XPReward);
// Example: deserialization
// ref fields will be assigned by the Deserialize implementation when called by the framework.
// The following shows the same semantics as the struct's Deserialize method:
reader.Read(out upgradeData.m_UpgradeCost);
reader.Read(out upgradeData.m_XPReward);
// The struct can be added to an entity as a component in the ECS:
entityManager.AddComponentData(entity, upgradeData);