简体   繁体   中英

How can I run Unity generated apk in my app without including it in the project as a module?

I am developing an android app for real estate and I have a virtual tour made in unity. As I will have many virtual tours in the future, integrating the tour in the app will make it large and heavy. I want the user to manually select the tour he wants to see, and then it should download it from the cloud and display it within the app. Please describe the methodology to achieve this.

You can build your core app, and then make an asset bundle for each tour:

AssetBundle is an archive file containing platform specific Assets (Models, Textures, Prefabs, Audio clips, and even entire Scenes) that can be loaded at runtime. Unity docs: https://docs.unity3d.com/Manual/AssetBundlesIntro.html

here is the script to download an asset bundle from server:

public class MyBehaviour : MonoBehaviour {
    void Start() {
        StartCoroutine(GetAssetBundle());
    }


        IEnumerator GetAssetBundle() {
            UnityWebRequest www = UnityWebRequest.GetAssetBundle("http://www.my-server.com/myData.unity3d");
            yield return www.SendWebRequest();

            if(www.isNetworkError || www.isHttpError) {
                Debug.Log(www.error);
            }
            else {
                AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM