您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

59 行
2.2 KiB

using UnityEngine;
namespace UnityEditor.VFXToolbox
{
internal class CurveToTextureUtility
{
public static void CurveToTexture(AnimationCurve curve, ref Texture2D texture)
{
if(texture != null && curve!= null && texture.height == 1 && texture.width > 1)
{
Color[] colors = new Color[texture.width];
for (int i = 0; i < texture.width; i++)
{
float t = (float)i / (texture.width - 1);
float v = curve.Evaluate(t);
colors[i] = new Color(v, v, v, 1);
}
texture.SetPixels(colors);
texture.Apply();
}
}
public static void GradientToTexture(Gradient gradient, ref Texture2D texture, bool linear = false)
{
if(texture != null && gradient != null && texture.height == 1 && texture.width > 1)
{
Color[] colors = new Color[texture.width];
for (int i = 0; i < texture.width; i++)
{
float t = (float)i / (texture.width - 1);
if(linear)
colors[i] = gradient.Evaluate(t).linear;
else
colors[i] = gradient.Evaluate(t);
}
texture.SetPixels(colors);
texture.Apply();
}
}
public static void GradientToTexture(Gradient gradient, AnimationCurve curve, ref Texture2D texture, bool linear = false)
{
if (texture != null && gradient != null && texture.height == 1 && texture.width > 1)
{
Color[] colors = new Color[texture.width];
for (int i = 0; i < texture.width; i++)
{
float t = (float)i / (texture.width - 1);
float b = curve.Evaluate(t);
if (linear)
colors[i] = b * gradient.Evaluate(t).linear;
else
colors[i] = b * gradient.Evaluate(t);
}
texture.SetPixels(colors);
texture.Apply();
}
}
}
}