Unity3D圣典3.3版本-中文版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
AnimationClip.SetCurve 设置曲线
# [AnimationClip](AnimationClip.html).SetCurve 设置曲线 function *SetCurve* (*relativePath* : string, *type* : Type, *propertyName* : string, *curve* : [AnimationCurve](../AnimationCurve/AnimationCurve.html)) : void ### Parameters**参数** * *relativePath* The 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 为空,表示动画剪辑附加的游戏物体。 * *type* The class type of the component that is animated 被动画的组件的类类型 * *propertyName* The name or path to the property being animated 被动画的属性的名字或路径 * *curve* The 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](../Transform/Transform.html) 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](../Material/Material.html) 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](../Material/Material.html) 材质属性可以动画,使用 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](AnimationClip.ClearCurves.html) 函数, [AnimationCurve](../AnimationCurve/AnimationCurve.html) 类. * [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) ```
da
2022年5月13日 22:12
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码