Skip to content

Game.Policies.Policy

Assembly: Assembly-CSharp
Namespace: Game.Policies

Type: struct

Base: IBufferElementData, ISerializable

Summary:
Represents a serializable buffer element that references a policy entity, stores associated flags and a numeric adjustment. Marked with [InternalBufferCapacity(0)] so the element has no inline buffer capacity. Intended for use with Unity's ECS dynamic buffers (DynamicBuffer) and supports custom binary serialization via Colossal.Serialization.Entities IWriter/IReader.


Fields

  • public Unity.Entities.Entity m_Policy
    Holds the Entity reference for the policy. Serialized/deserialized as an Entity value.

  • public PolicyFlags m_Flags
    Enum flags describing policy options/state. Serialized as a single byte (cast to/from byte during serialization).

  • public float m_Adjustment
    Numeric adjustment value associated with the policy. Serialized/deserialized as a float.

Properties

  • This type defines no properties.

Constructors

  • public Policy(Unity.Entities.Entity policy, PolicyFlags flags, float adjustment)
    Initializes a Policy element with the given entity, flags and adjustment value. Simply assigns the provided arguments to the corresponding fields.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the Policy element into the provided writer in the following order:
  • Writes the Entity (m_Policy).
  • Writes the PolicyFlags as a single byte (casts m_Flags to byte).
  • Writes the float adjustment (m_Adjustment).

Useful when persisting buffers or sending state over binary streams.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the Policy element from the provided reader in the same order used by Serialize:
  • Reads an Entity into m_Policy.
  • Reads a byte and assigns it to m_Flags (casts byte to PolicyFlags).
  • Reads a float into m_Adjustment.

Ensures the struct is restored from the serialized representation.

Usage Example

// Example inside a System where an entity has a DynamicBuffer<Policy>
protected override void OnUpdate()
{
    Entities.ForEach((Entity e, ref DynamicBuffer<Game.Policies.Policy> policies) =>
    {
        // Create a Policy value and add to buffer
        var newPolicy = new Game.Policies.Policy(somePolicyEntity, PolicyFlags.SomeFlag, 1.25f);
        policies.Add(newPolicy);

        // Example: serialize first element using a writer (pseudocode - depends on concrete writer)
        // var writer = new SomeBinaryWriter(...);
        // policies[0].Serialize(writer);

    }).WithoutBurst().Run();
}