当前位置:网站首页>【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();
}
}
代码纯手敲,有问题该巴该巴就好了
边栏推荐
- 【七夕快乐篇】Nacos是如何实现服务注册功能的?
- 2022牛客暑期多校训练营5(BCDFGHK)
- 《MySQL入门很轻松》第2章:MySQL管理工具介绍
- [LeetCode] Summary of Matrix Simulation Related Topics
- Xiaohei's leetcode journey: 95. Longest substring with at least K repeating characters
- 元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?
- uniapp动态实现滑动导航效果demo(整理)
- NebulaGraph v3.2.0 Release Note,对查询最短路径的性能等多处优化
- uniapp 分享功能-分享给朋友群聊朋友圈效果(整理)
- 【SSR服务端渲染+CSR客户端渲染+post请求+get请求+总结】
猜你喜欢
情人节---快来学习一下程序员的专属浪漫吧
怎么将自己新文章自动推送给自己的粉丝(巨简单,学不会来打我)
在线中文姓名生成工具推荐
【LeetCode】矩阵模拟相关题目汇总
【CVA估值训练营】财务建模指南——第一讲
KT6368A蓝牙的认证问题_FCC和BQB_CE_KC认证或者其它说明
uniapp horizontal tab (horizontal scrolling navigation bar) effect demo (organization)
uniapp横向选项卡(水平滚动导航栏)效果demo(整理)
性能测试如何准备测试数据
小黑leetcode之旅:95. 至少有 K 个重复字符的最长子串
随机推荐
MAUI Blazor 权限经验分享 (定位,使用相机)
uniapp sharing function - share to friends group chat circle of friends effect (sorting)
数据类型及输入输出初探(C语言)
node中package解析、npm 命令行npm详解,node中的common模块化,npm、nrm两种方式查看源和切换镜像
对写作的一些感悟
Mysql based
工业物联网 —— 新型数据库的召唤
情人节---快来学习一下程序员的专属浪漫吧
Senior game modelers tell newbies, what are the necessary software for game scene modelers?
KT6368A蓝牙的认证问题_FCC和BQB_CE_KC认证或者其它说明
uinty lua 关于异步函数的终极思想
SQL association table update
Uniapp dynamic sliding navigation effect demo (finishing)
MongoDB权限验证开启与mongoose数据库配置
[CVA Valuation Training Camp] Financial Modeling Guide - Lecture 1
Privacy Computing Overview
After another 3 days, I have sorted out 90 NumPy examples, and I can't help but bookmark it!
LeetCode Hot 100
元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?
typeScript - Partially apply a function