本文整理汇总了C#中UnityEngine.Gradient.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# Gradient.Evaluate方法的具体用法?C# Gradient.Evaluate怎么用?C# Gradient.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Gradient
的用法示例。
在下文中一共展示了Gradient.Evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawGradientRect
/// <summary>
/// Draws gradient rectangle on texture
/// </summary>t
public static void DrawGradientRect(this Texture2D texture, int x, int y, int blockWidth, int blockHeight,
Gradient gradient, Directions progressionDirection)
{
Func<int, int, Color> getColor;
switch (progressionDirection)
{
case Directions.Left:
getColor = (_x, _y) => gradient.Evaluate(1 - (float) _x/(float) blockWidth);
break;
case Directions.Right:
getColor = (_x, _y) => gradient.Evaluate((float) _x/(float) blockWidth);
break;
case Directions.Down:
getColor = (_x, _y) => gradient.Evaluate(1 - (float) _y/(float) blockHeight);
break;
case Directions.Up:
getColor = (_x, _y) => gradient.Evaluate((float) _y/(float) blockHeight);
break;
default:
Debug.LogError("Not supported direction: " + progressionDirection);
return;
}
var colors = new Color[blockWidth*blockHeight];
for (int _y = 0; _y < blockHeight; _y++)
{
for (int _x = 0; _x < blockWidth; _x++)
{
colors[_x + _y*blockWidth] = getColor(_x, _y);
}
}
texture.SetPixels(x, y, blockWidth, blockHeight, colors);
}
示例2: RefreshPreview
public static void RefreshPreview(Gradient gradient, Texture2D preview)
{
Color[] colors = new Color[512];
for (int index = 0; index < 256; ++index)
colors[index] = colors[index + 256] = gradient.Evaluate((float) index / 256f);
preview.SetPixels(colors);
preview.Apply();
}
示例3: BlendGradient
public Gradient BlendGradient(Gradient terrain_gradient, Gradient object_gradient)
{
List<ColorHSV> targetPalette = new List<ColorHSV>();
List<ColorHSV> currentPalette = new List<ColorHSV>();
targetPalette = RandomE.TetradicPalette(0.25f, 0.75f);
Debug.Log(targetPalette.Count);
ColorHSV groundColor = new ColorHSV(terrain_gradient.Evaluate(0));
ColorHSV newColor = new ColorHSV(object_gradient.Evaluate(1));
targetPalette.Add(ColorHSV.Lerp(groundColor, newColor, 0.5f));
var gradient = ColorE.Gradient(from: targetPalette[2].WithSV(0.8f, 0.8f),
to: targetPalette[3].WithSV(0.8f, 0.8f));
return object_gradient;
}
示例4: Start
// Use this for initialization
void Start ()
{
padGradient = PanelWaveform.GetColorGradient (lineAttributes.startColor, lineAttributes.endColor);
for(int i = 0; i < numLines; i++)
{
float val = (float)i/(numLines-1);
lines.Add(NewLine(padGradient.Evaluate(val)));
}
CreatePad ();
//just in case someone changes the private var. rippleLines can't be > numLines
if( rippleWidth > numLines)
{
rippleWidth = numLines;
}
}
示例5: GenerateColorsGoldenRatioGradient
/// <summary>
/// Gives a list of colors where that maximises distance on
/// the gradient between consecutaive colors.
/// </summary>
/// <param name="colorCount"></param>
/// <param name="gradient"></param>
/// <returns></returns>
public static List<Color> GenerateColorsGoldenRatioGradient(int colorCount, Gradient gradient)
{
var colors = new List<Color>();
var t = Random.value;
for (int i = 0; i < colorCount; i++)
{
var newColor = gradient.Evaluate(t);
colors.Add(newColor);
t += GoldenRatioConjugate;
t %= 1.0f;
}
return colors;
}
示例6: Generate
private void Generate()
{
gradient = RandomE.gradientHSV;
var noiseOffset = new Vector2(Random.Range(0f, 100f), Random.Range(0f, 100f));
draft.colors.Clear();
for (int i = 0; i < draft.vertices.Count; i++)
{
var vertex = draft.vertices[i];
var x = scale*vertex.x/xSegments + noiseOffset.x;
var y = scale*vertex.z/zSegments + noiseOffset.y;
var noise = Mathf.PerlinNoise(x, y);
draft.vertices[i] = new Vector3(vertex.x, noise, vertex.z);
draft.colors.Add(gradient.Evaluate(noise));
}
GetComponent<MeshFilter>().mesh = draft.ToMesh();
}
示例7: Grad
public static Color Grad(float x)
{
/*
// Terrain gradient color keys
List<GradientColorKey> terrainColorKeys = new List<GradientColorKey>
{
new GradientColorKey(new Color(0, 0, 0.5f), 0),
new GradientColorKey(new Color(0.125f, 0.25f, 0.5f), 0.4f),
new GradientColorKey(new Color(0.25f, 0.375f, 0.75f), 0.48f),
new GradientColorKey(new Color(0, 0.75f, 0), 0.5f),
new GradientColorKey(new Color(0.75f, 0.75f, 0), 0.625f),
new GradientColorKey(new Color(0.625f, 0.375f, 0.25f), 0.75f),
new GradientColorKey(new Color(0.5f, 1, 1), 0.875f),
new GradientColorKey(Color.white, 1)
};
// Generic gradient alpha keys
var alphaKeys = new List<GradientAlphaKey> {new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1)};
*/
Gradient g = new Gradient();
GradientColorKey[] gck;
GradientAlphaKey[] gak;
// Populate the color keys at the relative time 0 and 1 (0 and 100%)
gck = new GradientColorKey[2];
gck[0].color = Color.red;
gck[0].time = 0.0f;
gck[1].color = Color.blue;
gck[1].time = 1.0f;
// Populate the alpha keys at relative time 0 and 1 (0 and 100%)
gak = new GradientAlphaKey[2];
gak[0].alpha = 1.0f;
gak[0].time = 0.0f;
gak[1].alpha = 0.0f;
gak[1].time = 1.0f;
//g.SetKeys(terrainColorKeys.ToArray(), alphaKeys.ToArray());
g.SetKeys(gck,gak);
return g.Evaluate(x);;
}
示例8: GenerateColorsRandomGradient
/// <summary>
/// Generates a list of colours randomly sampled from a gradient.
/// </summary>
/// <param name="colorCount"></param>
/// <param name="gradient"></param>
/// <returns></returns>
public static List<Color> GenerateColorsRandomGradient(int colorCount, Gradient gradient)
{
var colors = new List<Color>();
for (int i = 0; i < colorCount; i++)
{
var color = gradient.Evaluate(Random.value);
colors.Add(color);
}
return colors;
}
示例9: RefreshPreview
public static void RefreshPreview(Gradient gradient, Texture2D preview)
{
Color[] array = new Color[512];
for (int i = 0; i < 256; i++)
{
array[i] = (array[i + 256] = gradient.Evaluate((float)i / 256f));
}
preview.SetPixels(array);
preview.Apply();
}
示例10: GetColorFromGradientAtTime
/// <summary>
/// Gets the color from gradient at time.
/// </summary>
/// <returns>The color from gradient at time.</returns>
/// <param name="gradient">Gradient.</param>
/// <param name="time">Time.</param>
private Color GetColorFromGradientAtTime(Gradient gradient, float time)
{
if (!HydraMathUtils.Approximately(m_GradientLength, 0.0f))
time /= m_GradientLength;
return gradient.Evaluate(time, m_GradientWrapMode);
}
示例11: GetRandomColorFromGradient
/// <summary>
/// Gets a random color from the gradient.
/// </summary>
/// <returns>The random color from gradient.</returns>
/// <param name="gradient">Gradient.</param>
private Color GetRandomColorFromGradient(Gradient gradient)
{
return gradient.Evaluate(m_RandomColorGenerator.value);
}
示例12: DrawTransparentCircles
IEnumerator DrawTransparentCircles() {
currentOverlay.SetPixels32(blankOverlay.GetPixels32());
List<Vector2> convertedLocations = new List<Vector2>();
foreach(AnomalousEvent anomaly in AEM.EventList.Values) {
foreach(GridLocation gl in anomaly.gridNumToLocations) {
Debug.Log ("GridLocation");
if(gl.statusCode > 0) {
float tempX = currentOverlay.width * ((-180 - gl.spawnLocation.y)/(-180 - 180));
float tempY = currentOverlay.height * ((-90 - gl.spawnLocation.x)/(-90 - 90));
convertedLocations.Add (new Vector2(tempX,tempY));
}
}
}
Gradient g = new Gradient();
GradientColorKey[] gck = new GradientColorKey[2];
gck[0].color = Color.red;
gck[0].time = 0.0f;
gck[1].color = Color.yellow;
gck[1].time = 1.0f;
GradientAlphaKey[] gak = new GradientAlphaKey[2];
gak[0].alpha = 0.75f;
gak[0].time = 0.0f;
gak[1].alpha = 0.0f;
gak[1].time = 1.0f;
g.SetKeys(gck,gak);
foreach(Vector2 loc in convertedLocations) {
for(int x = (int)Mathf.Clamp(loc.x - tempCircleSize, 0,overlayWidth - 1); x < (int)Mathf.Clamp(loc.x + tempCircleSize, 0,overlayWidth - 1); x++) {
for(int y = (int)Mathf.Clamp(loc.y - tempCircleSize, 0,overlayHeight -1); y < (int)Mathf.Clamp(loc.y + tempCircleSize, 0,overlayHeight - 1); y++) {
float dist = Vector2.Distance(loc, new Vector2(x,y));
if(dist<tempCircleSize) {
Color temp = currentOverlay.GetPixel(x,y);
Color blend;
if (WaterLandMask.GetPixel(x,y) != Color.white){
blend = Color.clear;
} else {
blend = Color.white;
}
if(temp != Color.clear) {
if(temp.a > g.Evaluate(dist/tempCircleSize).a)
currentOverlay.SetPixel(x,y,(temp * blend));
else
currentOverlay.SetPixel(x,y,(g.Evaluate(dist/tempCircleSize) * blend));
} else {
currentOverlay.SetPixel(x,y,(g.Evaluate(dist/tempCircleSize) * blend));
}
}
}
if( x % 10 == 0)
yield return null;
}
currentOverlay.Apply();
MapOverlay.GetComponent<Renderer>().material.SetTexture("_MainTex", currentOverlay);
}
//Debug.Log ("done");
//currentOverlay = temp;
}
示例13: GetTexture
/// <summary>
/// Creates a texture map for the current content of the noise map.
/// </summary>
/// <param name="gradient">The gradient to color the texture map with.</param>
/// <returns>The created texture map.</returns>
public Texture2D GetTexture(Gradient gradient)
{
Texture2D texture = new Texture2D(this.m_width, this.m_height);
Color[] pixels = new Color[this.m_width * this.m_height];
for (int x = 0; x < this.m_width; x++)
{
for (int y = 0; y < this.m_height; y++)
{
float sample = 0.0f;
if (!float.IsNaN(this.m_borderValue) && (x == 0 || x == this.m_width - m_ucBorder || y == 0 || y == this.m_height - m_ucBorder))
{
sample = this.m_borderValue;
}
else
{
sample = this.m_data[x, y];
}
pixels[x + y * this.m_width] = gradient.Evaluate((sample + 1) / 2);
}
}
texture.SetPixels(pixels);
texture.wrapMode = TextureWrapMode.Clamp;
texture.Apply();
return texture;
}
示例14: SetStartColor
public void SetStartColor(Gradient minGradient, Gradient maxGradient) {
if (Application.isPlaying == false) return;
if (this.startColor.minMaxState == MinMaxState.MinMaxGradient) {
this.SetColor_REFLECTION(this.particleSystem, "minGradient", minGradient);
this.SetColor_REFLECTION(this.particleSystem, "maxGradient", maxGradient);
this.SetColor_PARTICLES(maxGradient.Evaluate(0f));
}
}
示例15: RefreshPreview
public static void RefreshPreview(Gradient gradient, Texture2D preview)
{
Color[] colors = new Color[0x200];
for (int i = 0; i < 0x100; i++)
{
colors[i] = colors[i + 0x100] = gradient.Evaluate(((float) i) / 256f);
}
preview.SetPixels(colors);
preview.Apply();
}