/// <summary>
        /// 开始加载
        /// </summary>
        private IEnumerator Load(LoadRequest request)
        {
            Texture2D[] textures = new Texture2D[m_FilePathStrs.Length];

            for (int i = 0; i < m_FilePathStrs.Length; i++)
            {
                var file = string.Format(m_FilePathStrs[i], request.PageX >> request.MipLevel, request.PageY >> request.MipLevel, request.MipLevel);
                var www  = UnityWebRequestTexture.GetTexture(file);
                yield return(www.SendWebRequest());

                if (!www.isNetworkError && !www.isHttpError)
                {
                    textures[i]            = ((DownloadHandlerTexture)www.downloadHandler).texture;
                    Stat.TotalDownladSize += (float)www.downloadedBytes / 1024.0f / 1024.0f;
                }
                else
                {
                    Debug.LogWarningFormat("Load file({0}) failed: {1}", file, www.error);
                    Stat.TotalFailCount++;
                }
            }

            m_RuningRequests.Remove(request);
            OnLoadComplete?.Invoke(request, textures);
        }
        /// <summary>
        /// 新建加载请求
        /// </summary>
        public LoadRequest Request(int x, int y, int mip)
        {
            // 是否已经在请求队列中
            foreach (var r in m_RuningRequests)
            {
                if (r.PageX == x && r.PageY == y && r.MipLevel == mip)
                {
                    return(null);
                }
            }
            foreach (var r in m_PendingRequests)
            {
                if (r.PageX == x && r.PageY == y && r.MipLevel == mip)
                {
                    return(null);
                }
            }

            // 加入待处理列表
            var request = new LoadRequest(x, y, mip);

            m_PendingRequests.Add(request);

            Stat.TotalRequestCount++;

            return(request);
        }
Beispiel #3
0
        /// <summary>
        /// 加载完成回调
        /// </summary>
        private void OnLoadComplete(LoadRequest request, Texture2D[] textures)
        {
            // 找到对应页表
            var node = m_PageTable.Get(request.PageX, request.PageY, request.MipLevel);

            if (node == null || node.Payload.LoadRequest != request)
            {
                return;
            }

            node.Payload.LoadRequest = null;

            var id = m_TileTexture.RequestTile();

            m_TileTexture.UpdateTile(id, textures);

            node.Payload.TileIndex = id;
            m_ActivePages[id]      = node;
        }