Skip to content

Instantly share code, notes, and snippets.

@marukun318
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marukun318/020c069e3ca41228989b to your computer and use it in GitHub Desktop.
Save marukun318/020c069e3ca41228989b to your computer and use it in GitHub Desktop.
アセットバンドルファイル名をインポート時に強制設定
/// アセットバンドルファイル名をインポート時に強制設定
/// 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);
}
}
@marukun318
Copy link
Author

インポートで強制的にアセットバンドル名が設定されてしまうので、よく考えたら実用的には微妙だった。
せっかくだから置いてみます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment