制作unity小工具 获取FBX模型里面的AnimationClip片段
来源:互联网 发布:燕十八php教程2016 编辑:程序博客网 时间:2024/05/17 09:38
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
public class AnimatorTools : EditorWindow
{
[MenuItem("AnimatorTools/复制AnimationClip")]
static void CopyClip()
{
//测试被选择物体的路径:Assets/Art/Model/Character/hero3009/hero3009@attack.FBX
string selectPath = AssetDatabase.GetAssetPath (Selection.activeObject);
Debug.Log ("测试被选择物体的路径:"+selectPath);
string[] str = selectPath.Split ("/"[0]);
//得到的路径:Assets/Art/Model/Character/hero3009/
string _folderAssetPath = selectPath.Substring (0,selectPath.Length-str[str.Length-1].Length);
Debug.Log ("得到的路径:"+_folderAssetPath);
//获取文件夹底下所有文件路径
string projectDataPath = Application.dataPath.Substring (0,Application.dataPath.Length-6);
string[] allFilePath = Directory.GetFiles (projectDataPath+_folderAssetPath,"*",SearchOption.TopDirectoryOnly);
List<string> allAniPath = new List<string> ();
//做个循环让以.FBX结尾的文件放进List中
for (int i = 0; i < allFilePath.Length; i++)
{
string remove = projectDataPath;
string newPath = allFilePath [i].Remove (0,remove.Length);
if(newPath.Substring(newPath.Length-4,4).Equals(".FBX"))
{
if (newPath.Substring (newPath.Length - 9, 9).Equals("@skin.FBX"))
{
continue;
}
allAniPath.Add (newPath);
Debug.Log("写进allAniPath表中的路径:"+newPath);
}
}
//FBX中读取动作片段
if (allAniPath == null)
return;
for(int i=0;i<allAniPath.Count;i++)
{
AnimationClip newClip = new AnimationClip ();
AnimationClip oldClip = AssetDatabase.LoadAssetAtPath (allAniPath[i],typeof(AnimationClip)) as AnimationClip;
Debug.Log (oldClip.name);
EditorUtility.CopySerialized (oldClip,newClip);
//@--standy和run执行loopTime和 loopPose执行循环--@
if (oldClip.name.Equals ("standby") || oldClip.name.Equals ("run"))
{AnimationClipSettings clipSetting = AnimationUtility.GetAnimationClipSettings (newClip);
clipSetting.loopTime = true;
clipSetting.loopBlend = true;
AnimationUtility.SetAnimationClipSettings (newClip,clipSetting);
}
AssetDatabase.CreateAsset (newClip,_folderAssetPath+newClip.name+".anim");
File.Delete (allAniPath[i]);
}
allAniPath.Clear ();
AssetDatabase.Refresh ();
}
}
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
using System;
public class AnimatorTools : EditorWindow
{
[MenuItem("AnimatorTools/复制AnimationClip")]
static void CopyClip()
{
//测试被选择物体的路径:Assets/Art/Model/Character/hero3009/hero3009@attack.FBX
string selectPath = AssetDatabase.GetAssetPath (Selection.activeObject);
Debug.Log ("测试被选择物体的路径:"+selectPath);
string[] str = selectPath.Split ("/"[0]);
//得到的路径:Assets/Art/Model/Character/hero3009/
string _folderAssetPath = selectPath.Substring (0,selectPath.Length-str[str.Length-1].Length);
Debug.Log ("得到的路径:"+_folderAssetPath);
//获取文件夹底下所有文件路径
string projectDataPath = Application.dataPath.Substring (0,Application.dataPath.Length-6);
string[] allFilePath = Directory.GetFiles (projectDataPath+_folderAssetPath,"*",SearchOption.TopDirectoryOnly);
List<string> allAniPath = new List<string> ();
//做个循环让以.FBX结尾的文件放进List中
for (int i = 0; i < allFilePath.Length; i++)
{
string remove = projectDataPath;
string newPath = allFilePath [i].Remove (0,remove.Length);
if(newPath.Substring(newPath.Length-4,4).Equals(".FBX"))
{
if (newPath.Substring (newPath.Length - 9, 9).Equals("@skin.FBX"))
{
continue;
}
allAniPath.Add (newPath);
Debug.Log("写进allAniPath表中的路径:"+newPath);
}
}
//FBX中读取动作片段
if (allAniPath == null)
return;
for(int i=0;i<allAniPath.Count;i++)
{
AnimationClip newClip = new AnimationClip ();
AnimationClip oldClip = AssetDatabase.LoadAssetAtPath (allAniPath[i],typeof(AnimationClip)) as AnimationClip;
Debug.Log (oldClip.name);
EditorUtility.CopySerialized (oldClip,newClip);
//@--standy和run执行loopTime和 loopPose执行循环--@
if (oldClip.name.Equals ("standby") || oldClip.name.Equals ("run"))
{AnimationClipSettings clipSetting = AnimationUtility.GetAnimationClipSettings (newClip);
clipSetting.loopTime = true;
clipSetting.loopBlend = true;
AnimationUtility.SetAnimationClipSettings (newClip,clipSetting);
}
AssetDatabase.CreateAsset (newClip,_folderAssetPath+newClip.name+".anim");
File.Delete (allAniPath[i]);
}
allAniPath.Clear ();
AssetDatabase.Refresh ();
}
}
阅读全文
1 0
- 制作unity小工具 获取FBX模型里面的AnimationClip片段
- Unity 动态为AnimationClip 注入事件的小工具类
- 使用python Tkinter制作一个可以生成重复文本片段的小工具
- UNITY 用于打点统计的小工具
- WPF制作的天气预报小工具
- Unity小工具推荐
- Unity 导入 fbx 模型文件
- Unity 修改FBX模型动画
- 获取PM2.5信息的小工具
- 选择复制剪贴板里面的内容——小工具
- unity AnimationState和animationclip的区别
- 单词表制作小工具
- unity FBX模型导出系统源码WRP FBX Exporter下载
- Java制作的快速打开文件夹、程序的小工具
- WIN7\Vista 边栏小工具的制作 HelloWorld
- 使用java反射机制制作的小工具
- WinForm制作定时显示基金净值的桌面小工具
- WinForm制作定时显示基金净值的桌面小工具(续)
- 可能用到的第三方库
- 数据传输
- 关于mysql存储过程的definer的问题
- JAVAWEB第六天sax方式解析xml
- Android自定义未读消息提示View
- 制作unity小工具 获取FBX模型里面的AnimationClip片段
- 全网最新:Netty源码剖析&NIO+Netty5各种RPC架构实战路线
- addTextChangedListener(TextWatcher watcher)
- spring中使用@Scheduled注解时corn表达式、fixedRate、fixedDelay的区别
- UDP
- UDP网络编程
- 如果getParameter()的参数不存在 将返回什么
- [kuangbin带你飞]专题1 简单搜索 D
- java test表中查询数据