Recently, I find that Prefab /GameObject load from Unity project is not completely removable from memory. But Asset bundle can help. Of course, it must be pros and cons. Let's see how to implement asset bundle.
1. Create AssetBundle. You can Create the asset on wherever you want. [MenuItem("Assets/Build AssetBundles")] static void BuildAllAssetBundles() { BuildPipeline.BuildAssetBundles(Path.Combine(Application.dataPath, "AssetBundles"), BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.Android); } 2. Update the asset load from upload on GoogleDrive. Set the public access authority. 3. Get the link. You only use the middle part of the share link and combine it to become a downloadable link: Share link: https://drive.google.com/file/d/1HmscueNqI2wSuytWot1gT_mK7qeAjcv-/view?usp=sharing Download link: https://drive.google.com/uc?export=download&id=1HmscueNqI2wSuytWot1gT_mK7qeAjcv- 4. Finally, code like this: StartCoroutine(LoadAssetBundeFromWWW(www)); IEnumerator LoadAssetBundeFromWWW(WWW www) { yield return www; AssetBundle bundle = www.assetBundle;//get the asset bundle if (www.error == null) { var prefab = bundle.LoadAsset("Cube2");//the name of your asset/prefab you want to get GameObject go = Instantiate(prefab) as GameObject; //if you want to destory it. you may also need to unload the unused asset from ram Destroy(go); bundle.Unload(true); } }
0 Comments
Leave a Reply. |
Archives
May 2024
Categories |