当前位置:网站首页>【unity编译器扩展之模型动画拷贝】
【unity编译器扩展之模型动画拷贝】
2022-08-05 00:02:00 【的成长之路】
首先得拿到要拷贝动画的模型,路径或者object
有一些类不熟悉的直接查官方API:unity官方API
关键类:AssetDatabase,AssetImporter
如果是UnityEngine.Object 类型的文件话,可以直接使用
AssetDatabase.GetAssetPath(Object):拿到文件路径(相对路径)
AssetDatabase.LoadAllAssetsAtPath(path):可以直接拿到文件身上的组件,例如FBX文件身上的AnimationClip等(相对路径)
AssetImporter.GetAtPath(Path):可以通过路径获取资源(相对路径),AssetImporter类下有多个子类,对于各种unity资源,可以转换
AnimatorController :动画状态机(动画控制器)
首先获得模型身上的动画
List<AnimationClip> tempAnim= new List<AnimationClip>;
UnityEngine.Object[] objs = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(fbx));
foreach(var item in objs){
if(item is AnimationClip){
tempAnim.Add(item);
}
}
拿到模型后去选择我们要拷贝的某个动画,我这就默认随便选择一个了,如果是选择多个,那么就同理就好
然后进行拷贝
拷贝需要拿到新拷贝的名字,和要拷贝的动画,还有就是模型的路径或者模型本身
static void CopyAnimationClip(UnityEngine.Object obj, string clipName, string newName)
{
string path = AssetDatabase.GetAssetPath(obj);
ModelImporter modelImporter = AssetImporter.GetAtPath(path) as ModelImporter;
if. (modelImporter.clipAnimations = null && modelImporter.clipAnimations.Length › 0)
{
ModelImporterClipAnimation[] clips = new ModelImporterClipAnimation(modelImporter.clipAnimations.Length+1];
modelImporter.clipAnimations.CopyTo(clips,0);
List<ModelImporterClipAnimation> clipList = new List<ModelImporterClipAnimation>(modelImporter.clipAnimations);
ModelImporterClipAnimation srcClip = clipList.Find( (× ) =› ( return x.name.Equals (clipName); });
ModelImporterClipAnimation newClip = new ModelImporterClipAnimation();
Type t = newClip.GetType();
foreach (var item Propertyinfo in srcClip.GetType().GetProperties())
{
if (item.GetSetMethod (false) == null)
continue;
if (item.GetValue(srcClip) == null)
continue;
t.GetProperty(item Name). SetValue ( newClip, item.GetValue(srcClip));
}
newClip.name = newName;
clips[clips. Length - 1] = newClip;
modelImporter.clipAnimations = clips;
AssetDatabase.ImportAsset(path);
AssetDatabase.Refresh();
}
}
代码纯手敲,有问题该巴该巴就好了
边栏推荐
- 4-《PyTorch深度学习实践》-反向传播
- 【Valentine's Day special effects】--Canvas realizes full screen love
- Day118.尚医通:订单列表、详情、支付
- SQL association table update
- STC89C52RC的P4口的应用问题
- The role of @Async annotation and how to implement asynchronous listening mechanism
- VMware NSX 4.0 -- 网络安全虚拟化平台
- Detailed explanation of common DNS resource record types
- 子连接中的参数传递
- MongoDB permission verification is turned on and mongoose database configuration
猜你喜欢
MAUI Blazor 权限经验分享 (定位,使用相机)
Nuclei (2) Advanced - In-depth understanding of workflows, Matchers and Extractors
【CVA估值训练营】财务建模指南——第一讲
Getting started with 3D modeling for games, what modeling software can I choose?
Develop a SpaceX website based on the Appian low-code platform
KT148A语音芯片ic工作原理以及芯片的内部架构描述
uniapp动态实现滑动导航效果demo(整理)
线程三连鞭之“线程的状态”
How to burn the KT148A voice chip into the chip through the serial port and the tools on the computer
2022牛客暑期多校训练营5(BCDFGHK)
随机推荐
隐私计算综述
uniapp horizontal tab (horizontal scrolling navigation bar) effect demo (organization)
Pytorch分布式训练/多卡/多GPU训练DDP的torch.distributed.launch和torchrun
网站最终产品页使用单一入口还是多入口?
MAUI Blazor 权限经验分享 (定位,使用相机)
IDEA file encoding modification
MAUI Blazor 权限经验分享 (定位,使用相机)
Cython
简单的顺序结构程序(C语言)
【数据挖掘概论】数据挖掘的简单描述
小黑leetcode冲浪:94. 二叉树的中序遍历
KT148A voice chip ic working principle and internal architecture description of the chip
Mysql based
没有这些「伪需求」,产品经理的 KPI 怎么完成?
Cython
Basic web in PLSQL
招标公告 | 海纳百创公众号运维项目
Detailed explanation of common DNS resource record types
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
Nuclei(二)进阶——深入理解workflows、Matchers和Extractors