由于模型数量有点多,并且都要修改参数,还有从里面提取动画。就搜搜查查,搞了个小工具,批量的修改 FBX 模型的 参数,以及提取动画相关。
using UnityEditor; using UnityEngine; using System.IO; using System.Collections; using System.Collections.Generic; public class ModifyMoidel : Editor { [MenuItem("BenBen/修改模型ModelScal")] public static void ModifyMoidelScale() { Listpaths = new List (); foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.Assets)) { Debug.Log(o.name); //非对象不继续 if (!(o is GameObject)) continue; //将o作为模型存储在mod中 //Debug.LogWarning(o.name); GameObject mod = o as GameObject; //将mod模型路径存储在path中 string path = AssetDatabase.GetAssetPath(mod); ModelImporter modelimporter = ModelImporter.GetAtPath(path) as ModelImporter; if (!modelimporter) { UnityEngine.Debug.LogError(string.Format("path-->{0}<---不是ModelImporter", path)); continue; } //修改Model 下的Scale Factor modelimporter.globalScale = 10; paths.Add(path); AssetDatabase.ImportAsset(path); } AssetDatabase.Refresh(); CreatNewAnimations(paths); } private static void CreatNewAnimations(List paths) { UnityEditor.Animations.AnimatorController animatorCOntroller= null; UnityEditor.Animations.AnimatorControllerLayer layer = null; UnityEditor.Animations.AnimatorStateMachine asm = null; Debug.Log(paths.Count); for (int i = 0; i {0}<--不包含AnimationClip", paths[i])); continue; } string fbxName = Path.GetFileNameWithoutExtension(paths[i]); fbxName = fbxName.Substring(fbxName.LastIndexOf("_") + 1); //新的AnimationClip名字 var newClipName = GetAniName(int.Parse(fbxName)) + ".anim"; string directoryPath = paths[i].Replace(Path.GetFileName(paths[i]), "AnimationClip/"); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } EditorCurveBinding[] binding = AnimationUtility.GetCurveBindings(clip); for (int j = 0; j
如果有更简单的实现方法欢迎各位大佬留言。
补充:Unity 动态修改prefab 同步fbx
有时候我们想prefab和fbx无缝切换怎么办,也就是在unity里调完效果后不满意,返回dcc如阿健修改模型,但是prefab上又挂载了东西,不想重拖怎么办?这时候prefab variant就又用途了
建立变体,把变体拖到场景里。
或者先拖fbx到场景,再选择变体放置。
然后修改好模型后,直接再在文件浏览器里替换同名prefab
貌似需要到prefab模式里再revert一下
这样就可以实现“动态”修改perfab了。没改变的话可以右键相关属性revert
嗯
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
内容推荐:免费高清PNG素材下载