zoukankan      html  css  js  c++  java
  • U3D中的又一个坑

     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动画导入前的处理,对动画集进行切分,转成单个的动画子集
    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         //错误写法
    22         //这里的clipAnimations是个属性,对它赋值时会调用它的set方法,该方法会检测数组的每个元素,有一个为NULL就报错,示例如下:
    23         modelImporter.clipAnimations = new ModelImporterClipAnimation[10]; //有10个元素的数组,每个都是NULL,运行时报错
    24 
    25         //正确写法
    26         //modelImporter.clipAnimations =操作一旦执行,对clipAnimations中的任何元素的更改都不再起作用,必须在此操作前执行更改
    27         modelImporter.clipAnimations = anims;
    28         for (var i = 0; i < modelImporter.clipAnimations.Length; ++i)
    29         {
    30             //anims[i].name更改了,但modelImporter.clipAnimations[i].name没更改,
    31             //虽然语法上它们仍指向同一变量,应该是内部特殊处理
    32             anims[i].name = "ani-" + i;
    33             anims[i].takeName = "ani-" + i;
    34         }
    35         
    36     }
    37 }
  • 相关阅读:
    java----session
    js封装成插件-------Canvas统计图插件编写
    js封装成插件
    js学习--变量作用域和作用域链
    学习js函数--自执行函数
    学习js函数--函数定义
    footer不满一屏时在最底部,超出一屏时在页面最下部
    ios 点击区域阴影问题
    提交表单后数据返回时间过长
    点击显示video
  • 原文地址:https://www.cnblogs.com/timeObjserver/p/8296679.html
Copyright © 2011-2022 走看看