Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active June 16, 2016 16:51
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 tsubaki/23359b3c9f501baae718e9520b1082aa to your computer and use it in GitHub Desktop.
Save tsubaki/23359b3c9f501baae718e9520b1082aa to your computer and use it in GitHub Desktop.
AssetBundleの読込
using UnityEngine;
using System.Collections;
using AssetBundles;
public class CreateInstance : MonoBehaviour {
[SerializeField]
string variant;
IEnumerator Start () {
// ロードするアセットの言語を設定
AssetBundleManager.ActiveVariants = new string[] { variant };
#if DEVELOPMENT_BUILD || UNITY_EDITOR
AssetBundleManager.SetDevelopmentAssetBundleServer ();
#endif
// AssetBundle Managerを初期化
if (AssetBundleManager.SimulateAssetBundleInEditor == false)
yield return AssetBundleManager.Initialize();
// prefabを取得(ついでに依存関係も解決)
var result = AssetBundleManager.LoadAssetAsync("prefab", "Canvas", typeof(GameObject));
yield return result;
// prefabをAssetBundleから複製
var obj = result.GetAsset<GameObject>();
GameObject.Instantiate(obj);
// AssetBundleを開放
AssetBundleManager.UnloadAssetBundle("prefab");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment