Exemplo n.º 1
0
        private void DoWaitingDataUpdate()
        {
            while (dataWaitingQueue.Count > 0 && operations.Count < MaxLoadingCount)
            {
                AssetLoaderData data = dataWaitingQueue.Dequeue();
                StartLoadingData(data);
                data.State = AssetLoaderDataState.Loading;
                dataLoadingList.Add(data);

                DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::DoWaitingDataUpdate->Start Load Data.data = {data}");
            }
        }
Exemplo n.º 2
0
 protected override void StartLoadingData(AssetLoaderData data)
 {
     for (int i = 0; i < data.Paths.Length; ++i)
     {
         string assetPath = data.Paths[i];
         if (!assetNodeDic.TryGetValue(assetPath, out AAssetNode assetNode))
         {
             assetNode = CreateAssetNode(assetPath);
         }
         assetNode.RetainRef();
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// 按批量方式进行资源的加载
        /// 如果指定使用标签进行资源加载,则会忽略<paramref name="addresses"/>的值
        /// </summary>
        /// <param name="label">加载设定指定标签的资源</param>
        /// <param name="addresses">资源加载地址</param>
        /// <param name="isInstance">是否需要实例化</param>
        /// <param name="complete">单个资源加载完毕后回调</param>
        /// <param name="batchComplete">所有资源加载完毕后回调</param>
        /// <param name="progress">单个资源加载进度回调</param>
        /// <param name="batchProgress">所有资源加载进度回调</param>
        /// <param name="priority">优先级</param>
        /// <param name="userData">自定义参数</param>
        /// <returns></returns>
        internal AssetHandler LoadBatchAssetAsync(
            string label,
            string[] addresses,
            bool isInstance,
            OnAssetLoadComplete complete,
            OnBatchAssetLoadComplete batchComplete,
            OnAssetLoadProgress progress,
            OnBatchAssetsLoadProgress batchProgress,
            AssetLoaderPriority priority,
            SystemObject userData)
        {
            //如果指定按标签加载资源,则查找标记为指定标签的所有资源
            if (!string.IsNullOrEmpty(label))
            {
                addresses = addressConfig.GetAddressesByLabel(label);
                DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::LoadBatchAssetAsync->Load asset by label.label = {label},addresses = {string.Join(",",addresses)}");
            }

            if (addresses == null || addresses.Length == 0)
            {
                DebugLog.Error(AssetConst.LOGGER_NAME, "AAssetLoader::LoadBatchAssetAsync->addresses is null");
                return(null);
            }
            //获取资源真实的路径
            string[] paths = addressConfig.GetPathsByAddresses(addresses);
            if (paths == null || paths.Length == 0)
            {
                DebugLog.Error(AssetConst.LOGGER_NAME, "AssetLoader::LoadBatchAssetAsync->paths is null");
                return(null);
            }
            else
            {
                DebugLog.Debug(AssetConst.LOGGER_NAME, $"AssetLoader::LoadBatchAssetAsync->find assetPath by address.addresses = {string.Join(",", addresses)},path = {string.Join(",",paths)}");
            }

            if (dataWaitingQueue.Count >= dataWaitingQueue.MaxSize)
            {
                dataWaitingQueue.Resize(dataWaitingQueue.MaxSize * 2);
                DebugLog.Debug(AssetConst.LOGGER_NAME, "AssetLoader::LoadBatchAssetAsync->Reset the queue size.");
            }

            AssetLoaderData data = dataPool.Get();

            data.InitData(label, addresses, paths, isInstance, complete, progress, batchComplete, batchProgress, userData);
            data.State = AssetLoaderDataState.Waiting;
            dataWaitingQueue.Enqueue(data, (float)priority);

            return(data.Handler);
        }
Exemplo n.º 4
0
        protected override void OnDataUpdate(AssetLoaderData data)
        {
            if (data.State == AssetLoaderDataState.Canceled || data.State == AssetLoaderDataState.Error)
            {
                foreach (var path in data.Paths)
                {
                    if (!string.IsNullOrEmpty(path))
                    {
                        assetNodeDic[path].ReleaseRef();
                    }
                }
            }
            else if (data.State == AssetLoaderDataState.Loading)
            {
                bool isComplete        = true;
                bool isProgressChanged = false;
                for (int i = 0; i < data.Paths.Length; ++i)
                {
                    string path = data.Paths[i];
                    if (string.IsNullOrEmpty(path))
                    {
                        continue;
                    }

                    AAssetNode assetNode = assetNodeDic[path];
                    if (assetNode.IsDone())
                    {
                        data.DoComplete(i, assetNode);
                        assetNode.ReleaseRef();
                    }
                    else
                    {
                        float progress = GetAssetProgress(path);
                        data.DoProgress(i, progress);

                        isProgressChanged = true;
                        isComplete        = false;
                    }
                }
                if (isProgressChanged)
                {
                    data.DoBatchProgress();
                }
                if (isComplete)
                {
                    data.DoBatchComplete();
                }
            }
        }
Exemplo n.º 5
0
 private void DoLoadingDataUpdate()
 {
     if (dataLoadingList.Count > 0)
     {
         for (int i = dataLoadingList.Count - 1; i >= 0; --i)
         {
             AssetLoaderData data = dataLoadingList[i];
             OnDataUpdate(data);
             if (data.State >= AssetLoaderDataState.Finished)
             {
                 dataLoadingList.RemoveAt(i);
                 dataPool.Release(data);
             }
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// 子类需要重写,用于检查资源当前状况
 /// </summary>
 /// <param name="data"></param>
 protected abstract void OnDataUpdate(AssetLoaderData data);
Exemplo n.º 7
0
 /// <summary>
 /// 开始加载指定的资源,子类需要重写
 /// </summary>
 /// <param name="data"></param>
 protected abstract void StartLoadingData(AssetLoaderData data);