U3D中的又一个坑
U3D中的又一個(gè)坑
1 using System.Collections; 2 using System.Collections.Generic; 3 using UnityEditor; 4 using UnityEngine; 5 6 public class animImport : AssetPostprocessor 7 { 8 9 //fbx動(dòng)畫導(dǎo)入前的處理,對(duì)動(dòng)畫集進(jìn)行切分,轉(zhuǎn)成單個(gè)的動(dòng)畫子集 10 void OnPreprocessAnimation() 11 { 12 var modelImporter = assetImporter as ModelImporter; 13 var anims = new ModelImporterClipAnimation[10]; 14 for (var i = 0; i < anims.Length; ++i) 15 { 16 anims[i] = new ModelImporterClipAnimation(); 17 anims[i].takeName = "hello-" + i; 18 anims[i].name = "hello-" + i; 19 } 20 21 //錯(cuò)誤寫法 22 //這里的clipAnimations是個(gè)屬性,對(duì)它賦值時(shí)會(huì)調(diào)用它的set方法,該方法會(huì)檢測(cè)數(shù)組的每個(gè)元素,有一個(gè)為NULL就報(bào)錯(cuò),示例如下: 23 modelImporter.clipAnimations = new ModelImporterClipAnimation[10]; //有10個(gè)元素的數(shù)組,每個(gè)都是NULL,運(yùn)行時(shí)報(bào)錯(cuò) 24 25 //正確寫法 26 //modelImporter.clipAnimations =操作一旦執(zhí)行,對(duì)clipAnimations中的任何元素的更改都不再起作用,必須在此操作前執(zhí)行更改 27 modelImporter.clipAnimations = anims; 28 for (var i = 0; i < modelImporter.clipAnimations.Length; ++i) 29 { 30 //anims[i].name更改了,但modelImporter.clipAnimations[i].name沒更改, 31 //雖然語(yǔ)法上它們?nèi)灾赶蛲蛔兞?#xff0c;應(yīng)該是內(nèi)部特殊處理 32 anims[i].name = "ani-" + i; 33 anims[i].takeName = "ani-" + i; 34 } 35 36 } 37 }?
posted on 2018-01-16 14:58 時(shí)空觀察者9號(hào) 閱讀(...) 評(píng)論(...) 編輯 收藏
總結(jié)
- 上一篇: MaxScript 学习笔记【有转载】
- 下一篇: C#与U3D中字符串尾0