????????AB包的卸載高效穩定游戲開發的強制要求,它解決了資源管理中的內存泄漏問題,為動態的內容加載、熱更新、大型世界的構建提供了內存保障,最終提升了游戲性能、穩定性和用戶體驗。
卸載資源
????????方式一(推薦使用):
卸載內存里的AB包,但場景里可以正常引用對應資源:
AssetBundle,UnLoad(false)
????????或
AssetBundle.UnLoadAllAssetBundles(false)
????????方式二:
卸載內存里的AB包同時也卸載場景里對AB包的引用關系:
AssetBundle.UnLoad(true)
????????或
AssetBundle.UnLoadAllAssetBundle(true)
AssetBundle包的獲取注意
AssetBundle ab = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + "cube");
ab.Unload(false);
//卸載后才能再次加載對應的AssetBundle
AssetBundle ab1 = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + "cube");
如下會報錯:
AssetBundle ab = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + "cube");
//卸載后才能再次加載對應的AssetBundle
AssetBundle ab1 = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + "cube");
????????