Game.Prefabs.ColorVariation
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: Unity.Entities.IBufferElementData
Summary:
ColorVariation is a Unity ECS buffer element used by prefab parts to describe color variation data. It references a ColorSet (from Game.Rendering), identifies which color group it applies to, controls synchronization and source type, encodes per-color probability and optional external channel mappings, and stores HSV/value and alpha variation ranges. The struct is annotated with InternalBufferCapacity(1) so it is intended to be used as a dynamic buffer on entities with an initial capacity of 1.
Fields
-
public ColorSet m_ColorSet
Holds the ColorSet reference/identifier that provides the base colors this variation operates on. ColorSet is defined in Game.Rendering. -
public ColorGroupID m_GroupID
Identifies which color group in the ColorSet this variation targets (likely an enum or identifier for color slots/groups). -
public ColorSyncFlags m_SyncFlags
Flags controlling synchronization behavior (e.g., whether the color is synced across variants or systems). Implementation-specific enum/bitflags. -
public ColorSourceType m_ColorSourceType
Indicates the source of color data (e.g., palette, material property, external source). Implementation-specific enum. -
public byte m_Probability
Probability weight for this variation (0–255). How this value is interpreted depends on the consuming code (e.g., normalized or compared directly). -
public sbyte m_ExternalChannel0
public sbyte m_ExternalChannel1
-
public sbyte m_ExternalChannel2
Indexes of external color channels mapped to each color index. Negative values (the default) indicate "no external channel". These are signed bytes to allow -1 to mean unassigned. -
public byte m_HueRange
public byte m_SaturationRange
-
public byte m_ValueRange
Per-color HSV variation ranges (stored as bytes). Non-zero values indicate that random variation in that component is permitted/used. -
public byte m_AlphaRange0
public byte m_AlphaRange1
public byte m_AlphaRange2
Alpha variation ranges for up to three color channels (stored as bytes). Non-zero values indicate alpha variation is enabled for the respective channel.
Properties
-
public bool hasExternalChannels { get; }
True if any of m_ExternalChannel0/1/2 are >= 0. Use to quickly test whether this variation maps to external channels. -
public bool hasVariationRanges { get; }
True if any of m_HueRange, m_SaturationRange, or m_ValueRange are non-zero. Indicates HSV variation is available. -
public bool hasAlphaRanges { get; }
True if any of m_AlphaRange0/1/2 are non-zero. Indicates at least one alpha range is enabled.
Constructors
public ColorVariation()
Structs in C# have an implicit parameterless constructor. All fields are default-initialized (numeric fields to 0, sbyte channels to 0 which should be set to -1 explicitly if you want them unassigned).
Note: Typical usage sets m_ExternalChannel* to -1 to mark them as unassigned because the default 0 would otherwise indicate channel 0.
Methods
public int GetExternalChannelIndex(int colorIndex) : System.Int32
Returns the external channel index mapped for a given color index (0, 1 or 2). Returns -1 for out-of-range colorIndex or if the stored sbyte is negative. Implementation:- colorIndex 0 -> returns m_ExternalChannel0
- colorIndex 1 -> returns m_ExternalChannel1
- colorIndex 2 -> returns m_ExternalChannel2
-
default -> -1
-
public void SetExternalChannelIndex(int colorIndex, int channelIndex) : System.Void
Sets the external channel index (casts to sbyte) for colorIndex 0..2. If colorIndex is outside 0..2 the method does nothing. Use channelIndex = -1 to mark the external channel as unassigned.
Usage Example
// Example: adding a ColorVariation to an entity's dynamic buffer in a system
var buffer = entityManager.GetBuffer<ColorVariation>(entity);
var variation = new ColorVariation
{
m_ColorSet = myColorSet, // from Game.Rendering
m_GroupID = myGroupId,
m_SyncFlags = ColorSyncFlags.None,
m_ColorSourceType = ColorSourceType.Palette,
m_Probability = 128, // example probability
m_ExternalChannel0 = -1, // -1 = unassigned
m_ExternalChannel1 = -1,
m_ExternalChannel2 = -1,
m_HueRange = 10, // allow small hue variation
m_SaturationRange = 0,
m_ValueRange = 5,
m_AlphaRange0 = 0,
m_AlphaRange1 = 0,
m_AlphaRange2 = 0,
};
buffer.Add(variation);
// Using helper methods
int ext0 = buffer[0].GetExternalChannelIndex(0);
buffer[0].SetExternalChannelIndex(1, 2); // map color index 1 to external channel 2