/// <summary> /// 获得加载器 /// </summary> /// <param name="type">类型</param> /// <param name="path">路径</param> /// <param name="param">附加参数</param> /// <param name="async">异步</param> /// <returns>加载器</returns> public Loader PopLoader(Loader.LoaderType type, string path, object param, bool async) { LoaderData ld; if (!m_loaders.TryGetValue(path, out ld)) { if (m_pools[type].Count > 0) { ld = m_pools[type].Dequeue(); } if (ld == null) { ld = new LoaderData { Reference = 0, Loader = CreateLoader(type), Callbacks = new List <LoadMgr.LoadedHandler>() }; } ld.Loader.Init(path, param, null, OnLoadCompleted, async); m_loaders.Add(path, ld); } if (!async) { ld.Loader.IsAsync = false; } ++ld.Reference; return(ld.Loader); }
/// <summary> /// 添加加载任务 /// </summary> /// <param name="group">加载组</param> /// <param name="type">类型</param> /// <param name="path">路径</param> /// <param name="param">附加参数</param> /// <param name="onLoaded">回调</param> /// <param name="async">异步</param> /// <param name="priority">优先级</param> /// <param name="insert">插入</param> /// <returns></returns> public void AddLoadTask(LoaderGroup group, Loader.LoaderType type, string path, object param, LoadMgr.GroupLoadedCallback onLoaded, bool async, LoadMgr.LoadPriority priority = LoadMgr.LoadPriority.Normal, bool insert = false) { if (!async) { Loader loader = PopLoader(type, path, param, false); PushCallback(loader, (data) => { if (onLoaded != null) { onLoaded(group, data); } }); loader.Load(); PushLoader(loader); return; } if (group == null) { group = PopGroup(priority); } group.Add(type, path, param, onLoaded, true, insert); }
/// <summary> /// 创建加载器 /// </summary> /// <param name="type">类型</param> /// <returns>加载器</returns> private Loader CreateLoader(Loader.LoaderType type) { Loader loader = null; switch (type) { case Loader.LoaderType.Stream: loader = new StreamLoader(); break; case Loader.LoaderType.Asset: loader = new AssetLoader(); break; case Loader.LoaderType.Scene: loader = new SceneLoader(); break; case Loader.LoaderType.Resource: loader = new ResourceLoader(); break; case Loader.LoaderType.Bundle: if (ConstantData.EnableCache) { loader = new CacheBundleLoader(); } else { loader = new BundleLoader(); } break; case Loader.LoaderType.BundleAsset: loader = new BundleAssetLoader(); break; } return(loader); }
/// <summary> /// 添加任务 /// </summary> /// <param name="type">类型</param> /// <param name="path">路径</param> /// <param name="param">附加参数</param> /// <param name="onLoaded">回调</param> /// <param name="async">异步</param> /// <param name="insert">插队</param> public void Add(Loader.LoaderType type, string path, object param, LoadMgr.GroupLoadedCallback onLoaded, bool async, bool insert) { LoaderInfo loader = new LoaderInfo { Loader = m_task.PopLoader(type, path, param, async), Callback = onLoaded }; if (insert) { m_loaders.Insert(0, loader); } else { m_loaders.Add(loader); } if (InLoading && IsFinish) { IsFinish = false; LoadNext(); } }