Unity - Scripting API: Gradient
class in UnityEngine
/
Implemented in:UnityEngine.CoreModule
Success!
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Submission failed
For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
Description
Represents a Gradient used for animating colors.
Gradients allow animating or interpolating colors by having several "color keys" and "alpha keys". Color keys and alpha keys are separate, and each key has a time specified for it, ranging from 0.0 (0%) to 1.0 (100%). Note that the alpha and colors keys will be automatically sorted by time value and that it is ensured to always have a minimum of 2 color keys and 2 alpha keys.
How the colors are interpolated between the keys is controlled by GradientMode.
Public Gradient variables used in scripts automatically display the gradient editor in the inspector window. GradientUsageAttribute allows specifying whether the gradient colors should be high dynamic range for editing.
Properties
| Property | Description |
|---|---|
| alphaKeyCount | The number of alpha keys defined in the gradient. |
| alphaKeys | All alpha keys defined in the gradient. |
| colorKeyCount | The number of color keys defined in the gradient. |
| colorKeys | All color keys defined in the gradient. |
| colorSpace | Indicates the color space that the gradient color keys are using. |
| mode | Controls how the gradient colors are interpolated. |
Constructors
| Constructor | Description |
|---|---|
| Gradient | Create a new Gradient object. |
Public Methods
| Method | Description |
|---|---|
| Evaluate | Calculate color at a given time. |
| GetAlphaKeys | Get all the alpha keys assigned to the gradient. |
| GetColorKeys | Get all the color keys assigned to the gradient. |
| SetAlphaKeys | Setup gradient with an array of alpha keys. |
| SetColorKeys | Setup gradient with an array of color keys. |
| SetKeys | Setup Gradient with an array of color keys and alpha keys. |