Skip to content

Game.Prefabs.AreaGeometryData

Assembly:
Assembly-CSharp (game code / modding assembly — adjust if your mod compiles into a different assembly)

Namespace:
Game.Prefabs

Type:
struct

Base:
IComponentData, IQueryTypeParameter, ISerializable

Summary:
AreaGeometryData is an ECS component/serializable value type used to describe geometry-related settings for an area prefab. It stores the area type, geometry flags and basic placement constraints (snap distance and maximum height). The struct implements ISerializable to provide custom binary read/write logic for save/load and serialization systems used by the game/mod framework.


Fields

  • public AreaType m_Type
    The area type (enum) for this geometry. Serialized as a signed byte (sbyte) in the Serialize method.

  • public GeometryFlags m_Flags
    Bitfield flags describing geometry options. Serialized as a 32-bit unsigned integer (uint) in Serialize.

  • public float m_SnapDistance
    The snap distance used when placing/snapping area geometry. Serialized as a 32-bit float.

  • public float m_MaxHeight
    The maximum allowed height for the area geometry. Serialized as a 32-bit float.

  • public float m_LodBias
    Level-of-detail bias stored on the struct but not included in the Serialize/Deserialize implementations in the provided code. If you need this value persisted, update the serialization methods accordingly.

Properties

  • None. (All data are public fields; no C# properties are defined on this struct.)

Constructors

  • public AreaGeometryData()
    No explicit constructors are defined in the source file; the default parameterless constructor for the struct applies. Initialize fields directly when creating instances.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component fields to the provided writer in the following order and types:
  • m_Type cast to sbyte (signed byte)
  • m_Flags cast to uint (unsigned 32-bit)
  • m_SnapDistance as float
  • m_MaxHeight as float

Note: m_LodBias is not written. Keep reader/writer order identical when reading.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data from the reader in the same order as Serialize:
  • reads sbyte into a local and casts to AreaType for m_Type
  • reads uint into a local and casts to GeometryFlags for m_Flags
  • reads float into m_SnapDistance (by ref)
  • reads float into m_MaxHeight (by ref)

After reading primitive values, m_Type and m_Flags are assigned from the read integer values. As with Serialize, m_LodBias remains untouched by deserialization.

Remarks and compatibility notes: - The serialization uses explicit primitive widths (sbyte, uint, float). When modifying this struct or its serialization, ensure backward compatibility (or version data) so that save/load does not break. - The casting of AreaType to sbyte implies the enum expected range fits in a signed byte. If AreaType expands beyond that, update the serialization to use a larger integer type. - The struct implements IComponentData so it is intended to be attached to Entities in the Unity.Entities ECS/world context.

Usage Example

// Create and initialize
var geom = new AreaGeometryData {
    m_Type = AreaType.Residential,
    m_Flags = GeometryFlags.Visible | GeometryFlags.SnapToGrid,
    m_SnapDistance = 1.5f,
    m_MaxHeight = 50f,
    m_LodBias = 0.5f // note: not serialized by default
};

// Add to an entity (example using Unity.Entities)
entityManager.AddComponentData(entity, geom);

// Serialization example (writer provided by game/mod framework)
writer.Write((sbyte)geom.m_Type);
writer.Write((uint)geom.m_Flags);
writer.Write(geom.m_SnapDistance);
writer.Write(geom.m_MaxHeight);

// Deserialization will restore the serialized fields:
AreaGeometryData loaded;
reader.Read(out sbyte typeValue);
reader.Read(out uint flagsValue);
reader.Read(out float snapDistance);
reader.Read(out float maxHeight);
loaded.m_Type = (AreaType)typeValue;
loaded.m_Flags = (GeometryFlags)flagsValue;
loaded.m_SnapDistance = snapDistance;
loaded.m_MaxHeight = maxHeight;
// loaded.m_LodBias remains default/unchanged

If you need m_LodBias persisted, extend Serialize/Deserialize to write/read it (and handle versioning). Ensure any changes maintain consistent read/write ordering.