加载场景
public AssetReference sceneReference;
void Start()
{
sceneReference.LoadSceneAsync().Completed += (handle) =>
{
Debug.Log("场景加载后想做的操作");
};
}
释放资源
- 释放后的资源 再次使用 需要重新加载
- 资源释放 不影响场景中实例化出的对象 会影响非实例化的资源(材质、音效等)
- 资源释放后 AssetReference的资源引用(Asset)会清空 但AsyncOperationHandle类的资源引用(Result)不为空
public AssetReference assetReference;
public AssetReference materialReferece;
void Start()
{
assetReference.LoadAssetAsync<GameObject>().Completed += (handle) =>
{
if (handle.Status == AsyncOperationStatus.Succeeded)
{
GameObject cube = Instantiate(handle.Result, Vector3.zero, Quaternion.identity);
assetReference.ReleaseAsset();
materialReferece.LoadAssetAsync<Material>().Completed += (obj) =>
{
cube.GetComponent<MeshRenderer>().material = obj.Result;
Debug.Log(obj.Result);
Debug.Log(materialReferece.Asset);
materialReferece.ReleaseAsset();
Debug.Log(obj.Result);
Debug.Log(materialReferece.Asset);
};
}
};
}
|