コード例 #1
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();
        }
    }