Class GradientBackground
A plain C# helper that renders a smooth vertical gradient background by stretching a
2x2 Texture2D over a full-size RawImage child object.
Inherited Members
Namespace: Scylla.Core.Util.UI
Assembly: ScyllaCore.dll
Syntax
public sealed class GradientBackground
Remarks
GradientBackground is NOT a MonoBehaviour. It creates and owns its own
GameObject, which is parented to the caller-supplied object in the constructor.
The gradient child is inserted as the first sibling so it renders behind all other
UI content on the same parent.
The gradient uses a 2x2 bilinear texture: the bottom row holds the bottom color and the top row holds the top color. GPU bilinear filtering produces the smooth vertical transition at any resolution. The texture is updated by calling UpdateColors(Color, Color).
The LayoutElement attached to the child object has ignoreLayout = true,
so the background does not interfere with parent layout groups or
ContentSizeFitter components.
Call Dispose() when the background is no longer needed to release the
owned texture and destroy the child GameObject. Failing to call
Dispose() will leak both the texture and the game object.
Constructors
GradientBackground(GameObject, Color, Color)
Creates a gradient background child object under the specified parent and immediately applies the supplied gradient colors.
Declaration
public GradientBackground(GameObject parent, Color topColor, Color bottomColor)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | parent | The |
| Color | topColor | The color rendered at the top edge of the gradient. Supports full alpha transparency. |
| Color | bottomColor | The color rendered at the bottom edge of the gradient. Supports full alpha transparency. |
Properties
GameObject
Gets the child GameObject that hosts the gradient background.
Declaration
public GameObject GameObject { get; }
Property Value
| Type | Description |
|---|---|
| GameObject |
RawImage
Gets the RawImage component used to display the gradient texture.
Its tint color is always Color.white so the texture colors are displayed unmodified.
Declaration
public RawImage RawImage { get; }
Property Value
| Type | Description |
|---|---|
| RawImage |
RectTransform
Gets the RectTransform of the gradient child object.
It is anchored to fill the parent with zero offset, so its size tracks the parent automatically.
Declaration
public RectTransform RectTransform { get; }
Property Value
| Type | Description |
|---|---|
| RectTransform |
Methods
Dispose()
Destroys the gradient texture and the child GameObject, releasing all
owned resources.
Declaration
public void Dispose()
Remarks
A try-finally block ensures the texture is always destroyed even if
Object.Destroy on the GameObject throws an exception.
After calling Dispose this instance should not be used again.
IsVisible()
Returns whether the gradient background is currently visible.
Declaration
public bool IsVisible()
Returns
| Type | Description |
|---|---|
| bool |
|
SetVisible(bool)
Shows or hides the gradient background by toggling the active state of
the child GameObject.
Declaration
public void SetVisible(bool visible)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | visible |
|
UpdateColors(Color, Color)
Updates the gradient colors by rewriting the 2x2 texture pixels and calling
Texture2D.Apply() to upload the change to the GPU.
Declaration
public void UpdateColors(Color topColor, Color bottomColor)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | topColor | The new color for the top edge of the gradient. |
| Color | bottomColor | The new color for the bottom edge of the gradient. |