Game.Buildings.Efficiency
Assembly:
Assembly-CSharp (game assembly)
Namespace:
Game.Buildings
Type:
struct
Base:
Implements: Unity.Entities.IBufferElementData, Colossal.Serialization.Entities.ISerializable, System.IComparable
Attribute: [InternalBufferCapacity(8)]
Summary:
Represents a single efficiency entry for a building, pairing an EfficiencyFactor (likely an enum describing the type/source of the efficiency) with a float efficiency value. This struct is intended to be used as an ECS dynamic buffer element (IBufferElementData), can be serialized/deserialized through the game's serialization system (ISerializable), and provides an ordering via IComparable for sorting by efficiency (descending) and then by factor.
Fields
-
public EfficiencyFactor m_Factor
Describes the category or factor for this efficiency entry (e.g., service type, upgrade, modifier). Stored as an enum (EfficiencyFactor) and serialized as a single byte. -
public float m_Efficiency
The numeric efficiency value associated with m_Factor. Serialized as a float.
Additional notes: - The struct is annotated with [InternalBufferCapacity(8)], indicating an internal/default capacity of 8 items when used as a DynamicBuffer element on an entity.
Properties
- This type has no properties. It exposes public fields directly.
Constructors
public Efficiency(EfficiencyFactor factor, float efficiency)
Creates a new Efficiency instance with the given factor and efficiency value.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the struct to the provided writer. The implementation writes the m_Factor as a single byte (casting the enum) followed by the m_Efficiency float. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads data from the provided reader. It reads a byte and casts it to EfficiencyFactor for m_Factor, then reads the float into m_Efficiency. -
public int CompareTo(Efficiency other)
Implements comparison to support sorting. Compares entries primarily by efficiency in descending order (higher efficiency sorts before lower). If efficiencies are equal, compares m_Factor (the enum) to break ties.
Usage Example
// Create a single Efficiency instance
var eff = new Efficiency(EfficiencyFactor.Production, 0.85f);
// Example: adding Efficiency items to a DynamicBuffer in a system (pseudo-code)
public void AddEfficiencyToEntity(EntityManager em, Entity entity)
{
var buffer = em.GetBuffer<Efficiency>(entity); // assumes buffer has been added beforehand
buffer.Add(new Efficiency(EfficiencyFactor.Production, 0.85f));
buffer.Add(new Efficiency(EfficiencyFactor.Energy, 0.60f));
// Sort buffer entries by the CompareTo implementation (descending efficiency)
buffer.Sort();
}
// Example: comparing two instances
var a = new Efficiency(EfficiencyFactor.Production, 0.9f);
var b = new Efficiency(EfficiencyFactor.Production, 0.75f);
int comparison = a.CompareTo(b); // a is greater (higher efficiency) => a sorts before b
Notes:
- Serialization/Deserialization is designed to match the game's IWriter/IReader patterns. When implementing custom save/load code, use the provided writer/reader types.
- Because the struct is an IBufferElementData, it is intended to be used in Unity.Entities DynamicBuffer