国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Unity的AnimationCurve

2019-11-09 17:34:29
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

轉(zhuǎn)自:風(fēng)宇沖Unity3D教程學(xué)院http://blog.sina.com.cn/s/blog_471132920101f8nv.html,本文有多處增刪減改,詳細(xì)內(nèi)容請(qǐng)查看原文。

1.介紹 AnimationCurve是Unity3D里一個(gè)非常實(shí)用的功能。作用是編輯一條任意變化的曲線用在任何你想用在的地方。 如曲線地形,曲線軌跡等。也被用在了模型動(dòng)畫(huà)播放時(shí)的碰撞盒縮放及重力調(diào)節(jié)。AnimationCurve 曲線的繪制方法和Ragespline中的物體輪廓勾勒的方法類似。

2.基本使用 物體腳本上添加變量: public AnimationCurve anim;

會(huì)得到: 這里寫(xiě)圖片描述

點(diǎn)擊區(qū)域進(jìn)入曲線編輯界面: 這里寫(xiě)圖片描述

雙擊任意區(qū)域內(nèi)地方,創(chuàng)建關(guān)鍵點(diǎn)。對(duì)關(guān)鍵點(diǎn)點(diǎn)鼠標(biāo)郵件,則出如下界面: 這里寫(xiě)圖片描述

基本操作: 創(chuàng)建關(guān)鍵點(diǎn):左鍵雙擊 刪除關(guān)鍵點(diǎn): (1)鼠標(biāo)移動(dòng)至關(guān)鍵點(diǎn)上,右鍵->Delete Key。 (2)左鍵單擊關(guān)鍵點(diǎn),然后按鍵盤(pán)上的delete

設(shè)置曲線類型:鼠標(biāo)移動(dòng)至關(guān)鍵點(diǎn)上,右鍵-> Auto:根據(jù)關(guān)鍵點(diǎn)自動(dòng)設(shè)置曲線。 Free Smooth:統(tǒng)一設(shè)置入切線和出切線 Flat:入切線和出切線為水平 Broken:分別設(shè)置入切線和出切線

也可以選Left Tangent(入切線)或者Right Tangent(出切線)或者Both Tangents(兩切線)。 Free:自由曲線,與Broken效果基本一樣。 Linear:線性曲線 Constant:之前一直是上個(gè)點(diǎn)的值,然后瞬間變?yōu)檫@個(gè)點(diǎn)的值。

其中Auto最簡(jiǎn)單,Broken調(diào)整空間最大。曲線效果以綠線為準(zhǔn)。

編輯好一條曲線后,在曲線的左右兩端會(huì)有一個(gè)下拉菜單,點(diǎn)擊設(shè)置兩端各自重復(fù)的方式。 Loop:曲線循環(huán) 這里寫(xiě)圖片描述

Pingpong: 曲線和該曲線上下翻轉(zhuǎn)后的曲線循環(huán) 這里寫(xiě)圖片描述

Clamp:一直為端點(diǎn)的值。 這里寫(xiě)圖片描述

使用曲線: 在上面的腳本里,再添加幾行代碼,如下

using UnityEngine;using System.Collections;public class AnimationCurveTutor : MonoBehaviour {public AnimationCurve anim;public void Update(){transform.position = new Vector3(Time.time, anim.Evaluate(Time.time), 0);}}

運(yùn)行后,物體會(huì)按曲線軌跡向右移動(dòng)。

3.腳本創(chuàng)建AnimationCurve AnimationCurve可以理解為2部分。(1)鍵序列(2)左右循環(huán)模式(又作左右包裹模式)

一:鍵序列 創(chuàng)建鍵序列:Keyframe[] ks = new Keyframe[3]; 曲線中加入鍵序列:AnimationCurve curve = new AnimationCurve(ks); 獲取曲線中的鍵序列:curve[index] 或者 curve.keys[index] 添加單鍵:curve.Addkey(time,value) 刪除單鍵:curve.RemoveKey(index)

二:左右循環(huán) anim.PReWrapMode = WrapMode.Loop; anim.postWrapMode = WrapMode.Once;

三:鍵 Keyframe kf = new Keyframe(time,value); kf.inTangent = 45; kf.outTangent = 45;

用腳本動(dòng)態(tài)實(shí)時(shí)創(chuàng)建AnimationCurve。創(chuàng)建如下腳本,拖到任意物體運(yùn)行即可。

using UnityEngine;using System.Collections;public class CreateRuntime : MonoBehaviour { public AnimationCurve anim = new AnimationCurve(); void Start() { Keyframe[] ks = new Keyframe[3]; ks[0] = new Keyframe(0, 0); ks[0].inTangent = 0; ks[1] = new Keyframe(4, 0); ks[1].inTangent = 45; ks[2] = new Keyframe(8, 0); ks[2].inTangent = 90; anim = new AnimationCurve(ks); } void Update() { transform.position = new Vector3(Time.time, anim.Evaluate(Time.time), 0); }}

4.一些函數(shù): 1/ public float Evaluate(float time) 獲取當(dāng)前time位置對(duì)應(yīng)曲線上的value

2/ public int AddKey(Keyframe key) public int AddKey(float time, float value); 添加一個(gè)關(guān)鍵幀

3/ public int MoveKey(int index, Keyframe key) 移動(dòng)一個(gè)關(guān)鍵幀到指定index處

4/ public void RemoveKey(int index); 移除一個(gè)關(guān)鍵幀

5/ public void SmoothTangents(int index, float weight); //平滑化指定索引的關(guān)鍵幀的in和out tangents,weight:The smoothing weight to apply to the keyframe’s tangents.


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 清涧县| 永靖县| 石阡县| 临泽县| 贡觉县| 木兰县| 铁力市| 修文县| 寻甸| 镇雄县| 惠来县| 潼关县| 沙河市| 宁河县| 阿尔山市| 府谷县| 乐都县| 涟水县| 濮阳市| 九寨沟县| 自贡市| 个旧市| 鹤壁市| 五指山市| 清远市| 峡江县| 永德县| 兰西县| 兰坪| 沈阳市| 金阳县| 阳山县| 麻栗坡县| 冷水江市| 成安县| 盐山县| 盱眙县| 樟树市| 红原县| 左权县| 巴东县|