Skip to content

Game.Prefabs.LocalModifierData

Assembly:
Assembly-CSharp.dll

Namespace:
Game.Prefabs

Type:
struct

Base:
IBufferElementData, ISerializable

Summary:
Represents a local modifier entry used by prefab data in the game's ECS (Entity Component System). This buffer element stores the modifier type, value mode, radius combination mode and two Bounds1 values (delta and radius). It is marked with [InternalBufferCapacity(0)] so it is used as a dynamic entity buffer element. Implements ISerializable to control how the data is written to and read from the game's binary serialization format (IWriter / IReader).


Fields

  • public LocalModifierType m_Type
    Enum indicating which local modifier this entry represents (e.g., pollution, noise, etc.). Serialized as a single byte.

  • public ModifierValueMode m_Mode
    Enum that describes how the modifier value is applied (for example, add/multiply/override). Serialized as a single byte.

  • public ModifierRadiusCombineMode m_RadiusCombineMode
    Enum describing how multiple radii should be combined (for example, additive, max, etc.). Serialized as a single byte.

  • public Bounds1 m_Delta
    Bounds1 representing the delta/value range for the modifier. Contains min and max floats. The two floats are serialized first (min then max).

  • public Bounds1 m_Radius
    Bounds1 representing the radius range for the modifier. Contains min and max floats. The two floats are serialized after m_Delta values.

Notes: - The struct writes/reads fields in a specific order during serialization: m_Delta.min, m_Delta.max, m_Radius.min, m_Radius.max, then the three enums as bytes (m_Type, m_Mode, m_RadiusCombineMode). Deserialization reads in the same order. - The enums are cast to byte for compact representation.

Properties

  • (none)
    This struct does not expose any C# properties. It uses public fields and implements ISerializable.

Constructors

  • public LocalModifierData(LocalModifierType type, ModifierValueMode mode, ModifierRadiusCombineMode radiusMode, Bounds1 delta, Bounds1 radius)
    Initializes all fields of the struct with the provided values.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the struct to a provided writer in the following order:
  • m_Delta.min (float)
  • m_Delta.max (float)
  • m_Radius.min (float)
  • m_Radius.max (float)
  • (byte)m_Type
  • (byte)m_Mode
  • (byte)m_RadiusCombineMode

This deterministic ordering must be preserved for compatibility with the corresponding Deserialize implementation.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the struct from a reader using the same order as Serialize:
  • m_Delta.min (float)
  • m_Delta.max (float)
  • m_Radius.min (float)
  • m_Radius.max (float)
  • byte -> m_Type
  • byte -> m_Mode
  • byte -> m_RadiusCombineMode

Note: The method uses ref locals to assign floats directly into m_Delta and m_Radius fields for efficiency.

Additional notes: - Because this type implements ISerializable directly, the serialization format is explicitly controlled here rather than relying on automatic reflection-based serialization. - The generic constraints (TWriter : IWriter, TReader : IReader) follow the game's writer/reader interfaces used throughout the engine.

Usage Example

// Create bounds values (Bounds1 exposes .min and .max fields)
var delta = default(Bounds1);
delta.min = -1f;
delta.max = 1f;

var radius = default(Bounds1);
radius.min = 0f;
radius.max = 10f;

// Construct a LocalModifierData instance
var localModifier = new LocalModifierData(
    LocalModifierType.Pollution,                 // example enum value
    ModifierValueMode.Add,                       // example mode
    ModifierRadiusCombineMode.Max,               // example radius combine mode
    delta,
    radius
);

// Example: adding to an entity dynamic buffer (ECS)
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = /* obtain or create entity */;
var buffer = entityManager.GetBuffer<LocalModifierData>(entity);
buffer.Add(localModifier);

// Example: manual serialization with a writer (writer must implement IWriter)
TWriter writer = /* obtain writer */;
localModifier.Serialize(writer);

// Example: manual deserialization with a reader (reader must implement IReader)
LocalModifierData readModifier = default;
TReader reader = /* obtain reader */;
readModifier.Deserialize(reader);