Unity 读取配置文件 自动切割 Animations 分段
2016-09-26 19:05
513 查看
网上有些资源,是没有分割动画的。就是整的一个 Take01 转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
我们可以点 小加号 ,来增加一个动画,并设置起始帧 和 结束帧。
但是这样做,数据是保存在 Library 文件夹的,而我们一般都是不把 Library 上传到 SVN的。
所以这个数据就会丢失。
转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
那我们就把这个数据写到 配置文件中,然后在代码中读取出来,自动切割动画。
下面是脚本:
/************************************************
* 文件名:FBXPostprocessor.cs
* 描述:FBX处理 自动分割
* 创建人:陈鹏
* 创建日期:20160926
* http://blog.csdn.net/huutu/article/details/52672911 * ************************************************/
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Collections.Generic;
using System;
class FBXPostprocessor : AssetPostprocessor
{
// This method is called just before importing an FBX.
void OnPreprocessModel()
{
Debug.Log("OnPreprocessModel " + assetPath);
ModelImporter mi = (ModelImporter) assetImporter;
//clips txt
TextAsset clipsAsset = (TextAsset) AssetDatabase.LoadAssetAtPath(assetPath.Substring(0, assetPath.LastIndexOf('.')) + "_clips.txt", typeof(TextAsset));
if(clipsAsset != null)
{
List<ModelImporterClipAnimation> anims = new List<ModelImporterClipAnimation>();
string[] clipsText = clipsAsset.text.Replace("\r\n", "\n").Split('\n');
foreach(string c in clipsText)
{
string[] vs = c.Split(' ');
if(vs.Length >= 3)
{
string name = vs[0];
string begin = vs[1];
string end = vs[2];
ModelImporterClipAnimation clip = new ModelImporterClipAnimation();
clip.name = name;
clip.firstFrame = System.Convert.ToInt32(begin);
clip.lastFrame = System.Convert.ToInt32(end);
if(name == "idle" || name == "walk" || name == "run")
{
clip.loop = true;
clip.loopPose = true;
}
anims.Add(clip);
}
}
mi.clipAnimations = anims.ToArray();
}
}
}
放到 Editor 目录,然后编写配置文件如下:
Reimport Fbx 文件即可
重新导入完成后,就自动切割了动画转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
示例工程: http://pan.baidu.com/s/1hsrz5Z2
我们可以点 小加号 ,来增加一个动画,并设置起始帧 和 结束帧。
但是这样做,数据是保存在 Library 文件夹的,而我们一般都是不把 Library 上传到 SVN的。
所以这个数据就会丢失。
转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
那我们就把这个数据写到 配置文件中,然后在代码中读取出来,自动切割动画。
下面是脚本:
/************************************************
* 文件名:FBXPostprocessor.cs
* 描述:FBX处理 自动分割
* 创建人:陈鹏
* 创建日期:20160926
* http://blog.csdn.net/huutu/article/details/52672911 * ************************************************/
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Collections.Generic;
using System;
class FBXPostprocessor : AssetPostprocessor
{
// This method is called just before importing an FBX.
void OnPreprocessModel()
{
Debug.Log("OnPreprocessModel " + assetPath);
ModelImporter mi = (ModelImporter) assetImporter;
//clips txt
TextAsset clipsAsset = (TextAsset) AssetDatabase.LoadAssetAtPath(assetPath.Substring(0, assetPath.LastIndexOf('.')) + "_clips.txt", typeof(TextAsset));
if(clipsAsset != null)
{
List<ModelImporterClipAnimation> anims = new List<ModelImporterClipAnimation>();
string[] clipsText = clipsAsset.text.Replace("\r\n", "\n").Split('\n');
foreach(string c in clipsText)
{
string[] vs = c.Split(' ');
if(vs.Length >= 3)
{
string name = vs[0];
string begin = vs[1];
string end = vs[2];
ModelImporterClipAnimation clip = new ModelImporterClipAnimation();
clip.name = name;
clip.firstFrame = System.Convert.ToInt32(begin);
clip.lastFrame = System.Convert.ToInt32(end);
if(name == "idle" || name == "walk" || name == "run")
{
clip.loop = true;
clip.loopPose = true;
}
anims.Add(clip);
}
}
mi.clipAnimations = anims.ToArray();
}
}
}
放到 Editor 目录,然后编写配置文件如下:
Reimport Fbx 文件即可
重新导入完成后,就自动切割了动画转自http://blog.csdn.net/huutu http://www.thisisgame.com.cn
示例工程: http://pan.baidu.com/s/1hsrz5Z2
相关文章推荐
- 可实现自动重载配置文件读取类
- c# unity 读取配置json文件
- Unity Application Block 学习笔记 之 在VS2012中 配置文件 自动感应
- Unity读取 JSon配置文件
- unity读取txt配置文件
- 无法读取用户配置文件,系统自动建立Temp临时用户
- c++ 编写程序开机自动启动,读取配置文件问题
- Unity 读取文件 TextAsset读取配置文件
- Unity Application Block--通过配置文件读取映射
- spring类实现自动读取配置文件
- Unity读取 JSon配置文件
- Unity读取 JSon配置文件
- Unity读取 JSon配置文件
- (4-1)Unity3D/工具:6步学会在Unity中读取Excel配置文件
- Android 读取OTG中配置文件完成自动测试
- Qt:让控件(widgets)内容可以自动 保存/读取 到配置文件(QSettings)中
- 扩展spring类实现自动读取配置文件
- Unity Application Block--通过配置文件读取映射
- Unity Application Block--通过配置文件读取映射
- Unity_ini配置文件应用(用于读取或写入程序设置)