Skip to content

Game.SignalAnimation

Assembly:
Namespace: Game.Prefabs

Type: struct

Base: System.ValueType

Summary:
Represents a compact, frame-based signal animation backed by a FixedList128Bytes buffer of SignalGroupMask entries. Each element in the buffer encodes which signal groups are active for that frame. Evaluate(...) samples the buffer by mapping a time value to a frame index and returns 1.0 if the sampled frame has any bits in common with the queried signal group mask, otherwise 0.0. This struct is value-type lightweight and intended for simple per-frame signal lookups.


Fields

  • private Unity.Collections.FixedList128Bytes<SignalGroupMask> m_Buffer
    Holds the sequence of SignalGroupMask frames. FixedList128Bytes is a stack-allocated fixed-capacity list (128 bytes of storage). The number of frames that can be stored depends on the size of SignalGroupMask; ensure the input array length fits within the fixed list capacity to avoid truncation/overflow.

  • private System.Single m_LengthFactor
    A float representing the buffer length (set to m_Buffer.Length). Used to scale the incoming time value to a frame index: index = floor(time * m_LengthFactor). Stored as float for the multiplication step used when sampling.

Properties

  • None.

Constructors

  • public SignalAnimation(SignalGroupMask[] masks)
    Initializes the animation from a managed SignalGroupMask array. Copies each element into the internal FixedList128Bytes buffer and sets m_LengthFactor to the number of frames. Note: the provided masks.Length must be compatible with the FixedList128Bytes capacity.

Methods

  • public System.Single Evaluate(SignalGroupMask signalGroupMask, System.Single time)
    Samples the animation at the given time and returns 1.0f if the sampled frame contains any bits in common with the provided signalGroupMask, otherwise returns 0.0f.

Behavior details: - The frame index is computed as int index = clamp((int)floor(time * m_LengthFactor), 0, m_Buffer.Length - 1). - For time values < 0, the index clamps to 0; for sufficiently large time values, the index clamps to the last frame (m_Buffer.Length - 1). - The sample test uses bitwise AND: (m_Buffer[index] & signalGroupMask) != 0 — true means at least one common bit is set. - The return is binary (0f or 1f), implemented using math.select.

Usage Example

// Prepare frames (SignalGroupMask is assumed to be a bitmask-like type)
SignalGroupMask[] masks = new SignalGroupMask[]
{
    /* frame 0 mask */, 
    /* frame 1 mask */,
    /* ... */
};

var animation = new SignalAnimation(masks);

// Query the animation at normalized time t (e.g., 0..1)
float t = 0.25f;
SignalGroupMask queryMask = /* some mask */;
float value = animation.Evaluate(queryMask, t); // returns 0f or 1f

// Notes:
// - t < 0 -> samples first frame
// - t large -> samples last frame
// - The animation resolution equals masks.Length (ensure it fits FixedList128Bytes capacity)