Last active
August 29, 2015 14:16
-
-
Save marukun318/020c069e3ca41228989b to your computer and use it in GitHub Desktop.
アセットバンドルファイル名をインポート時に強制設定
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// アセットバンドルファイル名をインポート時に強制設定 | |
/// for Unity5 | |
/// | |
using UnityEngine; | |
using UnityEditor; | |
public sealed class AssetPreprocessor : AssetPostprocessor | |
{ | |
// アセットバンドル化するフォルダの設置場所 | |
private static string assetTopDir = "Assets/Data/"; // ※大文字小文字は区別される | |
private void SetAssetName(AssetImporter importer) | |
{ | |
string path = importer.assetPath; | |
if (!path.StartsWith(assetTopDir)) | |
return; | |
if (path.IndexOf("Resources/" ) >= 0) | |
return; | |
string abname = path.Replace(assetTopDir, ""); | |
int idx = abname.LastIndexOf('.' ); | |
if (idx != -1) | |
{ | |
abname = abname.Substring(0, idx) + ".unity3d"; | |
} | |
else | |
{ | |
abname = path; | |
} | |
importer.assetBundleName = abname; | |
importer.assetBundleVariant = ""; | |
} | |
private void OnPreprocessTexture() | |
{ | |
var importer = assetImporter as TextureImporter; | |
SetAssetName(importer); | |
} | |
private void OnPreprocessAudio() | |
{ | |
var importer = assetImporter as AudioImporter; | |
SetAssetName(importer); | |
} | |
private void OnPreprocessModel() | |
{ | |
var importer = assetImporter as ModelImporter; | |
SetAssetName(importer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
インポートで強制的にアセットバンドル名が設定されてしまうので、よく考えたら実用的には微妙だった。
せっかくだから置いてみます。