Game.Routes.Color
Assembly: Assembly-CSharp (typical game/mod assembly)
Namespace: Game.Routes
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
A lightweight ECS component that holds a UnityEngine.Color32 value for the game's routing systems. The struct is serializable via Colossal.Serialization (implements ISerializable) so its color value can be written to and read from save/stream writers. Being an IComponentData makes it usable with Unity's Entities (ECS) and implementing IQueryTypeParameter allows it to be used as a query parameter type where supported.
Fields
public UnityEngine.Color32 m_Color
Holds the color value. This is a blittable value type (Color32) and represents the RGBA color stored by the component.
Properties
- None.
This type exposes its data directly via the public field m_Color; there are no C# properties.
Constructors
public Color(UnityEngine.Color32 color)
Initializes the component with the provided Color32 value and stores it into m_Color.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Color field to the provided writer. Used by the game's serialization pipeline to persist this component's color. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads a Color32 value from the provided reader and assigns it to m_Color. Used when loading or deserializing component data.
Usage Example
// Create a Color component and add it to an entity (EntityManager usage)
using Unity.Entities;
using UnityEngine;
using Game.Routes;
Color32 red = new Color32(255, 0, 0, 255);
var colorComponent = new Color(red);
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity entity = entityManager.CreateEntity();
entityManager.AddComponentData(entity, colorComponent);
// Example of serialization usage (writer/reader are provided by the game's serialization system)
void SaveComponent<TWriter>(TWriter writer, Color comp) where TWriter : Colossal.Serialization.Entities.IWriter
{
comp.Serialize(writer);
}
void LoadComponent<TReader>(TReader reader, out Color comp) where TReader : Colossal.Serialization.Entities.IReader
{
comp = new Color();
comp.Deserialize(reader);
}
{{ Additional notes: - The struct is suitable for use in burst-compatible jobs as it contains only blittable data (Color32). - Since data is stored in a public field, direct access is simple/fast, but consider encapsulation if you need validation. - IQueryTypeParameter support means it can be used in query definitions depending on the project's ECS utilities. }}