Skip to content

Game.Companies.Profitability

Assembly: Assembly-CSharp
Namespace: Game.Companies

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents a company's profitability state stored as an ECS component. Contains a compact profitability value (byte) and an integer tracking the last known total worth. Implements serialization/deserialization to persist/load the component state and is usable as a query parameter type in Unity's Entities/ECS systems.


Fields

  • public byte m_Profitability Holds the company's profitability as a single byte. This compact value is intended for efficient storage and transmission as part of the game's serialization pipeline and ECS components.

  • public int m_LastTotalWorth Stores the last recorded total worth of the company. This field is conditionally serialized/deserialized depending on the serialization format (see Deserialize), which preserves compatibility with older/newer save formats.

Properties

  • This struct exposes no C# properties. It uses public fields directly as its data.

Constructors

  • public Profitability()
    Default value-type constructor (implicit). Fields default to 0 (m_Profitability = 0, m_LastTotalWorth = 0). No explicit constructors are defined in the source.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes component data to a writer. Specifically, it writes m_Profitability (byte) followed by m_LastTotalWorth (int). This method is used by the game's serialization system to persist the component.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component data from a reader. It always reads m_Profitability. It reads m_LastTotalWorth only when the reader's context format includes FormatTags.CompanyAndCargoFix — this conditional read preserves compatibility across different save format versions where lastTotalWorth may not have been present.

Additional behavioral notes: - The method uses by-reference reads into the struct fields (ref locals) when deserializing to avoid temporary copies. - The generic constraints require compatible IWriter/IReader implementations provided by the game's serialization framework. - The presence check reader.context.format.Has(FormatTags.CompanyAndCargoFix) is a version/compatibility guard. FormatTags.CompanyAndCargoFix is treated as a flag indicating that the saved data includes the company lastTotalWorth field.

Usage Example

// Example: creating and serializing a Profitability component.
// Note: IWriter and IReader are provided by the game's serialization framework.

var profit = new Game.Companies.Profitability
{
    m_Profitability = 85,       // e.g. percentage-like or normalized score
    m_LastTotalWorth = 1234567
};

// Serialize
IWriter writer = /* obtain writer from serialization context */;
profit.Serialize(writer);

// Deserialize (reader.Context.format must be set appropriately)
IReader reader = /* obtain reader from serialization context */;
var loadedProfit = default(Game.Companies.Profitability);
loadedProfit.Deserialize(reader);

// Using as an ECS component:
// entityManager.AddComponentData(entity, profit);

Notes and recommendations: - Because this struct implements IComponentData, use it with Unity.Entities APIs (AddComponentData, GetComponentData, etc.) when attaching to entities. - Be careful with binary compatibility: Deserialize has a conditional read for older/newer save formats; when constructing custom save/loader tools, ensure FormatTags compatibility is respected.