// Returns true if more Update calls are required.
        public override bool Update()
        {
            if (m_Request != null)
            {
                return(false);
            }

            LoadedAssetBundle loadedBundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);

            if (loadedBundle != null)
            {
                /// When asset bundle download fails this throws an exception but this should be caught above now
                m_Request = loadedBundle.m_AssetBundle.LoadAssetAsync(m_AssetName, m_Type);
                return(false);
            }
            else
            {
                return(true);
            }
        }
示例#2
0
        protected override void FinishDownload()
        {
            error = m_WWW.error;
            if (!string.IsNullOrEmpty(error))
            {
                Debug.LogWarning("[AssetBundleLoadOperation.AssetBundleDownloadFromWebOperation] URL was " + m_WWW.url + " error was " + error);
                return;
            }

            if (!m_isJsonIndex)
            {
                bundle = m_WWW.assetBundle;
                if (bundle == null)
                {
                    Debug.LogWarning("[AssetBundleLoadOperation.AssetBundleDownloadFromWebOperation] " + assetBundleName + " was not a valid assetBundle");
                    m_WWW.Dispose();
                    m_WWW = null;
                }
                else if (!WasBundleEncrypted())
                {
                    assetBundle = new LoadedAssetBundle(m_WWW.assetBundle);
                    m_WWW.Dispose();
                    m_WWW = null;
                }
            }
            else
            {
                string indexData = m_WWW.text;
                if (indexData == "")
                {
                    Debug.LogWarning("[AssetBundleLoadOperation.AssetBundleDownloadFromWebOperation] The JSON AssetBundleIndex was empty");
                }
                else
                {
                    assetBundle = new LoadedAssetBundle(m_WWW.text);
                }
                m_WWW.Dispose();
                m_WWW = null;
            }
        }
示例#3
0
 // Returns true if more Update calls are required.
 public override bool Update()
 {
     //base.Update();
     if (m_Request == null)
     {
         LoadedAssetBundle loadedBundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);
         if (loadedBundle != null)
         {
             if (_isJsonIndex)
             {
                 AssetBundleManager.AssetBundleIndexObject = ScriptableObject.CreateInstance <AssetBundleIndex>();
                 JsonUtility.FromJsonOverwrite(loadedBundle.m_data, AssetBundleManager.AssetBundleIndexObject);
             }
             else
             {
                 if (loadedBundle.m_AssetBundle == null)
                 {
                     Debug.LogWarning("AssetBundle was null for " + m_AssetBundleName);
                     return(false);
                 }
                 m_Request = loadedBundle.m_AssetBundle.LoadAssetAsync <AssetBundleIndex>(m_AssetName);
             }
         }
     }
     if (m_Request != null && m_Request.isDone)
     {
         AssetBundleManager.AssetBundleIndexObject = GetAsset <AssetBundleIndex>();
         return(false);
     }
     if (AssetBundleManager.AssetBundleIndexObject != null)
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
示例#4
0
        /// <summary>
        /// Sets up download operation for the given asset bundle if it's not downloaded already.
        /// </summary>
        static protected bool LoadAssetBundleInternal(string assetBundleToFind, bool isLoadingAssetBundleIndex = false, bool useJsonIndex = false, string jsonIndexUrl = "")
        {
            //encrypted bundles have the suffix 'encrypted' appended to the name TODO this should probably go in the index though and be settable in the UMAAssetBundleManagerSettings window
            //string encryptedSuffix = BundleEncryptionKey != "" ? "encrypted" : "";
            string assetBundleToGet = assetBundleToFind;

            if (BundleEncryptionKey != "" && m_AssetBundleIndex != null)
            {
                assetBundleToGet = m_AssetBundleIndex.GetAssetBundleEncryptedName(assetBundleToFind);
                Debug.Log("assetBundleToFind was " + assetBundleToFind + " assetBundleToGet was " + assetBundleToGet);
            }
            else if (BundleEncryptionKey != "" && m_AssetBundleIndex == null)
            {
                assetBundleToGet = assetBundleToFind + "encrypted";
            }

            // Already loaded.
            LoadedAssetBundle bundle = null;

            m_LoadedAssetBundles.TryGetValue(assetBundleToFind, out bundle);            //encrypted or not this will have the assetbundlename without the 'encrypted' suffix
            if (bundle != null && bundle.m_AssetBundle != null)
            {
                bundle.m_ReferencedCount++;
                return(true);
            }

            // @TODO: Do we need to consider the referenced count of WWWs?
            // users can call LoadAssetAsync()/LoadLevelAsync() several times then wait them to be finished which might have duplicate WWWs.
            if (m_DownloadingBundles.Contains(assetBundleToFind))
            {
                return(true);
            }

            string bundleBaseDownloadingURL = GetAssetBundleBaseDownloadingURL(assetBundleToFind);

            //TODO These dont support encrypted bundles yet
            if (bundleBaseDownloadingURL.ToLower().StartsWith("odr://"))
            {
#if ENABLE_IOS_ON_DEMAND_RESOURCES
                Log(LogType.Info, "Requesting bundle " + assetBundleToGet + " through ODR");
                m_InProgressOperations.Add(new AssetBundleDownloadFromODROperation(assetBundleToGet));
#else
                new ApplicationException("Can't load bundle " + assetBundleToFind + " through ODR: this Unity version or build target doesn't support it.");
#endif
            }
            else if (bundleBaseDownloadingURL.ToLower().StartsWith("res://"))
            {
#if ENABLE_IOS_APP_SLICING
                Log(LogType.Info, "Requesting bundle " + assetBundleToGet + " through asset catalog");
                m_InProgressOperations.Add(new AssetBundleOpenFromAssetCatalogOperation(assetBundleToGet));
#else
                new ApplicationException("Can't load bundle " + assetBundleToFind + " through asset catalog: this Unity version or build target doesn't support it.");
#endif
            }
            else
            {
                if (!bundleBaseDownloadingURL.EndsWith("/"))
                {
                    bundleBaseDownloadingURL += "/";
                }

                string url = bundleBaseDownloadingURL + assetBundleToGet;

                WWW download = null;
                // For index assetbundle, always download it as we don't have hash for it.
                //TODO make something to test if there is and internet connection and if not try to get a cached version of this so we can still access the stuff that has been previously cached
                //TODO2 Make the index cache somewhere when it is downloaded.
                if (isLoadingAssetBundleIndex)
                {
                    if (useJsonIndex && jsonIndexUrl != "")
                    {
                        url = jsonIndexUrl.Replace("[PLATFORM]", Utility.GetPlatformName());
                    }
                    else if (useJsonIndex)
                    {
                        url = url + ".json";
                    }
                    download = new WWW(url);
                    if (!String.IsNullOrEmpty(download.error) || download == null)
                    {
                        if (!String.IsNullOrEmpty(download.error))
                        {
                            Log(LogType.Warning, download.error);
                        }
                        else
                        {
                            Log(LogType.Warning, " index new WWW(url) was NULL");
                        }
                    }
                }
                else
                {
                    download = WWW.LoadFromCacheOrDownload(url, m_AssetBundleIndex.GetAssetBundleHash(assetBundleToFind), 0);
                }
                m_InProgressOperations.Add(new AssetBundleDownloadFromWebOperation(assetBundleToFind /* + encryptedSuffix*/, download, useJsonIndex));
            }

            m_DownloadingBundles.Add(assetBundleToFind);

            return(false);
        }
示例#5
0
        /// <summary>
        /// Retrieves an asset bundle that has previously been requested via LoadAssetBundle.
        /// Returns null if the asset bundle or one of its dependencies have not been downloaded yet.
        /// </summary>
        /// <param name="assetBundleName"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        static public LoadedAssetBundle GetLoadedAssetBundle(string assetBundleName, out string error)
        {
            if (m_DownloadingErrors.TryGetValue(assetBundleName, out error))
            {
                if (!error.StartsWith("-"))
                {
                    m_DownloadingErrors[assetBundleName] = "-" + error;
#if UNITY_EDITOR
                    if (assetBundleName == Utility.GetPlatformName().ToLower() + "index")
                    {
                        if (EditorPrefs.GetBool(Application.dataPath + "LocalAssetBundleServerEnabled") == false || SimpleWebServer.serverStarted == false)                      //when the user restarts Unity this might be true even if the server has not actually been started
                        {
                            if (SimulateAssetBundleInEditor)
                            {
                                //we already outputted a message in DynamicAssetloader
                            }
                            else
                            {
                                Debug.LogWarning("AssetBundleManager could not download the AssetBundleIndex from the Remote Server URL you have set in DynamicAssetLoader. Have you set the URL correctly and uploaded your AssetBundles?");
                                error = "AssetBundleManager could not download the AssetBundleIndex from the Remote Server URL you have set in DynamicAssetLoader. Have you set the URL correctly and uploaded your AssetBundles?";
                            }
                        }
                        else
                        {
                            //Otherwise the AssetBundles themselves will not have been built.
                            Debug.LogWarning("Switched to Simulation mode because no AssetBundles were found. Have you build them? (Go to 'Assets/AssetBundles/Build AssetBundles').");
                            error = "Switched to Simulation mode because no AssetBundles were found.Have you build them? (Go to 'Assets/AssetBundles/Build AssetBundles').";
                            //this needs to hide the loading infobox- or something needs too..
                        }
                        SimulateOverride = true;
                    }
                    else
#endif
                    Debug.LogWarning("Could not return " + assetBundleName + " because of error:" + error);
                }
                return(null);
            }

            LoadedAssetBundle bundle = null;
            m_LoadedAssetBundles.TryGetValue(assetBundleName, out bundle);
            if (bundle == null)
            {
                return(null);
            }

            // No dependencies are recorded, only the bundle itself is required.
            string[] dependencies = null;
            if (!m_Dependencies.TryGetValue(assetBundleName, out dependencies))
            {
                return(bundle);
            }

            // Otherwise Make sure all dependencies are loaded
            foreach (var dependency in dependencies)
            {
                if (m_DownloadingErrors.TryGetValue(dependency, out error))
                {
                    return(null);
                }
                // Wait all the dependent assetBundles being loaded.
                LoadedAssetBundle dependentBundle = null;
                m_LoadedAssetBundles.TryGetValue(dependency, out dependentBundle);
                if (dependentBundle == null)
                {
                    return(null);
                }
            }
            return(bundle);
        }
 // Returns true if more Update calls are required.
 public override bool Update()
 {
     //base.Update();
     if (m_Request == null)
     {
         LoadedAssetBundle loadedBundle = AssetBundleManager.GetLoadedAssetBundle(m_AssetBundleName, out m_DownloadingError);
         if (loadedBundle != null)
         {
             if (_isJsonIndex)
             {
                 AssetBundleManager.AssetBundleIndexObject = ScriptableObject.CreateInstance <AssetBundleIndex>();
                 JsonUtility.FromJsonOverwrite(loadedBundle.m_data, AssetBundleManager.AssetBundleIndexObject);
             }
             else
             {
                 if (loadedBundle.m_AssetBundle == null)
                 {
                     Debug.LogWarning("AssetBundle was null for " + m_AssetBundleName);
                     return(false);
                 }
                 m_Request = loadedBundle.m_AssetBundle.LoadAssetAsync <AssetBundleIndex>(m_AssetName);
             }
         }
     }
     if (m_Request != null && m_Request.isDone)
     {
         AssetBundleManager.AssetBundleIndexObject = GetAsset <AssetBundleIndex>();
         //If there is an AssetBundleManager.m_ConnectionChecker and it is set to m_ConnectionChecker.UseBundleIndexCaching
         //cache this so we can use it offline if we need to
         if (AssetBundleManager.ConnectionChecker != null && AssetBundleManager.ConnectionChecker.UseBundleIndexCaching == true)
         {
             if (AssetBundleManager.AssetBundleIndexObject != null)
             {
                 Debug.Log("Caching downloaded index with Build version " + AssetBundleManager.AssetBundleIndexObject.bundlesPlayerVersion);
                 var cachedIndexPath = Path.Combine(Application.persistentDataPath, "cachedBundleIndex");
                 if (!Directory.Exists(cachedIndexPath))
                 {
                     Directory.CreateDirectory(cachedIndexPath);
                 }
                 cachedIndexPath = Path.Combine(cachedIndexPath, m_AssetBundleName + ".json");
                 File.WriteAllText(cachedIndexPath, JsonUtility.ToJson(AssetBundleManager.AssetBundleIndexObject));
             }
         }
         return(false);
     }
     if (AssetBundleManager.AssetBundleIndexObject != null)
     {
         return(false);
     }
     else
     {
         // if there has been an error make this return false
         //It wont need any more updates and ABM needs to put it in failed downloads
         if (string.IsNullOrEmpty(m_DownloadingError))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }