返回介绍

AnimationClip.SetCurve 设置曲线

发布于 2019-12-18 15:37:11 字数 7263 浏览 1265 评论 0 收藏 0

JavaScript => public function SetCurve(relativePath: string, type: Type, propertyName: string, curve: AnimationCurve): void;
C# => public void SetCurve(string relativePath, Type type, string propertyName, AnimationCurve curve);

Parameters 参数

relativePathPath to the game object this curve applies to. relativePath is formatted similar to a pathname, e.g. “rootrelativePathleftArm”. 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”.

JavaScript:

var anim: Animation;
 
function Start() {
	anim = GetComponent.<Animation>();
 
	// Animates the x coordinate of a transform position.
	// Create the curve.
	var curve : AnimationCurve = AnimationCurve.Linear(0, 1, 2, 3);
 
	// Create the clip with the curve.
	var clip : AnimationClip = new AnimationClip();
	clip.legacy = true;
	clip.SetCurve("", Transform, "localPosition.x", curve);
 
	// Add and play the clip
	anim.AddClip(clip, "test");
	anim.Play("test");
}
@script RequireComponent(Animation)

C#:

using UnityEngine;
using System.Collections;
 
[RequireComponent(typeof(Animation))]
public class ExampleClass : MonoBehaviour {
    public Animation anim;
    void Start() {
        anim = GetComponent<Animation>();
        AnimationCurve curve = AnimationCurve.Linear(0, 1, 2, 3);
        AnimationClip clip = new AnimationClip();
        clip.legacy = true;
        clip.SetCurve("", typeof(Transform), "localPosition.x", curve);
        anim.AddClip(clip, "test");
        anim.Play("test");
    }
}

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”

See Also: ClearCurves function, AnimationCurve class.

JavaScript:

var anim: Animation;
 
function Start() {
	anim = GetComponent.<Animation>();
 
	// Animate color's alpha and main texture's horizontal offset.
	var clip = new AnimationClip ();
	clip.legacy = true;
	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));
	anim.AddClip (clip, clip.name);
	anim.Play(clip.name);
}
@script RequireComponent(Animation)

C#:

using UnityEngine;
using System.Collections;
 
[RequireComponent(typeof(Animation))]
public class ExampleClass : MonoBehaviour {
    public Animation anim;
    void Start() {
        anim = GetComponent<Animation>();
        AnimationClip clip = new AnimationClip();
        clip.legacy = true;
        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));
        anim.AddClip(clip, clip.name);
        anim.Play(clip.name);
    }
}

Property names can be looked up by setting Asset Serialization to Force Text mode in the Editor settings. The text files that are then written by the editor will include the names of the properties. For example, the yaml file written for a Scene object will include the Camera settings. Looking at this yaml file will show:

属性名可以通过设置资源序列化,可以在编辑器中设置强制文本模式进行查找。该文本文件由编辑器写入,将包含属性名。例如,yaml文件写入的场景对象将包含相机设置。看下面的yaml文件。

m_BackGroundColor: {r: .192156866, g: .301960796, b: .474509805, a: .0196078438}
m_NormalizedViewPortRect:
serializedVersion: 2
x: 0
y: 0
width: 1
height: 1
near clip plane: .300000012
far clip plane: 1000
field of view: 60
orthographic: 0
orthographic size: 5
m_Depth: -1

This shows that the name for the FOV parameter is “field of view”. If you wanted to create an animation clip to animate the camera field of view, you would pass “field of view” as the propertyName.

这个显示FOV参数的名为field of view。如果你想要创建一个动画剪辑来动画相机的field of view,你应该传递field of view作为参数。

AnimationClip

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文