Skip to content

Game.Prefabs.Effects.EffectColor

Assembly: Assembly-CSharp
Namespace: Game.Prefabs.Effects

Type: class

Base: ComponentBase

Summary:
EffectColor is a prefab component used to configure color variation for an effect prefab in the ECS world. It exposes inspector-editable fields (source and randomness sliders) which are applied to the EffectColorData component on the entity during prefab initialization. The randomness values are expressed in percent (0–100) in the inspector and converted to 0–1 ranges when written into the EffectColorData.m_VaritationRanges vector. The class is also annotated with a ComponentMenu attribute so it appears under "Effects/" in the Unity inspector.


Fields

  • public EffectColorSource m_Source
    The source of color data for the effect. Typically this is an enum or reference that selects where the effect color comes from (e.g., prefab color, global tint, a palette). This value is copied into the EffectColorData component during Initialize.

  • public float m_HueRandomness
    Inspector-exposed slider (Range 0–100). Represents hue variation as a percentage. Converted to a 0–1 value (by multiplying by 0.01) and stored in EffectColorData.m_VaritationRanges.x.

  • public float m_SaturationRandomness
    Inspector-exposed slider (Range 0–100). Represents saturation variation as a percentage. Converted to 0–1 and stored in EffectColorData.m_VaritationRanges.y.

  • public float m_BrightnessRandomness
    Inspector-exposed slider (Range 0–100). Represents brightness/value variation as a percentage. Converted to 0–1 and stored in EffectColorData.m_VaritationRanges.z.

Properties

  • None declared on this class. (The class only exposes public fields for inspector editing and overrides methods from ComponentBase.)

Constructors

  • public EffectColor()
    Default constructor (implicit). No special construction logic in the source; initialization work happens in the Initialize override at entity creation time.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds the component types that this prefab component requires on the entity. EffectColor adds a read/write EffectColorData component:
  • components.Add(ComponentType.ReadWrite()); This ensures the EffectColorData component is present on the prefab entity so Initialize can set its values.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty implementation. No additional archetype-only components are required by this prefab component. If an author wanted the component included in archetype creation explicitly, they would add types here.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called when the prefab is instantiated as an ECS entity. Behavior:

  • Calls base.Initialize(entityManager, entity).
  • Reads the existing EffectColorData struct from the entity.
  • Copies m_Source into componentData.m_Source.
  • Converts inspector percentage randomness fields into 0–1 ranges by multiplying each by 0.01 and writes them into componentData.m_VaritationRanges.x/y/z.
  • Writes the modified componentData back with entityManager.SetComponentData(entity, componentData). Notes: This follows the standard pattern of GetComponentData -> modify -> SetComponentData. Ensure EffectColorData exists on the entity (GetPrefabComponents ensures that).

Usage Example

// This illustrates what Initialize does under-the-hood.
// The prefab author can configure the public fields in the inspector,
// and when the prefab is converted to an entity the values are applied.

public override void Initialize(EntityManager entityManager, Entity entity)
{
    base.Initialize(entityManager, entity);

    // Read existing data, modify and write back
    EffectColorData componentData = entityManager.GetComponentData<EffectColorData>(entity);
    componentData.m_Source = m_Source;
    componentData.m_VaritationRanges.x = m_HueRandomness * 0.01f;
    componentData.m_VaritationRanges.y = m_SaturationRandomness * 0.01f;
    componentData.m_VaritationRanges.z = m_BrightnessRandomness * 0.01f;
    entityManager.SetComponentData(entity, componentData);
}

Additional notes and tips: - The [Range(0f, 100f)] attributes clamp editor input and provide a slider UI; the code assumes these are percentages and converts them to normalized 0–1 ranges for storage in EffectColorData. - EffectColorData appears to use a Vector3-like field named m_VaritationRanges (note the spelling in the code) for hue/saturation/brightness variation. Be careful to match the expected ordering (x = hue, y = saturation, z = brightness) when reading the data elsewhere. - Because GetArchetypeComponents is empty, this component relies on GetPrefabComponents to ensure the EffectColorData component exists. If you need the data present at archetype creation time, consider populating GetArchetypeComponents. - The ComponentMenu attribute organizes this component in the Unity component menu under "Effects/".