本文主要是介绍Unity中使用AssetPostprocessor对模型动画处理,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在游戏开发的过程中,会遇到模型动作同事频繁的修改模型动画,比如可能某个动作不对了等等。而程序使用的动画clip是从模型中拷贝一份出来的,而在AssetPostprocessor中就可以做一些处理这样模型同事频繁修改动画的话,只需要重新导入一下就可以了。
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths, bool didDomainReload){bool processed_flag = false;foreach (string asset_path in importedAssets) {Debug.LogError("导入资源 asset_path:"+asset_path);string dir = Path.GetDirectoryName(asset_path);Object main_asset = AssetDatabase.LoadMainAssetAtPath(asset_path);if (main_asset.GetType() == typeof(GameObject) && Path.GetExtension(asset_path).ToLower() == ".fbx") {Object[] assets = AssetDatabase.LoadAllAssetsAtPath(asset_path);List<Object> animation_clip_list = new List<Object>();foreach (Object asset in assets){if (asset.GetType() == typeof(AnimationClip)){if (!asset.name.StartsWith("__preview__")){animation_clip_list.Add(asset);}}}foreach (AnimationClip animation_clip in animation_clip_list){Object new_animation_clip = new AnimationClip();EditorUtility.CopySerialized(animation_clip, new_animation_clip);if(GetIsContains(new_animation_clip.name)){var clip = new_animation_clip as AnimationClip;AnimationClipSettings clipSetting = AnimationUtility.GetAnimationClipSettings(clip);clipSetting.loopTime = true;AnimationUtility.SetAnimationClipSettings(clip, clipSetting);}string animation_path = Path.Combine(copyPath, new_animation_clip.name + ".anim");AssetDatabase.CreateAsset(new_animation_clip, animation_path);}processed_flag = true;}}if (processed_flag) {AssetDatabase.Refresh();}}
这篇关于Unity中使用AssetPostprocessor对模型动画处理的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!