本文整理汇总了C#中UnityEngine.Gradient.SetKeys方法的典型用法代码示例。如果您正苦于以下问题:C# Gradient.SetKeys方法的具体用法?C# Gradient.SetKeys怎么用?C# Gradient.SetKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Gradient
的用法示例。
在下文中一共展示了Gradient.SetKeys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Update
// Update is called once per frame
void Update () {
if (timer == 0) {
LastColor = SoupMaterial.color;
}
if (!NextColor.Equals(SoupMaterial.color)) {
timer += Time.deltaTime;
Color c = Color.Lerp(LastColor, NextColor, timer / duration);
SoupMaterial.color = c;
SoupLight.color = c;
SoupLight.intensity = Mathf.Max(1.5f * (duration - timer), 1);
var col = Smoke.colorOverLifetime;
col.enabled = true;
Gradient grad = new Gradient();
grad.SetKeys( new GradientColorKey[] { new GradientColorKey(c, 0.0f), new GradientColorKey(Color.gray, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(0.0f, 1.0f) } );
col.color = new ParticleSystem.MinMaxGradient(grad);
if (timer >= duration) {
SoupMaterial.color = NextColor;
SoupLight.intensity = 1;
timer = 0;
}
}
}
示例2: Gradient
/// <summary>
/// Creates a gradient between two colors
/// </summary>
public static Gradient Gradient(Color from, Color to)
{
var g = new Gradient();
g.SetKeys(new[] {new GradientColorKey(from, 0), new GradientColorKey(to, 1)},
new[] {new GradientAlphaKey(from.a, 0), new GradientAlphaKey(to.a, 1)});
return g;
}
示例3: GradientPresets
/// <summary>
/// Initializes a new instance of Gradient.
/// </summary>
static GradientPresets()
{
// Grayscale gradient color keys
var grayscaleColorKeys = new List<GradientColorKey>
{
new GradientColorKey(Color.black, 0),
new GradientColorKey(Color.white, 1)
};
// RGB gradient color keys
var rgbColorKeys = new List<GradientColorKey>
{
new GradientColorKey(Color.red, 0),
new GradientColorKey(Color.green, 0.5f),
new GradientColorKey(Color.blue, 1)
};
// RGBA gradient color keys
var rgbaColorKeys = new List<GradientColorKey>
{
new GradientColorKey(Color.red, 0),
new GradientColorKey(Color.green, 1 / 3f),
new GradientColorKey(Color.blue, 2 / 3f),
new GradientColorKey(Color.black, 1)
};
// RGBA gradient alpha keys
var rgbaAlphaKeys = new List<GradientAlphaKey> {new GradientAlphaKey(0, 2 / 3f), new GradientAlphaKey(1, 1)};
// Terrain gradient color keys
var 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)};
_empty = new Gradient();
_rgb = new Gradient();
_rgb.SetKeys(rgbColorKeys.ToArray(), alphaKeys.ToArray());
_rgba = new Gradient();
_rgba.SetKeys(rgbaColorKeys.ToArray(), rgbaAlphaKeys.ToArray());
_grayscale = new Gradient();
_grayscale.SetKeys(grayscaleColorKeys.ToArray(), alphaKeys.ToArray());
_terrain = new Gradient();
_terrain.SetKeys(terrainColorKeys.ToArray(), alphaKeys.ToArray());
}
示例4: InitImpulseGradient
private void InitImpulseGradient ()
{
impulseGradient = new Gradient ();
GradientColorKey[] gck = new GradientColorKey[impulseGradientColors.Length];
GradientAlphaKey[] gak = new GradientAlphaKey[impulseGradientColors.Length];
for (int i = 0; i < impulseGradientColors.Length; i++) {
gck [i].color = impulseGradientColors [i];
gak [i].alpha = 1.0f;
gck [i].time = gak [i].time = impulseGradientTimes [i];
}
impulseGradient.SetKeys (gck, gak);
}
示例5: GetLerp
/// <summary>
/// Returns a gradient that represents a linear interpolation between two colors.
/// </summary>
/// <param name="color1"></param>
/// <param name="color2"></param>
/// <returns></returns>
public static Gradient GetLerp(Color color1, Color color2)
{
var gradient = new Gradient();
var leftColorKey = new GradientColorKey(color1, 0);
var rightColorKey = new GradientColorKey(color2, 1);
var leftAlphaKey = new GradientAlphaKey(color1.a, 0);
var rightAlphaKey = new GradientAlphaKey(color1.a, 1);
gradient.SetKeys(
new[]{leftColorKey, rightColorKey},
new[]{leftAlphaKey, rightAlphaKey});
return gradient;
}
示例6: CreateGradTexture
public void CreateGradTexture(){
// Create gradient object and assign generic starting colours
Grad = new Gradient();
LastGrad = new Gradient();
GradientColorKey[] gck = new GradientColorKey[2];
gck[0] = new GradientColorKey(Color.black, 0f);
gck[1] = new GradientColorKey(Color.white, 1f);
GradientAlphaKey[] gak = new GradientAlphaKey[2];
gak[0] = new GradientAlphaKey(1f, 0f);
gak[1] = new GradientAlphaKey(1f, 1f);
Grad.SetKeys(gck, gak);
LastGrad.SetKeys(gck, gak);
outTexture = new Texture2D(_gradientSizeX,_gradientSizeY);
outTexture.hideFlags = HideFlags.HideAndDontSave;
// Debug.Log (outTexture);
}
示例7: Start
void Start () {
GradientColorKey[] gradColorKey;
GradientAlphaKey[] gradAlphaKey;
grad = new Gradient();
gradColorKey = new GradientColorKey[3];
gradAlphaKey = new GradientAlphaKey[1];
gradColorKey[0].color = Color.magenta;
gradColorKey[0].time = 0.0f;
gradColorKey[1].color = Color.green;
gradColorKey[1].time = 0.5f;
gradColorKey[2].color = Color.magenta;
gradColorKey[2].time = 1.0f;
gradAlphaKey[0].alpha = 1.0f;
grad.SetKeys(gradColorKey,gradAlphaKey);
}
示例8: 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);;
}
示例9: CreateModel
public override void CreateModel(Transform parent)
{
GameObject model = Object.Instantiate(Resources.Load("ParticleSystem")) as GameObject;
if (model != null)
{
var colorOverLifetimeModule = model.GetComponent<ParticleSystem>().colorOverLifetime;
var gradient = new Gradient();
var gradientColorKeys = new GradientColorKey[]
{new GradientColorKey(_startColor, 0f), new GradientColorKey(_endColor, 1f)};
var gradientAlphaKeys = new GradientAlphaKey[]
{new GradientAlphaKey(1f, 0f), new GradientAlphaKey(1f, 0.8f), new GradientAlphaKey(0f, 1f)};
// only fade out in the last 20% of lifetime
gradient.SetKeys(gradientColorKeys, gradientAlphaKeys);
colorOverLifetimeModule.color = new ParticleSystem.MinMaxGradient(gradient);
model.transform.SetParent(parent);
model.transform.localPosition = LocalCoinPosition();
SetModel(model);
}
}
示例10: EvaluateColor
public Color EvaluateColor(double value)
{
if (_unityGradient == null)
{
var colorKeys = Stops
.Select(i => i.TryConvertToColorKey(Min, Max))
.Where(i => i != null)
.Select(i => i.Value)
.ToArray();
var alphaKeys = Stops
.Select(i => i.TryConvertToAlphaKey(Min, Max))
.Where(i => i != null)
.Select(i => i.Value)
.ToArray();
_unityGradient = new Gradient();
_unityGradient.SetKeys(colorKeys, alphaKeys);
}
return _unityGradient.Evaluate((float)((value - Min) / (Max - Min)));
}
示例11: Start
// Use this for initialization
void Start()
{
ren = GetComponent<MeshRenderer>();
mat = ren.material;
initialPos = transform.position;
pillarGradient = new Gradient();
gck = pillarGradient.colorKeys;
gck[0].color = mat.color;
gck[0].time = 0.0f;
gck[1].color = hotColor;
gck[1].time = 1.0f;
gak = pillarGradient.alphaKeys;
gak[0].alpha = 1.0f;
gak[0].time = 0.0f;
gak[1].alpha = 1.0f;
gak[1].time = 1.0f;
pillarGradient.SetKeys(gck, gak);
}
示例12: GetGradient
public static Gradient GetGradient(string key)
{
Gradient gradient = null;
if( z_GradientSerializer.Deserialize(EditorPrefs.GetString(key), out gradient) )
return gradient;
Gradient g = new Gradient();
g.SetKeys(
new GradientColorKey[] {
new GradientColorKey(new Color(.1f, 0f, 1f, 1f), 0f),
new GradientColorKey(Color.black, 1f)
},
new GradientAlphaKey[] {
new GradientAlphaKey(1f, 0f),
new GradientAlphaKey(1f, 1f),
});
return g;
}
示例13: setGradient
void setGradient()
{
gradientKeys = new GradientColorKey[4];
gradientKeys [0].color = headColor_hsv;
gradientKeys [0].time = 0.0f;
gradientKeys [1].color = headASColor_hsv;
gradientKeys [1].time = 0.2f;
gradientKeys [2].color = bottomAScolor_hsv;
gradientKeys [2].time = 0.7f;
gradientKeys [3].color = bottomColor_hsv;
gradientKeys [3].time = 1.0f;
gradientAlpha = new GradientAlphaKey[4];
gradientAlpha [0].alpha = 1.0f;
gradientAlpha [1].alpha = 1.0f;
gradientAlpha [2].alpha = 1.0f;
gradientAlpha [3].alpha = 1.0f;
gradientAlpha[0].time = 0.0f;
gradientAlpha[1].time = 0.2f;
gradientAlpha[2].time = 0.7f;
gradientAlpha[3].time = 1.0f;
randomGradient = new Gradient();
randomGradient.SetKeys(gradientKeys,gradientAlpha);
gradientKeys = new GradientColorKey[4];
gradientKeys [0].color = bottomColor_hsv;
gradientKeys [0].time = 0.0f;
gradientKeys [1].color = bottomAScolor_hsv;
gradientKeys [1].time = 0.2f;
gradientKeys [2].color = headASColor_hsv;
gradientKeys [2].time = 0.7f;
gradientKeys [3].color = headColor_hsv;
gradientKeys [3].time = 1.0f;
randomGradient2 = new Gradient();
randomGradient2.SetKeys(gradientKeys,gradientAlpha);
}
示例14: OnInitialize
//.........这里部分代码省略.........
particleSystem.simulationSpace = childKSPParticleEmitter.pe.useWorldSpace
? ParticleSystemSimulationSpace.World
: ParticleSystemSimulationSpace.Local;
particleSystem.maxParticles = particleCountLimit;
particleSystemRenderer.material = childKSPParticleEmitter.pr.material;
// TODO Actually copy the mode from childKSPParticleEmitter.particleRenderMode?
particleSystemRenderer.renderMode = ParticleSystemRenderMode.Billboard;
try
{
childKSPParticleEmitter.particleRenderMode =
(ParticleRenderMode)Enum.Parse(typeof(ParticleRenderMode), renderMode);
}
catch (ArgumentException)
{
Print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleRenderMode");
}
switch (childKSPParticleEmitter.particleRenderMode)
{
case ParticleRenderMode.Billboard:
particleSystemRenderer.renderMode = ParticleSystemRenderMode.Billboard;
break;
case ParticleRenderMode.Stretch:
particleSystemRenderer.renderMode = ParticleSystemRenderMode.Stretch;
break;
case ParticleRenderMode.SortedBillboard:
particleSystemRenderer.renderMode = ParticleSystemRenderMode.Billboard;
particleSystemRenderer.sortMode = ParticleSystemSortMode.Distance;
break;
case ParticleRenderMode.HorizontalBillboard:
particleSystemRenderer.renderMode = ParticleSystemRenderMode.HorizontalBillboard;
break;
case ParticleRenderMode.VerticalBillboard:
particleSystemRenderer.renderMode = ParticleSystemRenderMode.VerticalBillboard;
break;
default:
particleSystemRenderer.renderMode = ParticleSystemRenderMode.Billboard;
break;
}
//particleSystemRenderer.alignment = ParticleSystemRenderSpace.View;
if (childKSPParticleEmitter.doesAnimateColor)
{
ParticleSystem.ColorOverLifetimeModule col = particleSystem.colorOverLifetime;
col.enabled = true;
GradientColorKey[] colorKeys = new GradientColorKey[5];
GradientAlphaKey[] alphaKeys = new GradientAlphaKey[5];
Color[] colors = childKSPParticleEmitter.colorAnimation;
float step = 1f / (colors.Length - 1);
for (int t = 0; t < colors.Length; t++)
{
colorKeys[t] = new GradientColorKey(colors[t], t * step);
alphaKeys[t] = new GradientAlphaKey(colors[t].a, t * step);
}
Gradient gradient = new Gradient();
gradient.SetKeys(colorKeys, alphaKeys);
col.color = new ParticleSystem.MinMaxGradient(gradient);
}
//try
//{
// particleSystemRenderer.renderMode =
// (ParticleSystemRenderMode)Enum.Parse(typeof (ParticleSystemRenderMode), renderMode);
//}
//catch (ArgumentException)
//{
// Print("ModelMultiParticleFXExt: " + renderMode + " is not a valid ParticleSystemRenderMode");
//}
persistentEmitters.Add(pkpe);
DisableCollider(pkpe.go);
emitterGameObject.transform.SetParent(transforms[i]);
emitterGameObject.transform.localPosition = localPosition;
emitterGameObject.transform.localRotation = Quaternion.Euler(localRotation);
emitterGameObject.SetLayerRecursive(layerId);
}
}
Destroy(model);
list.Add(this);
// 1.0 don't seems to properly do this for engines.
OnEvent(0);
}
示例15: GradientPresets
/// <summary>
/// Initializes a new instance of Gradient.
/// </summary>
static GradientPresets()
{
// Generic gradient alpha keys
var alphaKeys = new List<GradientAlphaKey> { new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1) };
// RGBA gradient alpha keys
var rgbaAlphaKeys = new List<GradientAlphaKey> { new GradientAlphaKey(0, 2 / 3f), new GradientAlphaKey(1, 1) };
// cloud alpha keys
var cloudAlphaKeys = new List<GradientAlphaKey> { new GradientAlphaKey(0, 0), new GradientAlphaKey(1, 1) };
// Grayscale gradient color keys
var grayscaleColorKeys = new List<GradientColorKey>
{
new GradientColorKey(Color.black, 0),
new GradientColorKey(Color.white, 1)
};
var cloudColorKeys = new List<GradientColorKey>
{
new GradientColorKey(new Color(1,1,1,0), 0f),
new GradientColorKey(new Color(1,1,1,0), 0.5f),
new GradientColorKey(new Color(1,1,1,0), 1f)
};
// RGB gradient color keys
var rgbColorKeys = new List<GradientColorKey>
{
new GradientColorKey(Color.red, 0),
new GradientColorKey(Color.green, 0.5f),
new GradientColorKey(Color.blue, 1)
};
// RGBA gradient color keys
var rgbaColorKeys = new List<GradientColorKey>
{
new GradientColorKey(Color.red, 0),
new GradientColorKey(Color.green, 1 / 3f),
new GradientColorKey(Color.blue, 2 / 3f),
new GradientColorKey(Color.black, 1)
};
var one = 1f / 255f;
// Terrain gradient color keys
var terrainColorKeys = new List<GradientColorKey>
{
new GradientColorKey(new Color(one * 13, one * 48, one * 76), 0), // deep ocean
new GradientColorKey(new Color(one * 28, one * 74, one * 107), 0.42f), // shallow water
new GradientColorKey(new Color(one * 169, one * 160, one * 124), 0.45f), // beach
new GradientColorKey(new Color(one * 92, one * 131, one * 57), 0.46f), // green land
new GradientColorKey(new Color(one * 125, one * 112, one * 88), 0.55f), // arid / desert
new GradientColorKey(new Color(one * 92, one * 131, one * 57), 0.60f), // green land
new GradientColorKey(new Color(one * 11, one * 40, one * 4), 0.94f), // forest
new GradientColorKey(new Color(one * 236, one * 240, one * 249), 1) // mountain peaks
};
_empty = new Gradient();
_rgb = new Gradient();
_rgb.SetKeys(rgbColorKeys.ToArray(), alphaKeys.ToArray());
_rgba = new Gradient();
_rgba.SetKeys(rgbaColorKeys.ToArray(), rgbaAlphaKeys.ToArray());
_grayscale = new Gradient();
_grayscale.SetKeys(grayscaleColorKeys.ToArray(), alphaKeys.ToArray());
_cloud = new Gradient();
_cloud.SetKeys(cloudColorKeys.ToArray(), cloudAlphaKeys.ToArray());
_terrain = new Gradient();
_terrain.SetKeys(terrainColorKeys.ToArray(), alphaKeys.ToArray());
}