예제 #1
0
        private void BeginOperation()
        {
            string path       = m_ProvideHandle.ResourceManager.TransformInternalId(m_ProvideHandle.Location);
            string bundleName = Path.GetFileName(path);

            m_bundleOffset = computeBundleOffset(bundleName);
            path           = AssetBundleMgr.GetInstance().TransformAssetBundleLocation(path, bundleName, m_Options.Hash);
            if (File.Exists(path) || !ResourceManagerConfig.IsPathRemote(path))
            {
                //如果文件存在  情况 1、Editor模式下文件存在  2、persistent下的文件存在  3、streaming asset目录下
                m_RequestOperation            = AssetBundle.LoadFromFileAsync(path, m_Options == null ? 0 : m_Options.Crc, (ulong)m_bundleOffset);
                m_RequestOperation.completed += LocalRequestOperationCompleted;
            }
            else if (AssetBundleMgr.GetInstance().IsCached(bundleName, m_Options.Hash))
            {
                //persistent目录下ab是否存在,是否有缓存
                string cachePath = AssetBundleMgr.GetInstance().getCachedAssetBundlePath(bundleName);
                m_RequestOperation            = AssetBundle.LoadFromFileAsync(cachePath, m_Options == null ? 0 : m_Options.Crc, (ulong)m_bundleOffset);
                m_RequestOperation.completed += LocalRequestOperationCompleted;
            }
            else if (ResourceManagerConfig.ShouldPathUseWebRequest(path))
            {
                // 文件真的需要从网络上下载
                var req = CreateWebRequest(path);
                req.disposeDownloadHandlerOnDispose = false;
                m_WebRequestQueueOperation          = WebRequestQueue.QueueRequest(req);
                if (m_WebRequestQueueOperation.IsDone)
                {
                    m_RequestOperation            = m_WebRequestQueueOperation.Result;
                    m_RequestOperation.completed += WebRequestOperationCompleted;
                }
                else
                {
                    m_WebRequestQueueOperation.OnComplete += asyncOp =>
                    {
                        m_RequestOperation            = asyncOp;
                        m_RequestOperation.completed += WebRequestOperationCompleted;
                    };
                }
            }
            else
            {
                m_RequestOperation = null;
                m_ProvideHandle.Complete <AssetBundleEncryptResource>(null, false, new Exception(string.Format("Invalid path in AssetBundleEncryptResource: '{0}'.", path)));
            }
        }
예제 #2
0
        public static WebRequestQueueOperation QueueRequest(UnityWebRequest request)
        {
            WebRequestQueueOperation queueOperation = new WebRequestQueueOperation(request);

            if (s_ActiveRequests.Count < s_MaxRequest)
            {
                var webRequestAsyncOp = request.SendWebRequest();
                webRequestAsyncOp.completed += OnWebAsyncOpComplete;
                s_ActiveRequests.Add(webRequestAsyncOp);
                queueOperation.Complete(webRequestAsyncOp);
            }
            else
            {
                s_QueuedOperations.Enqueue(queueOperation);
            }

            return(queueOperation);
        }