Skip to content

Game.Objects.TripSource

Assembly: Game (inferred from project structure)
Namespace: Game.Objects

Type: struct

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

Summary:
TripSource is a lightweight ECS component intended to mark an entity as a trip source and track a countdown/timer until the next trip is produced. It stores a reference to the source Entity and an integer timer. The struct implements ISerializable to support Colossal's serialization system and can be used as a component in Unity.Entities (EntityManager/SystemBase) and in query parameter contexts.


Fields

  • public Entity m_Source
    Holds the Entity that acts as the trip source. This is the entity that produces trips or is associated with trip generation logic.

  • public int m_Timer
    An integer countdown or delay value (in whatever unit the mod/system interprets). The struct exposes constructors that initialize this value; it is serialized/deserialized alongside the source.

Properties

  • (none)
    This struct does not define C# properties; it exposes public fields directly.

Constructors

  • public TripSource(Entity source)
    Creates a TripSource with m_Source set to source and m_Timer initialized to 0.

  • public TripSource(Entity source, uint delay)
    Creates a TripSource with m_Source set to source and m_Timer initialized to (int)delay. Note: the delay parameter is a uint and is cast to int; callers should ensure the value is within int range to avoid overflow/truncation.

  • (implicit) public TripSource()
    As a value type, a default parameterless constructor exists implicitly, setting m_Source to default(Entity) and m_Timer to 0.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the component by writing m_Source first (Entity) and then m_Timer (int) using the provided writer. This method enables the Colossal serialization pipeline to persist the component state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads m_Source and m_Timer back from the provided reader. The method reads into ref locals of the fields. After deserialization, the component will contain the same Entity and timer values that were written.

Remarks: - The serialization order is source then timer; any reader/writer must follow the same order. - The methods are generic to support the IWriter/IReader abstractions used by the game's serialization framework.

Usage Example

// Create a TripSource and attach it to an entity via the EntityManager
Entity sourceEntity = /* obtain or create the source entity */;
TripSource tripSource = new TripSource(sourceEntity, 300u); // delay of 300 (cast to int)

EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.AddComponentData(sourceEntity, tripSource);

// In a system, you might decrement m_Timer and trigger trip generation when it reaches zero:
Entities.ForEach((ref TripSource ts) =>
{
    if (ts.m_Timer > 0)
        ts.m_Timer--;
    else
    {
        // produce trip from ts.m_Source ...
        // reset ts.m_Timer as needed
    }
}).Schedule();