示例#1
0
        /// <summary>
        /// 检查是否已在缓存
        /// </summary>
        /// <param name="group">加载组</param>
        /// <param name="name">AssetBundle名称</param>
        /// <param name="callback">完成回调</param>
        /// <param name="persistent">是否常驻</param>
        /// <param name="async">是否异步</param>
        /// <returns>已缓存(是-引用计数+1,并返回true, 否-返回false)</returns>
        public bool CheckAssetBundleInfo(LoaderGroup group, string name, LoaderGroupCompleteCallback callback,
                                         bool persistent, bool async)
        {
            AssetBundleInfo assetBundleInfo = GetAssetBundleInfo(name, persistent);

            if (null == assetBundleInfo)
            {
                AddAssetBundleInfo(name, persistent);
                return(false);
            }

            if (null == assetBundleInfo.assetBundle)
            {
                return(false);
            }

            if (null != callback)
            {
                if (!async)
                {
                    callback(group, assetBundleInfo);
                }
                else
                {
                    m_LoaderTask.AddAsyncCallback(callback, group, assetBundleInfo);
                }
            }

            return(true);
        }
示例#2
0
        /// <summary>
        /// 添加加载任务
        /// </summary>
        /// <param name="group">加载组</param>
        /// <param name="type">类型</param>
        /// <param name="path">路径</param>
        /// <param name="param">附加参数</param>
        /// <param name="completeCallback">回调</param>
        /// <param name="async">异步</param>
        /// <param name="priority">优先级</param>
        /// <param name="insert">插入</param>
        /// <returns></returns>
        public void AddLoadTask(LoaderGroup group, LoaderType type, string path, object param,
                                LoaderGroupCompleteCallback completeCallback, bool async,
                                LoadPriority priority = LoadPriority.Normal, bool insert = false)
        {
            if (!async)
            {
                Loader loader = GetLoader(type, path, param, false);
                PushCallback(loader, (data) =>
                {
                    completeCallback?.Invoke(group, data);
                });
                loader.Start();

                ReleaseLoader(loader);

                return;
            }

            if (group == null)
            {
                group = PopGroup(priority);
            }

            group.Add(type, path, param, completeCallback, true, insert);
        }
示例#3
0
        /// <summary>
        /// 更新
        /// </summary>
        private void UpdateGroup()
        {
            int index = 0;

            while (index < m_ListLoaderGroups.Count)
            {
                LoaderGroup group = m_ListLoaderGroups[index];
                group.Update();

                if (group.isFinish)
                {
                    LoaderGroupPool.Release(group);
                    m_ListLoaderGroups.RemoveAt(index);
                }
                else
                {
                    ++index;
                }
            }

            while (m_ListLoaderGroups.Count < kMaxGroupCount)
            {
                if (!StartNextGroup())
                {
                    break;
                }
            }
        }
示例#4
0
        /// <summary>
        /// 开始下一组
        /// </summary>
        /// <returns></returns>
        private bool StartNextGroup()
        {
            LoaderGroup loaderGroup = null;

            for (int i = (int)LoadPriority.Quantity - 1; i >= 0; --i)
            {
                Queue <LoaderGroup> groups = m_DicLoaderGroupWaits[(LoadPriority)i];
                if (groups.Count == 0)
                {
                    continue;
                }

                loaderGroup = groups.Dequeue();
                break;
            }

            if (loaderGroup == null)
            {
                return(false);
            }

            m_ListLoaderGroups.Add(loaderGroup);
            loaderGroup.Start();

            return(true);
        }
示例#5
0
        /// <summary>
        /// 获得加载组
        /// </summary>
        /// <returns></returns>
        public LoaderGroup PopGroup(LoadPriority priority = LoadPriority.Normal)
        {
            LoaderGroup group = LoaderGroupPool.Get(this);

            group.priority = priority;
            m_DicLoaderGroupWaits[priority].Enqueue(group);
            return(group);
        }
示例#6
0
        /// <summary>
        /// 增加异步回调
        /// </summary>
        /// <param name="callback">回调</param>
        /// <param name="group">加载组</param>
        /// <param name="data">资源对象</param>
        public void AddAsyncCallback(LoaderGroupCompleteCallback callback, LoaderGroup group, object data)
        {
            if (null == callback)
            {
                return;
            }

            AsyncCallbackInfo info = new AsyncCallbackInfo
            {
                completeCallback = callback,
                Group            = group,
                Data             = data
            };

            m_AsyncCallbackInfos.Add(info);
        }