Skip to content

Game.UI.Widgets.GradientStop

Assembly: Assembly-CSharp (game runtime assembly; types from the game's managed code)
Namespace: Game.UI.Widgets

Type: struct

Base: IJsonWritable

Summary:
Represents a single stop in a color gradient. Each stop contains an offset (typically a normalized position along the gradient) and a Color32 value. The struct implements IJsonWritable to allow writing/serializing itself using the game's IJsonWriter abstraction. The Write method emits the type full name and two properties: "offset" and "color".


Fields

  • public System.Single offset
    Defines the position of this gradient stop. Typically interpreted as a normalized value between 0.0 and 1.0 (start to end of gradient). The struct does not clamp or validate the value.

  • public UnityEngine.Color32 color
    The color at this stop. Uses UnityEngine.Color32 (byte components 0–255). This is the color serialized by Write.

Properties

  • This type has no properties.

Constructors

  • public GradientStop(float offset, Color32 color)
    Creates a new GradientStop with the given offset and color. No validation is performed on the offset or color values.

Methods

  • public void Write(IJsonWriter writer)
    Serializes the GradientStop to the provided IJsonWriter. Behavior:
  • Calls writer.TypeBegin(GetType().FullName) to begin a typed object.
  • Writes a property named "offset" and the offset value.
  • Writes a property named "color" and the color value.
  • Calls writer.TypeEnd() to finish the typed object. Note: the writer is expected to know how to serialize Color32; this code relies on the writer's implementation for actual color representation.

Usage Example

using UnityEngine;
using Colossal.UI.Binding;

// create a stop at 25% using opaque red
var stop = new Game.UI.Widgets.GradientStop(0.25f, new Color32(255, 0, 0, 255));

// serialize using a game-provided writer implementation
IJsonWriter writer = /* obtain writer from context */;
stop.Write(writer);

// Example: building a small gradient array
var gradientStops = new[]
{
    new Game.UI.Widgets.GradientStop(0f,   new Color32(0,   0,   0,   255)),
    new Game.UI.Widgets.GradientStop(0.5f, new Color32(128, 128, 128, 255)),
    new Game.UI.Widgets.GradientStop(1f,   new Color32(255, 255, 255, 255))
};
foreach (var s in gradientStops) s.Write(writer);

Additional notes: - Treat offsets as normalized positions unless your caller expects otherwise. - The struct is lightweight and suitable for storing small gradient definitions in UI code or for serializing/deserializing via the game's JSON writer infrastructure.