Version: 2020.1

Gradient

class in UnityEngine

切换到手册

描述

渐变,用于动画化颜色。

另请参阅:GradientColorKeyGradientAlphaKey

using UnityEngine;

public class ExampleScript : MonoBehaviour { Gradient gradient; GradientColorKey[] colorKey; GradientAlphaKey[] alphaKey;

void Start() { gradient = new Gradient();

// Populate the color keys at the relative time 0 and 1 (0 and 100%) colorKey = new GradientColorKey[2]; colorKey[0].color = Color.red; colorKey[0].time = 0.0f; colorKey[1].color = Color.blue; colorKey[1].time = 1.0f;

// Populate the alpha keys at relative time 0 and 1 (0 and 100%) alphaKey = new GradientAlphaKey[2]; alphaKey[0].alpha = 1.0f; alphaKey[0].time = 0.0f; alphaKey[1].alpha = 0.0f; alphaKey[1].time = 1.0f;

gradient.SetKeys(colorKey, alphaKey);

// What's the color at the relative time 0.25 (25 %) ? Debug.Log(gradient.Evaluate(0.25f)); } }

注意,Alpha 和颜色键将按时间值自动排序,并且确保始终至少有 2 个颜色键和 2 个 Alpha 键。

变量

alphaKeys在渐变中定义的所有 Alpha 键。
colorKeys在渐变中定义的所有颜色键。
mode控制计算渐变的方式。

构造函数

Gradient创建新的 Gradient 对象。

公共函数

Evaluate计算给定时间处的颜色。
SetKeys使用颜色键和 Alpha 键的数组设置渐变。