AB打包Day01
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Load : MonoBehaviour {
// Use this for initialization
void Start () {
string _abpath = Application.streamingAssetsPath + "\\Windows\\sp";///此处sp为预制体内自己所设名字
AssetBundle ab = AssetBundle.LoadFromFile(_abpath);
if (ab == null)
{
Debug.LogError("加载AB失败");
return;
}
//GameObject CubeObj = ab.LoadAsset<GameObject>("Cube");
GameObject CubeObj = ab.LoadAsset<GameObject>("Sphere,);
if (CubeObj != null)
{
//加载成功
Instantiate(CubeObj );
}
else
{
Debug.LogError("该资源不存在");
}
StartCoroutine("Creat", ab);
}
// Update is called once per frame
void Update () {
}
IEnumerator Creat(AssetBundle ab)
{
yield return new WaitForSeconds(3);
ab.Unload(false); //释放内存
Debug.LogWarning("begin");
yield return new WaitForSeconds(10);
Instantiate(ab.LoadAsset<GameObject>("Sphere"));
}
}