AnimationClip.SetCurve 设置曲线
function SetCurve (relativePath : string, type : Type, propertyName : string, curve : AnimationCurve) : void
Parameters参数
- relativePathThe path to the game object this curve applies to. relativePath is formatted similar to a pathname, e.g. "root/spine/leftArm". If relativePath is empty it refers to the game object the animation clip is attached to.
应用给该曲线的游戏物体的路径。relativePath被格式化类似路径,如"root/spine/leftArm"。如果relativePath为空,表示动画剪辑附加的游戏物体。 - typeThe class type of the component that is animated
被动画的组件的类类型 - propertyNameThe name or path to the property being animated
被动画的属性的名字或路径 - curveThe animation curve //动画曲线
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 只能被动画作为一个属性。
C#
JavaScript
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 properties can be animated using the property name exported in the shader. Common property names are: "_MainTex", "_BumpMap", "_Color", "_SpecColor", "_Emission". How to animate different material property types:
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 类.
C#
JavaScript
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)