AnimationClip.SetCurve 设置曲线

function SetCurve (relativePath : string, type : Type, propertyName : string, curve : AnimationCurve) : void

Parameters参数

Description描述

Assigns the curve to animate a specific property.

给动画指定曲线一个特殊的属性。

If curve is null the curve will be removed. If a curve already exists for that property, it will be replaced.

如果曲线为null,曲线将被移除,如果曲线属性已经存在,曲线将被替换。

通常的名称是: "localPosition.x", "localPosition.y", "localPosition.z", "localRotation.x", "localRotation.y", "localRotation.z", "localRotation.w" "localScale.x", "localScale.y", "localScale.z".

For performance reasons Transform position, rotation and scale can only be animated as one property.

出于性能原因,Transform的position, rotation和scale 只能被动画作为一个属性。

using UnityEngine;

using System.Collections;



public class example : MonoBehaviour {

	void Start() {

		AnimationCurve curve = AnimationCurve.Linear(0, 1, 2, 3);

		AnimationClip clip = new AnimationClip();

		clip.SetCurve("", typeof(Transform), "localPosition.x", curve);

		animation.AddClip(clip, "test");

		animation.Play("test");

	}

}
// Animates the x coordinate of a transform position

//动画transform位置的x轴坐标



function Start () {

	// Create the curve

	//创建曲线

	var curve : AnimationCurve = AnimationCurve.Linear(0, 1, 2, 3);



	// Create the clip with the curve

	//创建曲线的剪辑

	var clip : AnimationClip = new AnimationClip();

	clip.SetCurve("", Transform, "localPosition.x", curve);



	// Add and play the clip

	//点击并播放剪辑

	animation.AddClip(clip, "test");

	animation.Play("test");

}

@script RequireComponent(Animation)

Material材质属性可以使用shader导出的属性名称制作动画。通常使用的名称是: "_MainTex", "_BumpMap", "_Color", "_SpecColor", "_Emission"。如何动画化不同材质属性类型:

        Float属性: "PropertyName"  		

        Vector4 属性: "PropertyName.x", "PropertyName.y", "PropertyName.z", "PropertyName.w"

        Color 属性: "PropertyName.r", "PropertyName.g", "PropertyName.b", "PropertyName.a"

        UV 旋转属性:"PropertyName.rotation"

        UV 偏移和缩放: "PropertyName.offset.x", "PropertyName.offset.y", "PropertyName.scale.x", "PropertyName.scale.y"

        对于在同一renderer的多个索引材质,你能想这样添加前缀:"[1]._MainTex.offset.y"

  

另见: ClearCurves 函数, AnimationCurve 类.

using UnityEngine;

using System.Collections;



public class example : MonoBehaviour {

	void Start() {

		AnimationClip clip = new AnimationClip();

		clip.SetCurve("", typeof(Material), "_Color.a", new AnimationCurve(new Keyframe(0, 0, 0, 0), new Keyframe(1, 1, 0, 0)));

		clip.SetCurve("", typeof(Material), "_MainTex.offset.x", AnimationCurve.Linear(0, 1, 2, 3));

		animation.AddClip(clip, clip.name);

		animation.Play(clip.name);

	}

}
// Animate color's alpha and main texture's horizontal offset.

//动画颜色的通道和主要纹理的水平偏移

function Start () {

	var clip = new AnimationClip ();

	clip.SetCurve ("", Material, "_Color.a",	AnimationCurve (Keyframe(0, 0, 0, 0), Keyframe(1, 1, 0, 0)));	

	clip.SetCurve ("", Material, "_MainTex.offset.x",	AnimationCurve.Linear(0, 1, 2, 3));

	animation.AddClip (clip, clip.name);

	animation.Play(clip.name);

}

@script RequireComponent(Animation) 
Page last updated: 2012-4-21
http://s96.cnzz.com/stat.php?id=4924487&web_id=4924487">