进口fbx角色动画read-only解
2015-07-29 13:16
295 查看
原文链接:http://answers.unity3d.com/questions/8172/how-to-add-new-curves-or-animation-events-to-an-im.html
unity4.3版本号
方法1:
You can use an editor script that copies over the curves from the original imported Animation Clip into the duplicated Animation Clip.
Here is such an editor script.
Place it in a folder called Editor, located somewhere inside the Assets folder.
The script assumes that you have already made a duplicate of the imported clip and called it the same name but with a *copy postfix. For example, if you have an imported clip called MyAnimation,
it will search for *MyAnimation_copy*.
Select the original imported Animation Clip in the Project View.
You can now use the menu Assets -> Transfer Clip Curves to Copy
And the script:
using UnityEditor;
using UnityEngine;
using System.Collections;
public class CurvesTransferer {
const string duplicatePostfix = "_copy";
[MenuItem ("Assets/Transfer Clip Curves to Copy")]
static void CopyCurvesToDuplicate () {
// Get selected AnimationClip
AnimationClip imported = Selection.activeObject as AnimationClip;
if (imported == null) {
Debug.Log("Selected object is not an AnimationClip");
return;
}
// Find path of copy
string importedPath = AssetDatabase.GetAssetPath(imported);
string copyPath = importedPath.Substring(0, importedPath.LastIndexOf("/"));
copyPath += "/" + imported.name + duplicatePostfix + ".anim";
// Get copy AnimationClip
AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
if (copy == null) {
Debug.Log("No copy found at "+copyPath);
return;
}
// Copy curves from imported to copy
AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported, true);
for (int i=0; i<curveDatas.Length; i++) {
AnimationUtility.SetEditorCurve(
copy,
curveDatas[i].path,
curveDatas[i].type,
curveDatas[i].propertyName,
curveDatas[i].curve
);
}
Debug.Log("Copying curves into "+copy.name+" is done");
}
}
[/code]
方法2:
There is more simple variant. This script creates a new animation file itself and makes all copying operations.
using UnityEditor;
using UnityEngine;
public class CurvesTransferer
{
const string duplicatePostfix = "_copy";
static void CopyClip(string importedPath, string copyPath)
{
AnimationClip src = AssetDatabase.LoadAssetAtPath(importedPath, typeof(AnimationClip)) as AnimationClip;
AnimationClip newClip = new AnimationClip();
newClip.name = src.name + duplicatePostfix;
AssetDatabase.CreateAsset(newClip, copyPath);
AssetDatabase.Refresh();
}
[MenuItem("Assets/Transfer Clip Curves to Copy")]
static void CopyCurvesToDuplicate()
{
// Get selected AnimationClip
AnimationClip imported = Selection.activeObject as AnimationClip;
if (imported == null)
{
Debug.Log("Selected object is not an AnimationClip");
return;
}
// Find path of copy
string importedPath = AssetDatabase.GetAssetPath(imported);
string copyPath = importedPath.Substring(0, importedPath.LastIndexOf("/"));
copyPath += "/" + imported.name + duplicatePostfix + ".anim";
CopyClip(importedPath, copyPath);
AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
if (copy == null)
{
Debug.Log("No copy found at " + copyPath);
return;
}
// Copy curves from imported to copy
AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported, true);
for (int i = 0; i < curveDatas.Length; i++)
{
AnimationUtility.SetEditorCurve(
copy,
curveDatas[i].path,
curveDatas[i].type,
curveDatas[i].propertyName,
curveDatas[i].curve
);
}
Debug.Log("Copying curves into " + copy.name + " is done");
}
}
[/code]
方法3:
Guys, I loved this script so much, I went ahead and added a couple of features.
Here is a modified version of MaDDoX's edit that includes logic for automatically placing the animations into folders.
It first uses an animations folder to contain them all and then if the animation came from an FBX file, it will use the FBX's name to create a subfolder for those animations. Hopefully, this helps y'all keep things organized.
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Collections;
public class MultipleCurvesTransferer {
const string duplicatePostfix = "Edit";
const string animationFolder = "Animations";
static void CopyClip(string importedPath, string copyPath) {
AnimationClip src = AssetDatabase.LoadAssetAtPath(importedPath, typeof(AnimationClip)) as AnimationClip;
AnimationClip newClip = new AnimationClip();
newClip.name = src.name + duplicatePostfix;
AssetDatabase.CreateAsset(newClip, copyPath);
AssetDatabase.Refresh();
}
[MenuItem("Assets/Transfer Multiple Clips Curves to Copy")]
static void CopyCurvesToDuplicate()
{
// Get selected AnimationClip
Object[] imported = Selection.GetFiltered(typeof(AnimationClip), SelectionMode.Unfiltered);
if (imported.Length == 0)
{
Debug.LogWarning("Either no objects were selected or the objects selected were not AnimationClips.");
return;
}
//If necessary, create the animations folder.
if (Directory.Exists("Assets/" + animationFolder) == false) {
AssetDatabase.CreateFolder("Assets", animationFolder);
}
foreach (AnimationClip clip in imported) {
string importedPath = AssetDatabase.GetAssetPath(clip);
//If the animation came from an FBX, then use the FBX name as a subfolder to contain the animations.
string copyPath;
if (importedPath.Contains(".fbx")) {
//With subfolder.
string folder = importedPath.Substring(importedPath.LastIndexOf("/") + 1, importedPath.LastIndexOf(".") - importedPath.LastIndexOf("/") - 1);
if (!Directory.Exists("Assets/Animations/" + folder)) {
AssetDatabase.CreateFolder("Assets/Animations", folder);
}
copyPath = "Assets/Animations/" + folder + "/" + clip.name + duplicatePostfix + ".anim";
} else {
//No Subfolder
copyPath = "Assets/Animations/" + clip.name + duplicatePostfix + ".anim";
}
Debug.Log("CopyPath: " + copyPath);
CopyClip(importedPath, copyPath);
AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
if (copy == null)
{
Debug.Log("No copy found at " + copyPath);
return;
}
// Copy curves from imported to copy
AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(clip, true);
for (int i = 0; i < curveDatas.Length; i++)
{
AnimationUtility.SetEditorCurve(
copy,
curveDatas[i].path,
curveDatas[i].type,
curveDatas[i].propertyName,
curveDatas[i].curve
);
}
Debug.Log("Copying curves into " + copy.name + " is done");
}
}
}
[/code]
....
unity4.3版本号
方法1:
You can use an editor script that copies over the curves from the original imported Animation Clip into the duplicated Animation Clip.
Here is such an editor script.
Place it in a folder called Editor, located somewhere inside the Assets folder.
The script assumes that you have already made a duplicate of the imported clip and called it the same name but with a *copy postfix. For example, if you have an imported clip called MyAnimation,
it will search for *MyAnimation_copy*.
Select the original imported Animation Clip in the Project View.
You can now use the menu Assets -> Transfer Clip Curves to Copy
And the script:
using UnityEditor;
using UnityEngine;
using System.Collections;
public class CurvesTransferer {
const string duplicatePostfix = "_copy";
[MenuItem ("Assets/Transfer Clip Curves to Copy")]
static void CopyCurvesToDuplicate () {
// Get selected AnimationClip
AnimationClip imported = Selection.activeObject as AnimationClip;
if (imported == null) {
Debug.Log("Selected object is not an AnimationClip");
return;
}
// Find path of copy
string importedPath = AssetDatabase.GetAssetPath(imported);
string copyPath = importedPath.Substring(0, importedPath.LastIndexOf("/"));
copyPath += "/" + imported.name + duplicatePostfix + ".anim";
// Get copy AnimationClip
AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
if (copy == null) {
Debug.Log("No copy found at "+copyPath);
return;
}
// Copy curves from imported to copy
AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported, true);
for (int i=0; i<curveDatas.Length; i++) {
AnimationUtility.SetEditorCurve(
copy,
curveDatas[i].path,
curveDatas[i].type,
curveDatas[i].propertyName,
curveDatas[i].curve
);
}
Debug.Log("Copying curves into "+copy.name+" is done");
}
}
[/code]
方法2:
There is more simple variant. This script creates a new animation file itself and makes all copying operations.
using UnityEditor;
using UnityEngine;
public class CurvesTransferer
{
const string duplicatePostfix = "_copy";
static void CopyClip(string importedPath, string copyPath)
{
AnimationClip src = AssetDatabase.LoadAssetAtPath(importedPath, typeof(AnimationClip)) as AnimationClip;
AnimationClip newClip = new AnimationClip();
newClip.name = src.name + duplicatePostfix;
AssetDatabase.CreateAsset(newClip, copyPath);
AssetDatabase.Refresh();
}
[MenuItem("Assets/Transfer Clip Curves to Copy")]
static void CopyCurvesToDuplicate()
{
// Get selected AnimationClip
AnimationClip imported = Selection.activeObject as AnimationClip;
if (imported == null)
{
Debug.Log("Selected object is not an AnimationClip");
return;
}
// Find path of copy
string importedPath = AssetDatabase.GetAssetPath(imported);
string copyPath = importedPath.Substring(0, importedPath.LastIndexOf("/"));
copyPath += "/" + imported.name + duplicatePostfix + ".anim";
CopyClip(importedPath, copyPath);
AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
if (copy == null)
{
Debug.Log("No copy found at " + copyPath);
return;
}
// Copy curves from imported to copy
AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported, true);
for (int i = 0; i < curveDatas.Length; i++)
{
AnimationUtility.SetEditorCurve(
copy,
curveDatas[i].path,
curveDatas[i].type,
curveDatas[i].propertyName,
curveDatas[i].curve
);
}
Debug.Log("Copying curves into " + copy.name + " is done");
}
}
[/code]
方法3:
Guys, I loved this script so much, I went ahead and added a couple of features.
Here is a modified version of MaDDoX's edit that includes logic for automatically placing the animations into folders.
It first uses an animations folder to contain them all and then if the animation came from an FBX file, it will use the FBX's name to create a subfolder for those animations. Hopefully, this helps y'all keep things organized.
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Collections;
public class MultipleCurvesTransferer {
const string duplicatePostfix = "Edit";
const string animationFolder = "Animations";
static void CopyClip(string importedPath, string copyPath) {
AnimationClip src = AssetDatabase.LoadAssetAtPath(importedPath, typeof(AnimationClip)) as AnimationClip;
AnimationClip newClip = new AnimationClip();
newClip.name = src.name + duplicatePostfix;
AssetDatabase.CreateAsset(newClip, copyPath);
AssetDatabase.Refresh();
}
[MenuItem("Assets/Transfer Multiple Clips Curves to Copy")]
static void CopyCurvesToDuplicate()
{
// Get selected AnimationClip
Object[] imported = Selection.GetFiltered(typeof(AnimationClip), SelectionMode.Unfiltered);
if (imported.Length == 0)
{
Debug.LogWarning("Either no objects were selected or the objects selected were not AnimationClips.");
return;
}
//If necessary, create the animations folder.
if (Directory.Exists("Assets/" + animationFolder) == false) {
AssetDatabase.CreateFolder("Assets", animationFolder);
}
foreach (AnimationClip clip in imported) {
string importedPath = AssetDatabase.GetAssetPath(clip);
//If the animation came from an FBX, then use the FBX name as a subfolder to contain the animations.
string copyPath;
if (importedPath.Contains(".fbx")) {
//With subfolder.
string folder = importedPath.Substring(importedPath.LastIndexOf("/") + 1, importedPath.LastIndexOf(".") - importedPath.LastIndexOf("/") - 1);
if (!Directory.Exists("Assets/Animations/" + folder)) {
AssetDatabase.CreateFolder("Assets/Animations", folder);
}
copyPath = "Assets/Animations/" + folder + "/" + clip.name + duplicatePostfix + ".anim";
} else {
//No Subfolder
copyPath = "Assets/Animations/" + clip.name + duplicatePostfix + ".anim";
}
Debug.Log("CopyPath: " + copyPath);
CopyClip(importedPath, copyPath);
AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
if (copy == null)
{
Debug.Log("No copy found at " + copyPath);
return;
}
// Copy curves from imported to copy
AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(clip, true);
for (int i = 0; i < curveDatas.Length; i++)
{
AnimationUtility.SetEditorCurve(
copy,
curveDatas[i].path,
curveDatas[i].type,
curveDatas[i].propertyName,
curveDatas[i].curve
);
}
Debug.Log("Copying curves into " + copy.name + " is done");
}
}
}
[/code]
....
相关文章推荐
- 电脑使用--快捷键等【转】
- 代码重构-批量删除
- HDU 1073 Online Judge
- 目录
- [leetcode-30]Substring with Concatenation of All Words(java)
- 电源管理之——battery选型
- 第17周项目6 阅读文件,多文件
- 微软MSDN订阅用户已可提前手工下载Windows 10安装包
- VS中lib和dll
- 十大紧缺行业发布,近半工作机会在一线
- 视频显示分辨率标准大全
- 表、栈和队列
- Client访问控制和Cyrus sasl认证.doc
- RadGridView
- HDU 1029 Ignatius and the Princess IV
- 第一个mysql存储过程
- 数据结构(三):非线性逻辑结构-树
- 基于Html5的移动端(APP)开发框架的优缺点
- Java实现不同的类的属性之间相互赋值
- 字符识别OCR研究 字符识别,字符区域定位