Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using UnityEngine;
using System.Collections;
public class LoadPrefabFromAssetbundle : MonoBehaviour {
[SerializeField]
string typeName; // type-aもしくはtype-bと入力
void Start ()
{
// スプライトを格納したAssetBundleの読込
var spriteUri = string.Format("{0}/{1}.{2}", Application.streamingAssetsPath, "character", typeName);
var spriteAb = AssetBundle.LoadFromFile(spriteUri);
// プレハブを格納したAssetBundleの読込
var prefabUri = string.Format("{0}/{1}", Application.streamingAssetsPath, "prefab");
var prefabAb = AssetBundle.LoadFromFile(prefabUri);
// プレハブを取得してインスタンス化
var prefab = prefabAb.LoadAsset<GameObject>("PlayerPrefab");
var instance = GameObject.Instantiate(prefab);
// アンロード
prefabAb.Unload(false);
spriteAb.Unload(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment