本文整理汇总了C#中UnityEngine.AnimationCurve.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# AnimationCurve.Evaluate方法的具体用法?C# AnimationCurve.Evaluate怎么用?C# AnimationCurve.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.AnimationCurve
的用法示例。
在下文中一共展示了AnimationCurve.Evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StoneMove
IEnumerator StoneMove(AnimationCurve curve, float delay = 0 )
{
if (ismoving)
yield break;
ismoving = true;
float timer = 0;
Vector3 stoneOriPosition = stone.transform.position;
Vector3 shadowOriPosition = shadow.transform.position;
while(true)
{
if (timer > delay)
{
stone.transform.position = stoneOriPosition + new Vector3(0,curve.Evaluate((timer-delay)/(glowTime + glowDuration)),0);
shadow.transform.position = shadowOriPosition - new Vector3(0,curve.Evaluate((timer-delay)/(glowTime + glowDuration)),0);
}
if (timer > glowTime + glowDuration + delay)
break;
timer += Time.deltaTime;
yield return null;
}
ismoving = false;
yield break;
}
示例2: evaluateProbabilityCurve
public static float evaluateProbabilityCurve(AnimationCurve curve, int sliceCount)
{
/*
allows you to use animationCurves as probability curves.
uses domain 0-1
any range
slices the domain into sliceCount pieces. the odds of returning the x value from a slice
is linearly proportional to the y value on the curve
*/
float total = 0;
float stepSize = 1 / (float)sliceCount;
for (float x=0; x<=1; x+=stepSize) {
total += curve.Evaluate (x);
}
float rand = ((float)Random.Range (0, total * 1000)) / 1000;
for (float x=0; x<=1; x+=stepSize) {
float y = curve.Evaluate (x);
if (y > 0)
rand -= y;
if (rand < 0)
return x;
}
Debug.Log ("warning: evaluateProbabilityCurve never evaluated. returning 1");
return 1f;
}
示例3: GetSamplePoints
Vector2[] GetSamplePoints(AnimationCurve curve, Vector2 offset) {
if (curve.length == 0) {
return new Vector2[] { offset, offset };
}
else {
var ret = new List<Vector2>();
float maxTime = GetMaxTime(curve);
for (var t = 0f; t < maxTime; t += sampleInterval) {
ret.Add(new Vector2(t, curve.Evaluate(t)) + offset);
}
ret.Add(new Vector2(maxTime, curve.Evaluate(maxTime)) + offset);
return ret.ToArray();
}
}
示例4: GenerateTerrainMesh
public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail) {
AnimationCurve heightCurve = new AnimationCurve (_heightCurve.keys);
int width = heightMap.GetLength (0);
int height = heightMap.GetLength (1);
float topLeftX = (width - 1) / -2f;
float topLeftZ = (height - 1) / 2f;
int meshSimplificationIncrement = (levelOfDetail == 0)?1:levelOfDetail * 2;
int verticesPerLine = (width - 1) / meshSimplificationIncrement + 1;
MeshData meshData = new MeshData (verticesPerLine, verticesPerLine);
int vertexIndex = 0;
for (int y = 0; y < height; y += meshSimplificationIncrement) {
for (int x = 0; x < width; x += meshSimplificationIncrement) {
meshData.vertices [vertexIndex] = new Vector3 (topLeftX + x, heightCurve.Evaluate (heightMap [x, y]) * heightMultiplier, topLeftZ - y);
meshData.uvs [vertexIndex] = new Vector2 (x / (float)width, y / (float)height);
if (x < width - 1 && y < height - 1) {
meshData.AddTriangle (vertexIndex, vertexIndex + verticesPerLine + 1, vertexIndex + verticesPerLine);
meshData.AddTriangle (vertexIndex + verticesPerLine + 1, vertexIndex, vertexIndex + 1);
}
vertexIndex++;
}
}
return meshData;
}
示例5: GenerateTerrainMesh
public static MeshData GenerateTerrainMesh(float[,] heightMap, float heightMultiplier, AnimationCurve _heightCurve, int levelOfDetail) {
AnimationCurve heightCurve = new AnimationCurve (_heightCurve.keys);
int meshSimplificationIncrement = (levelOfDetail == 0)?1:levelOfDetail * 2;
int borderedSize = heightMap.GetLength (0);
int meshSize = borderedSize - 2*meshSimplificationIncrement;
int meshSizeUnsimplified = borderedSize - 2;
float topLeftX = (meshSizeUnsimplified - 1) / -2f;
float topLeftZ = (meshSizeUnsimplified - 1) / 2f;
int verticesPerLine = (meshSize - 1) / meshSimplificationIncrement + 1;
MeshData meshData = new MeshData (verticesPerLine);
int[,] vertexIndicesMap = new int[borderedSize,borderedSize];
int meshVertexIndex = 0;
int borderVertexIndex = -1;
for (int y = 0; y < borderedSize; y += meshSimplificationIncrement) {
for (int x = 0; x < borderedSize; x += meshSimplificationIncrement) {
bool isBorderVertex = y == 0 || y == borderedSize - 1 || x == 0 || x == borderedSize - 1;
if (isBorderVertex) {
vertexIndicesMap [x, y] = borderVertexIndex;
borderVertexIndex--;
} else {
vertexIndicesMap [x, y] = meshVertexIndex;
meshVertexIndex++;
}
}
}
for (int y = 0; y < borderedSize; y += meshSimplificationIncrement) {
for (int x = 0; x < borderedSize; x += meshSimplificationIncrement) {
int vertexIndex = vertexIndicesMap [x, y];
Vector2 percent = new Vector2 ((x-meshSimplificationIncrement) / (float)meshSize, (y-meshSimplificationIncrement) / (float)meshSize);
float height = heightCurve.Evaluate (heightMap [x, y]) * heightMultiplier;
Vector3 vertexPosition = new Vector3 (topLeftX + percent.x * meshSizeUnsimplified, height, topLeftZ - percent.y * meshSizeUnsimplified);
meshData.AddVertex (vertexPosition, percent, vertexIndex);
if (x < borderedSize - 1 && y < borderedSize - 1) {
int a = vertexIndicesMap [x, y];
int b = vertexIndicesMap [x + meshSimplificationIncrement, y];
int c = vertexIndicesMap [x, y + meshSimplificationIncrement];
int d = vertexIndicesMap [x + meshSimplificationIncrement, y + meshSimplificationIncrement];
meshData.AddTriangle (a,d,c);
meshData.AddTriangle (d,a,b);
}
vertexIndex++;
}
}
return meshData;
}
示例6: GenerateProfileShape
/// <summary>
/// Helper function to generate the profile shape to be extruded according to the given curve and parameters.
/// </summary>
/// <param name="profile"></param>
/// <param name="numDivsProfile"></param>
/// <param name="width"></param>
/// <param name="verticalScale"></param>
/// <param name="profileShape"></param>
public static void GenerateProfileShape(AnimationCurve profile, int numDivsProfile, float width, float verticalScale, Shape profileShape, bool collider = false)
{
Vector2[] points = new Vector2[numDivsProfile + 1];
float[] uCoords = new float[numDivsProfile + 1];
Vector2[] normals = new Vector2[numDivsProfile + 1];
for(int i = 0; i < numDivsProfile + 1; ++i)
{
points[i].x = (float)i * (width / numDivsProfile);
points[i].y = -profile.Evaluate(1.0f - Mathf.InverseLerp(0.0f, width, points[i].x)) * verticalScale;
normals[i].x = 0.0f;
normals[i].y = 1.0f;
uCoords[i] = Mathf.InverseLerp(0.0f, width, points[i].x);
points[i].x -= width * 0.5f;
}
int[] lines = new int[points.Length * 2 - 2];
int k = 0;
for (int i = 0; i < points.Length - 1; i++)
{
lines[k] = i;
lines[k + 1] = i + 1;
k += 2;
}
profileShape.points = points;
profileShape.normals = normals;
profileShape.uCoords = uCoords;
profileShape.lines = lines;
}
示例7: Start
void Start()
{
_texture = new Texture2D(Width, Height, TextureFormat.ARGB32, false);
_texture.Apply(false, false);
if (_movieCapture)
{
_movieCapture.SetSourceTexture(_texture);
}
_pixels = new Color32[Width*Height];
_palette = new Color32[PaletteSize];
Keyframe[] keysR = { new Keyframe(0f, 0f), new Keyframe(0.25f, 1f), new Keyframe(1f, 0f) };
Keyframe[] keysG = { new Keyframe(0f, 1f), new Keyframe(0.5f, 0f), new Keyframe(1f, 1f) };
Keyframe[] keysB = { new Keyframe(0f, 1f), new Keyframe(0.75f, 0f), new Keyframe(1f, 0f) };
AnimationCurve curveR = new AnimationCurve(keysR);
AnimationCurve curveG = new AnimationCurve(keysG);
AnimationCurve curveB = new AnimationCurve(keysB);
for (int i = 0; i < PaletteSize; i++)
{
float r = curveR.Evaluate((float)i / (float)PaletteSize);
float g = curveG.Evaluate((float)i / (float)PaletteSize);
float b = curveB.Evaluate((float)i / (float)PaletteSize);
_palette[i] = new Color32((byte)(r * 255.0f), (byte)(g * 255.0f), (byte)(b * 255.0f), (byte)(b * 255.0f));
}
}
示例8: CurveDissolve
public static IEnumerator CurveDissolve(Material mat, AnimationCurve dissolveCurve, float time, float curveStartPercentage, float speed)
{
float elapsedTime = curveStartPercentage;
while (elapsedTime <= 1f && elapsedTime >= 0f) {
if (mat.HasProperty(dissolveAmountID)) {
mat.SetFloat(dissolveAmountID, Mathf.Clamp01(dissolveCurve.Evaluate(elapsedTime)));
}
elapsedTime += Time.deltaTime/time * speed;
yield return null;
}
if (mat.HasProperty(dissolveAmountID)) {
mat.SetFloat(dissolveAmountID, Mathf.Clamp01(dissolveCurve.Evaluate(Mathf.Clamp01(elapsedTime))));
}
}
示例9: GetValueFromCurveAtPosition
public float GetValueFromCurveAtPosition(AnimationCurve curve, float xPosition)
{
float xPos = xPosition + seed;
xPos = xPos % curve[curve.length - 1].time;
var result = curve.Evaluate(xPos);
result += Random.Range(-worldJitterAmount, worldJitterAmount);
result = Mathf.Clamp01(result);
return result;
}
示例10: DoAnimate
private IEnumerator DoAnimate(AnimationCurve curve)
{
var renderer = GetComponent<SpriteRenderer>();
var duration = curve[curve.length - 1].time;
for (var t = 0f; t <= duration; t += Mathf.Max(0.001f, Time.deltaTime)) {
renderer.color = renderer.color.WithA(curve.Evaluate(t));
yield return null;
}
}
示例11: DoAnimate
private IEnumerator DoAnimate(AnimationCurve curve)
{
var image = GetComponentInChildren<Image>();
var duration = curve[curve.length - 1].time;
for (var t = 0f; t <= duration; t += Mathf.Max(0.001f, Time.deltaTime)) {
image.color = image.color.WithA(curve.Evaluate(t));
yield return null;
}
}
示例12: Interpolate
public static PositionRotation Interpolate(PositionRotation start, PositionRotation end, float progress, AnimationCurve curve)
{
var diff = (end.Position - start.Position);
var curveProgress = curve.Evaluate(progress);
var pos = new Vector3(
start.Position.x + diff.x * curveProgress,
start.Position.y + diff.y * curveProgress,
start.Position.z + diff.z * curveProgress
);
var rot = Quaternion.RotateTowards(start.Rotation, end.Rotation, Quaternion.Angle(start.Rotation, end.Rotation) * curveProgress);
return new PositionRotation(pos, rot);
}
示例13: Move
IEnumerator Move(Vector3 pos1, Vector3 pos2, AnimationCurve ac, float time) {
float timer = 0.0f;
pos2 += Random.insideUnitSphere * scatter;
while (timer <= time) {
transform.position = Vector3.Lerp (pos1, pos2, ac.Evaluate(timer/time));
timer += Time.deltaTime;
yield return null;
}
}
示例14: _Coro_FlyProcess
IEnumerator _Coro_FlyProcess(AnimationCurve scaleCurve, float useTime, Vector3 flyLocalDirect)
{
float curTime = 0F;
while (curTime < useTime)
{
transform.localPosition += flyLocalDirect * FlySpeed * Time.deltaTime;
curTime += Time.deltaTime;
float scale = scaleCurve.Evaluate(curTime / useTime);
transform.localScale = new Vector3(scale, scale, 1F);
yield return 0;
}
}
示例15: ConvertAlphaTexture
public static Color[] ConvertAlphaTexture(Color[] srcColors, bool bEnableAlphaChannel, AnimationCurve curveAlphaWeight, float redWeight, float greenWeight, float blueWeight)
{
for (int c = 0; c < srcColors.Length; c++)
{
if (bEnableAlphaChannel)
{
if (curveAlphaWeight != null)
srcColors[c].a = curveAlphaWeight.Evaluate(srcColors[c].grayscale);
else srcColors[c].a = srcColors[c].grayscale;
} else srcColors[c].a = 1;
}
return srcColors;
}