プロジェクトビューのPrefabの名前を一括変更する

8035 ワード

簡単なコードは次のとおりです.
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Collections;
using System.Collections.Generic;

public class RenameEffect 
{
    [MenuItem("XiYouEditor/Effect/RenameEffect-AddPrefix")]
    static void Execute()
    {
        foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
        {
            if (!(o is Object))
                continue;
            AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(o), "P-" + o.name);
        }
    }
}

コピーアクションファイルを処理します.
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Collections;
using System.Collections.Generic;

public class AnimationBatch
{
    [MenuItem("XiYouEditor/Animation/Copy Batch")]
    static void Execute()
    {
        List<string> lstAnimName = new List<string>();

        foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
        {
            if (!(o is GameObject))
                continue;
            if (!o.name.Contains("@"))
                continue;
            
            GameObject charFbx = (GameObject)o;
            
            string strClipName = charFbx.name;
            int nIndex = strClipName.LastIndexOf('@');
            strClipName = strClipName.Substring(nIndex + 1, strClipName.Length - nIndex - 1);
            
            AnimationClip newClip = new AnimationClip();
            EditorUtility.CopySerialized(charFbx.animation.GetClip(strClipName), newClip);
            
            string strNewAnim = AssetDatabase.GetAssetPath(charFbx);
            strNewAnim = strNewAnim.Substring(0, strNewAnim.LastIndexOf('/') + 1);
            strNewAnim += strClipName;
            strNewAnim += ".anim";
            
            if(!File.Exists(strNewAnim))
                AssetDatabase.CreateAsset(newClip, strNewAnim);

            lstAnimName.Add(strClipName);
        }

        foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
        {
            if (!(o is GameObject))
                continue;
            if (o.name.Contains("@"))
                continue;

            GameObject charFbx = (GameObject)o;

            string CharDirPath = AssetDatabase.GetAssetPath(charFbx);
            CharDirPath = CharDirPath.Substring(0, CharDirPath.LastIndexOf('/') + 1);

            //  
            charFbx.animation.clip = null;

            foreach (string name in lstAnimName)
            {
                AnimationClip DestClip = (AnimationClip)AssetDatabase.LoadAssetAtPath(CharDirPath + name + ".anim", typeof(AnimationClip));
                charFbx.animation.RemoveClip(name);
                charFbx.animation.AddClip(DestClip, name);
            }

            //  
            AnimationClip defaultClip = charFbx.animation.GetClip("Idle1");
            if (defaultClip != null)
                charFbx.animation.clip = defaultClip;

            charFbx.animation.cullingType = AnimationCullingType.AlwaysAnimate;

            EditorUtility.SetDirty(o);
        }
    }
}

具体的なコードはプロジェクトのニーズに応じてカスタマイズされます~