Ejemplo n.º 1
0
        void ProcessFinishedOperation(AssetBundleLoadOperation operation)
        {
            AssetBundleDownloadOperation download = operation as AssetBundleDownloadOperation;

            if (download == null)
            {
                return;
            }

            if (download.error == null)
            {
                m_LoadedAssetBundles.Add(download.assetBundleName, download.assetBundle);
            }
            else
            {
                string msg = string.Format("Failed downloading bundle {0} from {1}: {2}",
                                           download.assetBundleName, download.GetSourceURL(), download.error);
                m_DownloadingErrors.Add(download.assetBundleName, msg);
            }
            m_DownloadingBundles.Remove(download.assetBundleName);
        }
Ejemplo n.º 2
0
        void ProcessFinishedOperation(AssetBundleLoadOperation operation)
        {
            AssetBundleDownloadOperation download = operation as AssetBundleDownloadOperation;

            if (download == null)
            {
                return;
            }

            if (String.IsNullOrEmpty(download.error))
            {
                //Debug.Log("[AssetBundleManager] processed downloaded bundle " + download.assetBundleName);
                m_LoadedAssetBundles.Add(download.assetBundleName, download.assetBundle);
            }
            else
            {
                string msg = string.Format("Failed downloading bundle {0} from {1}: {2}",
                                           download.assetBundleName, download.GetSourceURL(), download.error);
                m_DownloadingErrors.Add(download.assetBundleName, msg);
            }
            m_DownloadingBundles.Remove(download.assetBundleName);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the download progress of an assetbundle, optionally including any bundles it is dependent on
        /// </summary>
        static public float GetBundleDownloadProgress(string assetBundleName, bool andDependencies)
        {
            float  overallProgress = 0;
            string error;

            if (m_DownloadingErrors.TryGetValue(assetBundleName, out error))
            {
                Debug.LogWarning(error);
                return(0);
            }

            if (m_LoadedAssetBundles.ContainsKey(assetBundleName))
            {
                overallProgress = 1f;
            }
            else
            {
                //find out its progress
                foreach (AssetBundleLoadOperation operation in m_InProgressOperations)
                {
                    if (operation.GetType() == typeof(AssetBundleDownloadOperation) || operation.GetType().IsSubclassOf(typeof(AssetBundleDownloadOperation)))
                    {
                        AssetBundleDownloadOperation typedOperation = (AssetBundleDownloadOperation)operation;
                        if (typedOperation.assetBundleName == assetBundleName)
                        {
                            overallProgress = typedOperation.downloadProgress == 1f ? 0.99f : typedOperation.downloadProgress;
                        }
                    }
                }
            }
            //deal with dependencies if necessary
            if (andDependencies)
            {
                string[] dependencies = null;
                m_Dependencies.TryGetValue(assetBundleName, out dependencies);
                if (dependencies != null)
                {
                    if (dependencies.Length > 0)
                    {
                        foreach (string dependency in dependencies)
                        {
                            if (m_LoadedAssetBundles.ContainsKey(dependency))
                            {
                                overallProgress += 1;
                            }
                            else                             //It must be in progress
                            {
                                foreach (AssetBundleLoadOperation operation in m_InProgressOperations)
                                {
                                    if (operation.GetType() == typeof(AssetBundleDownloadOperation) || operation.GetType().IsSubclassOf(typeof(AssetBundleDownloadOperation)))
                                    {
                                        AssetBundleDownloadOperation typedOperation = (AssetBundleDownloadOperation)operation;
                                        if (typedOperation.assetBundleName == dependency)
                                        {
                                            overallProgress += typedOperation.downloadProgress == 1f ? 0.99f : typedOperation.downloadProgress;
                                        }
                                    }
                                }
                            }
                        }
                        //divide by num dependencies +1
                        overallProgress = overallProgress / (dependencies.Length + 1);
                    }
                }
            }
            return(overallProgress);
        }