Skip to content

Game.PersonalCar

Assembly:
Assembly-CSharp (typical Unity game assembly; confirm in your project if different)

Namespace:
Game.Vehicles

Type:
public struct

Base:
System.ValueType (struct)
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a Unity ECS component for a personal car used by the game. The struct stores a reference to an associated keeper Entity and a bitfield/state value of type PersonalCarFlags. It supports explicit binary serialization via the ISerializable implementation (writing the keeper Entity then the flags as a uint). This component is intended to be attached to entities (vehicles) and used in ECS queries and systems that handle personal car behavior and persistence.


Fields

  • public Entity m_Keeper
    Holds the Entity that "keeps" or owns/controls this personal car. This is written and read during serialization. When creating or mutating the component, set this to the relevant entity (for example a citizen or manager entity).

  • public PersonalCarFlags m_State
    Bitfield or enum value (stored as an integer) representing the car's current state(s). The concrete PersonalCarFlags enum is not defined in this file; check the codebase for the enum definition to see possible flags (e.g., parked, en route, broken, reserved, etc.). During serialization this value is written as a uint.

Properties

  • None declared on this type. (Component exposes fields directly; no C# properties are defined.)

Constructors

  • public PersonalCar(Entity keeper, PersonalCarFlags state)
    Constructs a PersonalCar instance, initializing m_Keeper and m_State with the supplied values. Use this when creating the component to attach to an entity (for example via EntityManager.AddComponentData).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Serializes the component in the order:
  • writes the Entity stored in m_Keeper via writer.Write(Entity).
  • writes the m_State value cast to uint via writer.Write((uint)m_State). This method is used by the game's save/load or network persistence systems — ensure the writer conforms to the expected format/version.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Deserializes the component in the same order it was serialized:

  • reads an Entity into m_Keeper.
  • reads a uint value and casts it back to PersonalCarFlags to populate m_State. Make sure readers are set up to resolve entity references correctly in the context (they often map saved entity IDs back to runtime Entity instances).

Usage Example

// Create and add the component to an entity (example context: in a system or setup code)
Entity keeper = /* obtain or create keeper entity */;
Entity vehicleEntity = /* the vehicle entity */;
var car = new PersonalCar(keeper, PersonalCarFlags.None);
entityManager.AddComponentData(vehicleEntity, car);

// Serialization example (pseudocode, depends on concrete writer implementation)
car.Serialize(myWriter);

// Deserialization example (pseudocode)
var loadedCar = default(PersonalCar);
loadedCar.Deserialize(myReader);
// then attach to entity if needed:
// entityManager.SetComponentData(vehicleEntity, loadedCar);

Notes: - Check the PersonalCarFlags enum for valid flag values and semantics. - The struct implements IQueryTypeParameter, so it can be used directly in ECS query definitions if desired. - Ensure entity reference resolution (during load) uses the same entity-mapping logic used elsewhere in the game's serialization pipeline.