Beispiel #1
0
 /// <summary>
 /// 真正的请求资源
 /// </summary>
 /// <param name="respath">资源AB路径</param>
 /// <param name="completehandler">加载完成上层回调</param>
 /// <param name="loadtype">资源加载类型</param>
 /// <param name="loadmethod">资源加载方式</param>
 protected override void realRequestResource(string respath, LoadResourceCompleteHandler completehandler, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync)
 {
     // 如果资源已经加载完成,直接返回
     if (mAllLoadedResourceInfoMap[ResourceLoadType.NormalLoad].ContainsKey(respath))
     {
         completehandler(mAllLoadedResourceInfoMap[ResourceLoadType.NormalLoad][respath]);
         if (loadtype > ResourceLoadType.NormalLoad)
         {
             updateLoadedResourceInfoLoadType(respath, ResourceLoadType.NormalLoad, loadtype);
         }
     }
     else if (mAllLoadedResourceInfoMap[ResourceLoadType.Preload].ContainsKey(respath))
     {
         completehandler(mAllLoadedResourceInfoMap[ResourceLoadType.Preload][respath]);
         if (loadtype > ResourceLoadType.Preload)
         {
             updateLoadedResourceInfoLoadType(respath, ResourceLoadType.Preload, loadtype);
         }
     }
     else if (mAllLoadedResourceInfoMap[ResourceLoadType.PermanentLoad].ContainsKey(respath))
     {
         completehandler(mAllLoadedResourceInfoMap[ResourceLoadType.PermanentLoad][respath]);
     }
     else
     {
         AssetDatabaseLoader adloader = createADLoader(respath);
         //暂时默认都当同步加载,不支持异步模拟
         adloader.LoadMethod = loadmethod;
         adloader.LoadType   = loadtype;
         adloader.LoadResourceCompleteCallBack     = completehandler;
         adloader.LoadSelfResourceCompleteNotifier = onResourceLoadCompleteNotifier;
         mResourceRequestTaskMap.Add(respath, adloader);
         adloader.startLoad();
     }
 }
Beispiel #2
0
 /// <summary>
 /// 真正的请求资源
 /// </summary>
 /// <param name="resname">资源AB名</param>
 /// <param name="completehandler">加载完成上层回调</param>
 /// <param name="loadtype">资源加载类型</param>
 /// <param name="loadmethod">资源加载方式</param>
 protected override void realRequestResource(string resname, LoadResourceCompleteHandler completehandler, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync)
 {
     // 如果资源已经加载完成,直接返回
     if (mAllLoadedResourceInfoMap[ResourceLoadType.NormalLoad].ContainsKey(resname))
     {
         completehandler(mAllLoadedResourceInfoMap[ResourceLoadType.NormalLoad][resname]);
         if (loadtype > ResourceLoadType.NormalLoad)
         {
             updateLoadedResourceInfoLoadType(resname, ResourceLoadType.NormalLoad, loadtype);
         }
     }
     else if (mAllLoadedResourceInfoMap[ResourceLoadType.Preload].ContainsKey(resname))
     {
         completehandler(mAllLoadedResourceInfoMap[ResourceLoadType.Preload][resname]);
         if (loadtype > ResourceLoadType.Preload)
         {
             updateLoadedResourceInfoLoadType(resname, ResourceLoadType.Preload, loadtype);
         }
     }
     else if (mAllLoadedResourceInfoMap[ResourceLoadType.PermanentLoad].ContainsKey(resname))
     {
         completehandler(mAllLoadedResourceInfoMap[ResourceLoadType.PermanentLoad][resname]);
     }
     else
     {
         // 确保同一个资源加载的Loader是同一个
         // 保证同一个资源加载完成时上层所有加载该资源的回调正确
         AssetBundleLoader abloader = null;
         if (mABRequestTaskMap.ContainsKey(resname))
         {
             abloader = mABRequestTaskMap[resname];
             // 之前有请求resname资源,但还未完成
             // 比如先异步请求resname,在异步完成前来了一个同步请求resname
             // 修改加载方式并添加回调,调用同步加载方式,异步加载会在同步加载完成时一起回调
             abloader.LoadMethod                 = loadmethod;
             abloader.LoadType                   = loadtype;
             abloader.LoadABCompleteCallBack    += completehandler;
             abloader.LoadSelfABCompleteNotifier = onABLoadCompleteNotifier;
             if (loadmethod == ResourceLoadMethod.Sync)
             {
                 ResourceLogger.log(string.Format("请求同步加载一个正在异步加载的资源 : {0}", abloader.AssetBundleName));
                 //重置AB加载状态,走同步加载模式
                 abloader.LoadState = ResourceLoadState.None;
                 abloader.startLoad();
             }
         }
         else
         {
             abloader                            = createABLoader(resname);
             abloader.LoadMethod                 = loadmethod;
             abloader.LoadType                   = loadtype;
             abloader.LoadABCompleteCallBack     = completehandler;
             abloader.LoadSelfABCompleteNotifier = onABLoadCompleteNotifier;
             mABRequestTaskMap.Add(resname, abloader);
             abloader.startLoad();
         }
     }
 }
Beispiel #3
0
 /// <summary>
 /// 请求资源
 /// 上层资源加载统一入口
 /// </summary>
 /// <param name="respath">资源AB路径</param>
 /// <param name="completehandler">加载完成上层回调</param>
 /// <param name="loadtype">资源加载类型</param>
 /// <param name="loadmethod">资源加载方式</param>
 public void requstResource(string respath, LoadResourceCompleteHandler completehandler, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync)
 {
     // 在白名单里的资源一律以预加载形式加载,
     // 避免因为上层逻辑错误加载后被频繁加载卸载
     if (mResourceWhileListMap.ContainsKey(respath))
     {
         loadtype = ResourceLoadType.Preload;
     }
     realRequestResource(respath, completehandler, loadtype, loadmethod);
 }
Beispiel #4
0
 /// <summary>
 /// 真正的请求资源(由不同的资源模块去实现)
 /// </summary>
 /// <param name="resname">资源AB名</param>
 /// <param name="completehandler">加载完成上层回调</param>
 /// <param name="loadtype">资源加载类型</param>
 /// <param name="loadmethod">资源加载方式</param>
 protected abstract void realRequestResource(string resname, LoadResourceCompleteHandler completehandler, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync);
Beispiel #5
0
    /// <summary>
    /// 真正的请求资源
    /// </summary>
    /// <param name="respath">资源AB路径</param>
    /// <param name="completehandler">加载完成上层回调</param>
    /// <param name="loadtype">资源加载类型</param>
    /// <param name="loadmethod">资源加载方式</param>
    protected override void realRequestResource(string respath, LoadResourceCompleteHandler completehandler, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync)
    {
        // AB运行时统一转成小写,避免和AB打包那方输出的信息不一致
        respath = respath.ToLower();
        var abpath = string.Empty;

        // 因为依赖AB加载也是走统一入口,所以要区分是AB路径还是Asset路径
        if (!mAssetBundleBuildInfo.isABPath(respath))
        {
            // AB依赖信息文件和AB打包
            abpath = getAssetPathAssetBundleName(respath);
        }
        else
        {
            abpath = respath;
        }
        // 如果资源已经加载完成,直接返回
        if (mAllLoadedResourceInfoMap[ResourceLoadType.NormalLoad].ContainsKey(abpath))
        {
            completehandler(mAllLoadedResourceInfoMap[ResourceLoadType.NormalLoad][abpath]);
            if (loadtype > ResourceLoadType.NormalLoad)
            {
                updateLoadedResourceInfoLoadType(abpath, ResourceLoadType.NormalLoad, loadtype);
            }
        }
        else if (mAllLoadedResourceInfoMap[ResourceLoadType.Preload].ContainsKey(abpath))
        {
            completehandler(mAllLoadedResourceInfoMap[ResourceLoadType.Preload][abpath]);
            if (loadtype > ResourceLoadType.Preload)
            {
                updateLoadedResourceInfoLoadType(abpath, ResourceLoadType.Preload, loadtype);
            }
        }
        else if (mAllLoadedResourceInfoMap[ResourceLoadType.PermanentLoad].ContainsKey(abpath))
        {
            completehandler(mAllLoadedResourceInfoMap[ResourceLoadType.PermanentLoad][abpath]);
        }
        else
        {
            // 确保同一个资源加载的Loader是同一个
            // 保证同一个资源加载完成时上层所有加载该资源的回调正确
            AssetBundleLoader abloader = null;
            if (mABRequestTaskMap.ContainsKey(abpath))
            {
                abloader = mABRequestTaskMap[abpath];
                // 之前有请求resname资源,但还未完成
                // 比如先异步请求resname,在异步完成前来了一个同步请求resname
                // 修改加载方式并添加回调,调用同步加载方式,异步加载会在同步加载完成时一起回调
                abloader.LoadMethod                 = loadmethod;
                abloader.LoadType                   = loadtype;
                abloader.LoadABCompleteCallBack    += completehandler;
                abloader.LoadSelfABCompleteNotifier = onABLoadCompleteNotifier;
                if (loadmethod == ResourceLoadMethod.Sync)
                {
                    ResourceLogger.log(string.Format("请求同步加载一个异步加载状态:{0}的资源 : {1}", abloader.LoadState.ToString(), abloader.AssetBundlePath));
                    //重置AB加载状态,走同步加载模式
                    abloader.LoadState = ResourceLoadState.None;
                    abloader.startLoad();
                }
            }
            else
            {
                abloader                            = createABLoader(abpath);
                abloader.LoadMethod                 = loadmethod;
                abloader.LoadType                   = loadtype;
                abloader.LoadABCompleteCallBack     = completehandler;
                abloader.LoadSelfABCompleteNotifier = onABLoadCompleteNotifier;
                mABRequestTaskMap.Add(abpath, abloader);
                abloader.startLoad();
            }
        }
    }