Skip to content

Game.ColorDefinition

Assembly: Assembly-CSharp (game assembly; the code is part of the game's compiled assemblies)
Namespace: Game.Tools

Type: struct

Base: System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter

Summary:
A simple ECS component used to store a color value (UnityEngine.Color32) for an entity. This struct is a plain data container (POD) intended for use with Unity DOTS/Entities queries and systems. Typical uses include giving tools, props, or other game objects an associated color that systems can read or modify.


Fields

  • public UnityEngine.Color32 m_Color
    Holds the RGBA color as bytes (0-255). Use this field to read or assign the color for an entity. Color32 is compact and suitable for serialization and fast access in ECS.

Properties

  • This type defines no properties. It is a plain public field component for direct ComponentData access.

Constructors

  • public ColorDefinition()
    Default struct constructor (value-initialized). You can also initialize explicitly: new ColorDefinition { m_Color = new Color32(r, g, b, a) }

Methods

  • This struct defines no methods. It only implements IComponentData and IQueryTypeParameter (marker/interface usage for ECS queries).

Usage Example

// Add a ColorDefinition to a new entity
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = entityManager.CreateEntity(typeof(Game.Tools.ColorDefinition));
entityManager.SetComponentData(entity, new Game.Tools.ColorDefinition {
    m_Color = new Color32(255, 0, 0, 255) // opaque red
});

// Read/modify inside a system
public partial class ColorConsumerSystem : SystemBase
{
    protected override void OnUpdate()
    {
        Entities.ForEach((ref Game.Tools.ColorDefinition colorDef) =>
        {
            // Example: darken the color slightly (work with bytes)
            colorDef.m_Color.r = (byte)Mathf.Max(0, colorDef.m_Color.r - 10);
        }).ScheduleParallel();
    }
}

Additional notes: - Color32 stores components as bytes (r, g, b, a); convert to UnityEngine.Color if you need floating-point operations: Color color = colorDef.m_Color; and back via (Color32)color. - Because this is an IComponentData, prefer using EntityManager/EntityCommandBuffer or ECS queries to add/read/write this component rather than accessing it from GameObjects directly.