コード例 #1
0
    IEnumerator LoadAsset()
    {
        modelManager.loadingBunles.Add(ABName);

#if UNITY_IOS
        BundleFullURL = PlayerPrefs.GetString("ApiUrl") + "/media/3d/" + ABName + "/ios/bundle";
#endif
#if PLATFORM_ANDROID
        BundleFullURL = PlayerPrefs.GetString("ApiUrl") + "/media/3d/" + ABName + "/android/bundle";
#endif
        Debug.Log("Load bundle by: " + BundleFullURL);

        CachedAssetBundle cab = new CachedAssetBundle(ABName, new Hash128(0, 0));
        using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(BundleFullURL, cab))
        {
            preloader.LoadPercent(uwr);
            yield return(uwr.SendWebRequest());

            if (uwr.isNetworkError || uwr.isHttpError)
            {
                Debug.Log(uwr.error);
                preloader.CantLoad();
                preloader.Loaded();
                GetComponent <Collider>().enabled = false;
                GetComponent <Mover>().enabled    = false;
            }
            else
            {
                // Get downloaded asset bundle
                AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
                if (bundle.Contains(AssetName))
                {
                    Instantiate(bundle.LoadAssetAsync(AssetName).asset, gameObject.transform);
                    modelManager.bundles.Add(bundle);
                    modelManager.loadingBunles.Remove(ABName);
                    mover.modelName = ABName;
                    Debug.Log("is OBJ");
                    preloader.Loaded();
                }
                else
                {
                    Debug.Log("Check !loaded Asset name: " + AssetName);
                    preloader.CantLoad();
                    preloader.Loaded();
                    GetComponent <Collider>().enabled = false;
                    GetComponent <Mover>().enabled    = false;
                }
            }
        }
    }
コード例 #2
0
    IEnumerator DownloadAndCache()
    {
        // Wait for the Caching system to be ready
        preloader.Loading();
        isRun = true;
        Debug.Log("isRunningTRUE");
        while (!Caching.ready)
        {
            yield return(null);
        }
        Debug.Log("Caching ready");
        // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
        using (WWW www = WWW.LoadFromCacheOrDownload(BundleFullURL, version))
        {
            Debug.Log("Loading ready");
            if (www.error == null)
            {
                preloader.LoadPercent(www);
            }
            yield return(www);

            if (www.error != null)
            {
                Debug.Log(ABName + " not downloaded. Error" + www.error);
                preloader.CantLoad();
            }
            else
            {
                AssetBundle bundle = www.assetBundle;
                if (AssetName == "" && TextAssetName == "")
                {
                    Debug.Log("Asset name not assigned");
                }
                else
                {
                    Debug.Log("Asset ready");
                    if (bundle.Contains(AssetName))
                    {
                        Instantiate(bundle.LoadAsset(AssetName), gameObject.transform);
                        objectActive = true;
                        Debug.Log("is OBJ");
                        preloader.Loaded();
                    }
                    else
                    {
                        Debug.Log("Check asset name");
                    }
                }
                // Unload the AssetBundles compressed contents to conserve memory
                bundle.Unload(false);
            }
            www.Dispose();
        }
        Debug.Log("isRunningFALSE");
        isRun = false;
        if (onRequestLost)
        {
            OnTrackingLost();
        }
    }
コード例 #3
0
    IEnumerator LoadAsset()
    {
        modelManager.loadingBunles.Add(ABName);

        /*while (!Caching.ready)
         *  yield return null;
         *
         * WWW www = WWW.LoadFromCacheOrDownload(BundleFullURL + ABName, 1);
         * yield return www;
         *
         * if (!string.IsNullOrEmpty(www.error))
         * {
         *  preloader.LoadPercent(www);
         *  Debug.Log(www.error);
         *  yield return null;
         * }
         * AssetBundle bundle = www.assetBundle;
         * if (bundle.Contains(AssetName))
         * {
         *  Instantiate(bundle.LoadAssetAsync(AssetName).asset, gameObject.transform);
         *  modelManager.bundles.Add(bundle);
         *  modelManager.loadingBunles.Remove(ABName);
         *  mover.modelName = ABName;
         *  Debug.Log("is OBJ");
         *  preloader.Loaded();
         * }
         * else
         * {
         *  Debug.Log("Check asset name");
         * }*/

#if UNITY_IOS
        BundleFullURL = PlayerPrefs.GetString("ApiUrl") + "/media/3d/" + ABName + "/ios/bundle";
#endif
#if PLATFORM_ANDROID
        BundleFullURL = PlayerPrefs.GetString("ApiUrl") + "/media/3d/" + ABName + "/android/bundle";
#endif
        Debug.Log("Load Bundle Path = " + BundleFullURL);

        CachedAssetBundle cab = new CachedAssetBundle(ABName, new Hash128(0, 0));
        using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(BundleFullURL, cab))
        {
            preloader.LoadPercent(uwr);
            yield return(uwr.SendWebRequest());

            if (uwr.isNetworkError || uwr.isHttpError)
            {
                Debug.Log(uwr.error);
                preloader.CantLoad();
                preloader.Loaded();
                GetComponent <Collider>().enabled = false;
                GetComponent <Mover>().enabled    = false;
            }
            else
            {
                // Get downloaded asset bundle
                AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
                if (bundle.Contains(AssetName))
                {
                    Instantiate(bundle.LoadAssetAsync(AssetName).asset, gameObject.transform);
                    modelManager.bundles.Add(bundle);
                    modelManager.loadingBunles.Remove(ABName);
                    mover.modelName = ABName;
                    Debug.Log("is OBJ");
                    preloader.Loaded();
                }
                else
                {
                    Debug.Log("Check asset name");
                    preloader.CantLoad();
                    preloader.Loaded();
                    GetComponent <Collider>().enabled = false;
                    GetComponent <Mover>().enabled    = false;
                }
            }
        }
    }