Skip to content

Game.Tools.Recent

Assembly: Assembly-CSharp
Namespace: Game.Tools

Type: struct Recent

Base: Implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable

Summary:
Represents a small ECS component used to record the most recent modification information for an entity (used by in-game tools/features). It stores the frame index when the last modification occurred and an integer "cost" associated with that modification. The struct implements Colossal's ISerializable so its two fields are written to and read from the game's save/streaming system.


Fields

  • public uint m_ModificationFrame
    Stores the frame number (uint) in which the last modification to the associated entity occurred. Typically used to determine whether a change is recent within the current simulation frame or to avoid repeated processing.

  • public int m_ModificationCost
    An integer representing a "cost" or magnitude for the modification. The exact meaning is context-dependent (e.g., tool operation cost, weight for processing), but it is intended to carry additional metadata about the modification.

Properties

  • None. This struct exposes only public fields and does not define properties.

Constructors

  • public Recent()
    No explicit constructor is defined in the source, so the default parameterless struct constructor is used. Fields default to 0 (m_ModificationFrame = 0, m_ModificationCost = 0) unless set explicitly.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data to a writer for persistence. This method writes m_ModificationFrame followed by m_ModificationCost. The writer is expected to be a Colossal.Serialization writer capable of serializing primitive types.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component data from a reader into the struct fields. The method reads the frame into m_ModificationFrame and then the cost into m_ModificationCost. Note: the implementation uses ref locals to write directly into the fields.

Usage Example

// Attach the component to an entity (EntityManager reference assumed)
var recent = new Game.Tools.Recent {
    m_ModificationFrame = (uint)SimulationManager.instance.m_CurrentFrameIndex, // example source
    m_ModificationCost = 10
};
entityManager.AddComponentData(entity, recent);

// Read the component later
if (entityManager.HasComponent<Game.Tools.Recent>(entity))
{
    var r = entityManager.GetComponentData<Game.Tools.Recent>(entity);
    if (r.m_ModificationFrame == (uint)SimulationManager.instance.m_CurrentFrameIndex) {
        // handle recent modification
    }
}

// Serialization/deserialization are handled by the Colossal serialization system.
// Example pseudo-usage when implementing custom writer/reader calls:
writer.Write(recent.m_ModificationFrame);
writer.Write(recent.m_ModificationCost);

// And later when reading:
reader.Read(out recent.m_ModificationFrame);
reader.Read(out recent.m_ModificationCost);