在编辑器中导入时重命名动画片段 [英] Rename animation clips when importing in the Editor

查看:427
本文介绍了在编辑器中导入时重命名动画片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾了文档,但是没有看到任何重命名剪辑的方法,因为剪辑是由模型导入器导入的.是否有API调用来命名剪辑?这一点特别重要,因为mecanim使用字符串名称作为其api调用的基础,并且我希望其文件名正确的剪辑具有特定的命名约定,即使艺术家使用其他名称命名,还是我必须重命名成千上万个文件手?

I looked around the docs but didn't see any way to rename a clip as it is imported by a model importer. Is there an API call to name the clips? This is of particular importance because mecanim uses string names for the basis of its api calls and I want clips whose file names are right to have a specific naming convention even if the artist named it something else or will I have to rename thousands of files by hand?

https://s3.amazonaws .com/uploads.hipchat.com/20686/98498/FukbQZCxHofQopy/Untitled-2.jpg

推荐答案

获取 ModelImporter 来自 AssetImporter .然后,您可以从 ModelImporter.defaultClipAnimations 中获取动画剪辑.遍历动画剪辑,重命名每个动画剪辑然后保存.

Get ModelImporter from AssetImporter. You can then get the animation clips from ModelImporter.defaultClipAnimations. Loop through the animation clips, rename each one then save it.

类似这样的东西:

using UnityEditor;
public class CreateAnimationClip : AssetPostprocessor
{
    void OnPreprocessAnimation()
    {
        ModelImporter modelImporter = assetImporter as ModelImporter;

        ModelImporterClipAnimation[] clipAnimations = modelImporter.defaultClipAnimations;

        //Modify/Rename animation clips?
        for (int i = 0; i < clipAnimations.Length; i++)
        {
            clipAnimations[i].name = "Your New Clip Name";
        }

        //Assign modiffied clip names back to modelImporter
        modelImporter.clipAnimations = clipAnimations;

        //Save
        modelImporter.SaveAndReimport();
    }
}

这篇关于在编辑器中导入时重命名动画片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆