Пример #1
0
    /// <summary>
    /// 资源加载模块初始化
    /// </summary>
    public override void init()
    {
        base.init();
        // 初始化ABLoader和ABInfo可重用的基础数量
        AssetBundleLoaderFactory.initialize(20);             // 考虑到大部分都是采用同步加载,所以AssetBundleLoader并不需要初始化太多
        AssetBundleInfoFactory.initialize(200);
        mAssetBundleDpMap = new Dictionary <string, string[]>();

        ResLoadMode = ResourceLoadMode.AssetBundle;

        mABRequestTaskMap = new Dictionary <string, AssetBundleLoader>();
        mUnsedABInfoList  = new List <AbstractResourceInfo>();

        // TODO: 根据设备设定相关参数,改成读表控制
        mCheckUnsedABTimeInterval    = 5.0f;
        mWaitForCheckUnsedABInterval = new WaitForSeconds(mCheckUnsedABTimeInterval);
        mMaxUnloadABNumberPerFrame   = 10;
        mABMinimumLifeTime           = 20.0f;
        mABRecycleFPSThreshold       = 20;

        MaxMaximumAsyncCoroutine  = 2;
        AssetBundleAsyncQueueList = new List <AssetBundleAsyncQueue>();
        for (int i = 0; i < MaxMaximumAsyncCoroutine; i++)
        {
            var abaq = new AssetBundleAsyncQueue();
            AssetBundleAsyncQueueList.Add(abaq);
            abaq.startABAsyncLoad();
        }
        loadAllDpInfo();
    }
Пример #2
0
    /// <summary>
    /// 创建AB资源加载对象
    /// </summary>
    /// <param name="resname">资源名</param>
    /// <returns></returns>
    private AssetBundleLoader createABLoader(string resname)
    {
        var depabnames = getAssetBundleDpInfo(resname);
        var loader     = AssetBundleLoaderFactory.create();

        loader.AssetBundleName = resname;
        loader.DepABNames      = depabnames;
        return(loader);
    }
Пример #3
0
    /// <summary>
    /// 创建AB资源加载对象
    /// </summary>
    /// <param name="abpath">AB路径</param>
    /// <returns></returns>
    private AssetBundleLoader createABLoader(string abpath)
    {
        var depabnames = getAssetBundleDpInfo(abpath);
        var loader     = AssetBundleLoaderFactory.create();

        loader.AssetBundlePath = abpath;
        loader.DepABPaths      = depabnames;
        if (depabnames != null)
        {
            DIYLog.Log($"{abpath}资源依赖的AB资源如下:");
            foreach (var depabname in depabnames)
            {
                DIYLog.Log($"{depabname}");
            }
        }
        return(loader);
    }
Пример #4
0
    /// <summary>
    /// 创建AB资源加载对象
    /// </summary>
    /// <param name="resname">资源名</param>
    /// <returns></returns>
    private AssetBundleLoader createABLoader(string resname)
    {
        var depabnames = getAssetBundleDpInfo(resname);
        var loader     = AssetBundleLoaderFactory.create();

        loader.AssetBundleName = resname;
        loader.DepABNames      = depabnames;
        if (depabnames != null)
        {
            DIYLog.Log($"{resname}资源依赖的AB资源如下:");
            foreach (var depabname in depabnames)
            {
                DIYLog.Log($"{depabname}");
            }
        }
        return(loader);
    }
    /// <summary>
    /// 所有AB加载完成(自身和依赖AB)
    /// </summary>
    private void allABLoadedComplete()
    {
        ResourceLogger.log(string.Format("AB:{0}所有AB加载完成!", AssetBundleName));

        // 所有AB加载完添加依赖AB索引信息并通知上层可以使用了
        foreach (var dploader in mDepAssetBundleInfoList)
        {
            mABInfo.addDependency(dploader);
        }

        LoadState = ResourceLoadState.AllComplete;

        // 所有AB加载完成才算AB Ready可以使用
        mABInfo.mIsReady = true;

        // 通知上层ab加载完成,可以开始加载具体的asset
        LoadABCompleteCallBack(mABInfo);
        LoadABCompleteCallBack = null;

        // 自身AB以及依赖AB加载完成后,AssetBundleLoader的任务就完成了,回收重用
        AssetBundleLoaderFactory.recycle(this);
    }