进口fbx角色动画read-only解

进口fbx角色动画read-only解

大家好,又见面了,我是全栈君,今天给大家准备了Idea注册码。

原文链接:
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:


  1. using UnityEditor;
  2. using UnityEngine;
  3. using System.Collections;
  4.  
  5. public class CurvesTransferer {
  6.  
  7. const string duplicatePostfix = "_copy";
  8.  
  9. [MenuItem ("Assets/Transfer Clip Curves to Copy")]
  10. static void CopyCurvesToDuplicate () {
  11. // Get selected AnimationClip
  12. AnimationClip imported = Selection.activeObject as AnimationClip;
  13. if (imported == null) {
  14. Debug.Log("Selected object is not an AnimationClip");
  15. return;
  16. }
  17.  
  18. // Find path of copy
  19. string importedPath = AssetDatabase.GetAssetPath(imported);
  20. string copyPath = importedPath.Substring(0, importedPath.LastIndexOf("/"));
  21. copyPath += "/" + imported.name + duplicatePostfix + ".anim";
  22.  
  23. // Get copy AnimationClip
  24. AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
  25. if (copy == null) {
  26. Debug.Log("No copy found at "+copyPath);
  27. return;
  28. }
  29.  
  30. // Copy curves from imported to copy
  31. AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported, true);
  32. for (int i=0; i<curveDatas.Length; i++) {
  33. AnimationUtility.SetEditorCurve(
  34. copy,
  35. curveDatas[i].path,
  36. curveDatas[i].type,
  37. curveDatas[i].propertyName,
  38. curveDatas[i].curve
  39. );
  40. }
  41.  
  42. Debug.Log("Copying curves into "+copy.name+" is done");
  43. }
  44. }

方法2:

There is more simple variant. This script creates a new animation file itself and makes all copying operations.



  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. public class CurvesTransferer
  5. {
  6. const string duplicatePostfix = "_copy";
  7.  
  8. static void CopyClip(string importedPath, string copyPath)
  9. {
  10. AnimationClip src = AssetDatabase.LoadAssetAtPath(importedPath, typeof(AnimationClip)) as AnimationClip;
  11. AnimationClip newClip = new AnimationClip();
  12. newClip.name = src.name + duplicatePostfix;
  13. AssetDatabase.CreateAsset(newClip, copyPath);
  14. AssetDatabase.Refresh();
  15. }
  16.  
  17. [MenuItem("Assets/Transfer Clip Curves to Copy")]
  18. static void CopyCurvesToDuplicate()
  19. {
  20. // Get selected AnimationClip
  21. AnimationClip imported = Selection.activeObject as AnimationClip;
  22. if (imported == null)
  23. {
  24. Debug.Log("Selected object is not an AnimationClip");
  25. return;
  26. }
  27.  
  28. // Find path of copy
  29. string importedPath = AssetDatabase.GetAssetPath(imported);
  30. string copyPath = importedPath.Substring(0, importedPath.LastIndexOf("/"));
  31. copyPath += "/" + imported.name + duplicatePostfix + ".anim";
  32.  
  33. CopyClip(importedPath, copyPath);
  34.  
  35. AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
  36. if (copy == null)
  37. {
  38. Debug.Log("No copy found at " + copyPath);
  39. return;
  40. }
  41. // Copy curves from imported to copy
  42. AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported, true);
  43. for (int i = 0; i < curveDatas.Length; i++)
  44. {
  45. AnimationUtility.SetEditorCurve(
  46. copy,
  47. curveDatas[i].path,
  48. curveDatas[i].type,
  49. curveDatas[i].propertyName,
  50. curveDatas[i].curve
  51. );
  52. }
  53.  
  54. Debug.Log("Copying curves into " + copy.name + " is done");
  55. }
  56.  
  57. }

方法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.



  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. using System.IO;
  5. using System.Collections;
  6.  
  7. public class MultipleCurvesTransferer {
  8. const string duplicatePostfix = "Edit";
  9. const string animationFolder = "Animations";
  10.  
  11. static void CopyClip(string importedPath, string copyPath) {
  12. AnimationClip src = AssetDatabase.LoadAssetAtPath(importedPath, typeof(AnimationClip)) as AnimationClip;
  13. AnimationClip newClip = new AnimationClip();
  14. newClip.name = src.name + duplicatePostfix;
  15. AssetDatabase.CreateAsset(newClip, copyPath);
  16. AssetDatabase.Refresh();
  17. }
  18.  
  19. [MenuItem("Assets/Transfer Multiple Clips Curves to Copy")]
  20. static void CopyCurvesToDuplicate()
  21. {
  22. // Get selected AnimationClip
  23. Object[] imported = Selection.GetFiltered(typeof(AnimationClip), SelectionMode.Unfiltered);
  24. if (imported.Length == 0)
  25. {
  26. Debug.LogWarning("Either no objects were selected or the objects selected were not AnimationClips.");
  27. return;
  28. }
  29.  
  30. //If necessary, create the animations folder.
  31. if (Directory.Exists("Assets/" + animationFolder) == false) {
  32. AssetDatabase.CreateFolder("Assets", animationFolder);
  33. }
  34.  
  35. foreach (AnimationClip clip in imported) {
  36.  
  37.  
  38.  
  39. string importedPath = AssetDatabase.GetAssetPath(clip);
  40.  
  41. //If the animation came from an FBX, then use the FBX name as a subfolder to contain the animations.
  42. string copyPath;
  43. if (importedPath.Contains(".fbx")) {
  44. //With subfolder.
  45. string folder = importedPath.Substring(importedPath.LastIndexOf("/") + 1, importedPath.LastIndexOf(".") - importedPath.LastIndexOf("/") - 1);
  46. if (!Directory.Exists("Assets/Animations/" + folder)) {
  47. AssetDatabase.CreateFolder("Assets/Animations", folder);
  48. }
  49. copyPath = "Assets/Animations/" + folder + "/" + clip.name + duplicatePostfix + ".anim";
  50. } else {
  51. //No Subfolder
  52. copyPath = "Assets/Animations/" + clip.name + duplicatePostfix + ".anim";
  53. }
  54.  
  55. Debug.Log("CopyPath: " + copyPath);
  56.  
  57. CopyClip(importedPath, copyPath);
  58.  
  59. AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip;
  60. if (copy == null)
  61. {
  62. Debug.Log("No copy found at " + copyPath);
  63. return;
  64. }
  65. // Copy curves from imported to copy
  66. AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(clip, true);
  67. for (int i = 0; i < curveDatas.Length; i++)
  68. {
  69. AnimationUtility.SetEditorCurve(
  70. copy,
  71. curveDatas[i].path,
  72. curveDatas[i].type,
  73. curveDatas[i].propertyName,
  74. curveDatas[i].curve
  75. );
  76. }
  77.  
  78. Debug.Log("Copying curves into " + copy.name + " is done");
  79. }
  80. }
  81. }

….

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/117386.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • acwing-395. 冗余路径(Tarjan双连通分量)

    acwing-395. 冗余路径(Tarjan双连通分量)为了从 F 个草场中的一个走到另一个,奶牛们有时不得不路过一些她们讨厌的可怕的树。奶牛们已经厌倦了被迫走某一条路,所以她们想建一些新路,使每一对草场之间都会至少有两条相互分离的路径,这样她们就有多一些选择。每对草场之间已经有至少一条路径。给出所有 R 条双向路的描述,每条路连接了两个不同的草场,请计算最少的新建道路的数量,路径由若干道路首尾相连而成。两条路径相互分离,是指两条路径没有一条重合的道路。但是,两条分离的路径上可以有一些相同的草场。对于同一对草场之间,可能已经有两条不同的道路,你也可以

  • NumPy 中的集合运算

    NumPy 中的集合运算

    2021年11月22日
  • 怎么查看maven仓库地址_修改maven本地仓库

    怎么查看maven仓库地址_修改maven本地仓库Maven一般用来存放jar包的地方,有中央仓库和远程仓库1)找到下载的maven的路径,C:\Users\lqw\Documents\apache-maven-3.3.9\conf找到seting.xml文件,查看&lt;localRepository&gt;C:/repository&lt;/localRepository&gt;这里我改过默认地址了,可以自己设置2)找到自己的maven项目,…

  • Java多线程死锁问题

    Java多线程死锁问题死锁这么重要,请仔细阅读死锁问题死锁定义死锁举例如何排查死锁死锁发生的条件怎么解决死锁问题?线程通讯机制(wait/notify/notifyAll)LockSupport死锁问题死锁定义多线程编程中,因为抢占资源造成了线程无限等待的情况,此情况称为死锁。死锁举例注意:线程和锁的关系是:一个线程可以拥有多把锁,一个锁只能被一个线程拥有。当两个线程分别拥有一把各自的锁之后,又尝试去获取对方的锁,这样就会导致死锁情况的发生,具体先看下面代码:/***线程死锁问题*/public

  • 为 PHPer 准备的 Go 入门知识

    为 PHPer 准备的 Go 入门知识

  • 初学者计算机电脑怎样学,初学者怎样学习电脑能够快速入门(免费科普电脑基础知识)…

    初学者计算机电脑怎样学,初学者怎样学习电脑能够快速入门(免费科普电脑基础知识)…上次回答了一个关于怎样自学电脑操作比较快的问题,现在我把我的答案整理升级,增加了键盘的快速入手使用方法。发布出来,以便更多的人能够有所收获。1.开机和关机作为完全初学者,首先需要学会正确的开关机。下图我整理了一些常见主机的开关机键与重启(restart)按键。常见主机上的开关机键和重启键一般来说,较大的一个是开关机键,较小的一个为重启键。在电脑处于关闭状态时,按一下开关机键即为开机。当电脑处于开…

    2022年10月19日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号