当前位置:网站首页>【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();
}
}
代码纯手敲,有问题该巴该巴就好了
边栏推荐
- 元宇宙:未来我们的每一个日常行为是否都能成为赚钱工具?
- 矩阵数学原理
- ARC129E Yet Another Minimization 题解 【网络流笔记】
- 三、实战---爬取百度指定词条所对应的结果页面(一个简单的页面采集器)
- 从单体架构迁移到 CQRS 后,我觉得 DDD 并不可怕
- 3. Actual combat---crawl the result page corresponding to Baidu's specified entry (a simple page collector)
- 在线中文姓名生成工具推荐
- 小黑leetcode之旅:95. 至少有 K 个重复字符的最长子串
- 2022 Niu Ke Summer Multi-School Training Camp 5 (BCDFGHK)
- Mathematical Principles of Matrix
猜你喜欢

uniapp sharing function - share to friends group chat circle of friends effect (sorting)

KT148A voice chip ic working principle and internal architecture description of the chip

Huggingface入门篇 II (QA)

Ab3d.PowerToys and Ab3d.DXEngine Crack

仿网易云音乐小程序-uniapp

从单体架构迁移到 CQRS 后,我觉得 DDD 并不可怕
![[Happy Qixi Festival] How does Nacos realize the service registration function?](/img/df/5793145da45bc80d227b0babfac914.png)
[Happy Qixi Festival] How does Nacos realize the service registration function?

入门3D游戏建模师知识必备

Xiaohei leetcode surfing: 94. Inorder traversal of binary tree

数据类型-整型(C语言)
随机推荐
10 个关于 Promise 和 setTimeout 知识的面试题,通过图解一次说透彻
The role of @ Import annotations as well as how to use
小黑leetcode冲浪:94. 二叉树的中序遍历
typeScript - Partially apply a function
2022年华数杯数学建模
golang 协程的实现原理
没有这些「伪需求」,产品经理的 KPI 怎么完成?
Nuclei(二)进阶——深入理解workflows、Matchers和Extractors
《MySQL入门很轻松》第2章:MySQL管理工具介绍
The applicable scenarios and common product types of the KT148A electronic voice chip ic solution
mysql基础
三大技巧让你成功入门3D建模,零基础小白必看
在线中文姓名生成工具推荐
Xiaohei leetcode surfing: 94. Inorder traversal of binary tree
Cython
Xiaohei's leetcode journey: 95. Longest substring with at least K repeating characters
Privacy Computing Overview
Flask框架 根据源码分析可扩展点
软件开发工具的技术要素
头脑风暴:完全背包