スクリプト
using System; using System.IO; using System.Linq; using UnityEditor; public static class AssetRenamer { public static void Rename ( string directoryName, Func<string, string> onReplace ) { if ( !directoryName.EndsWith( "/" ) ) { directoryName += "/"; } var assetPaths = AssetDatabase .GetAllAssetPaths() .Where( x => x.StartsWith( directoryName ) ) .ToArray() ; AssetDatabase.StartAssetEditing(); try { foreach ( var assetPath in assetPaths ) { AssetDatabase.RenameAsset( assetPath, onReplace( Path.GetFileNameWithoutExtension( assetPath ) ) ); } } finally { AssetDatabase.StopAssetEditing(); AssetDatabase.Refresh(); } } }
使用例
[MenuItem( "hoge/hoge" )] private static void Hoge() { AssetRenamer.Rename( "Assets", x => x.Replace( "-", "_" ) ); }