8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

アセットバンドルマニフェストをEditorでファイルからロードする

Posted at

アセットバンドルビルドマニフェスト

BuildPipeline.BuildAssetBundles を呼ぶとAssetBundleManifest が返ります。
このとき、アセットバンドル出力先フォルダ(仮にAssetBundlesフォルダ)にAssetBundlesとAssetBundles.manifestというマニフェストファイルが生成されます。
このマニフェストファイルから AssetBundleManifest への変換をEditor上でしたかったのですが、方法が見当たらなかったのでメモを残しておきます;-D

# AssetBundleManifest ファイルからの読み込み

まずは以下のManifestHelper.csを保存して…

using UnityEditor;
using UnityEngine;

public static class ManifestHelper {
	public static AssetBundleManifest LoadAssetBundleManifest(string path) {
		AssetBundleManifest ret = default(AssetBundleManifest);
		AssetBundle assetBundle = default(AssetBundle);
		try {
			assetBundle = AssetBundle.LoadFromFile(path);
			ret = (AssetBundleManifest)assetBundle.LoadAsset("AssetBundleManifest", typeof(AssetBundleManifest));
		} catch (System.Exception e) {
			Debug.LogError("Exception occur: " + e);
		} finally {
			if (assetBundle != null) {
				assetBundle.Unload(false);
			}
		}
		return ret;
	}
}

Assets/AssetBundles/フォルダにあるAssetBundles(.manifest拡張子が付いてない方)をロードしたい場合は、

AssetBundleManifest manifest = ManifestHelper.LoadAssetBundleManifest(System.IO.Path.Combine(Application.dataPath, "AssetBundles/AssetBundles"));

で読み込めます。

以上です。

8
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?