예제 #1
0
    private static ResourcePackage GetResourcePackge(ResConfigData config)
    {
        ResourcePackage pkg = AllocResourcePackage(config.AssetBundleName);

        if (m_LoadedResourcePackage.Contains(pkg.instanceID))
        {
            pkg.AddRef();
        }
        else
        {
            string abName = config.AssetBundleName;
            string patch  = AssetBundleManager.FullAssetPackagePathRoot + config.AssetBundleName;

            UnionResConfigData unionRes = config as UnionResConfigData;
            if (unionRes != null)
            {
                patch  = unionRes.UnionFilePath;
                abName = unionRes.ShortUnionFilePath;
            }

            if (!m_RespackageTable.ContainsKey(abName))
            {
                AssetBudleLog("AssetBundle文件不存在!,路径:" + patch);
                return(pkg);
            }
            RemoveNeedToUnLoadPackage(pkg.instanceID);
            //异步加载的列表里有他,那么要强制同步加载了
            if (m_ResourcePackageRequestTable.Contains(pkg.instanceID))
            {
                m_ResourcePackageRequestTable.Remove(pkg.instanceID);
                if (pkg.isUpLoadToLoadingThread)
                {
                    pkg.AssetBundleInstance = pkg.fileRequest.assetBundle;
                }
                else
                {
                    pkg.isUpLoadToLoadingThread = true;
                    pkg.AssetBundleInstance     = LoadAssetBundle(patch, config);
                }
                RemoveFromAssetsFileUpLoadQueue(pkg.instanceID);
                RemoveAssetsFileProcessingList(pkg.instanceID);
                PushToResourcePackageCallBackList(pkg.instanceID);
            }
            else
            {
                AssetBundle pAssetBundle = LoadAssetBundle(patch, config);
                pkg.AssetBundleInstance = pAssetBundle;
            }
            pkg.filePatch = patch;
            pkg.AddRef();
            m_LoadedResourcePackage.Add(pkg.instanceID);
        }

        return(pkg);
    }
예제 #2
0
    /// <summary>
    /// 异步构建package
    /// </summary>
    /// <param name="reslutTable"></param>
    /// <param name="config"></param>
    /// <param name="resourcePackageCallBack"></param>
    /// <param name="UserCallBack"></param>
    /// <param name="userDataObj"></param>
    /// <returns></returns>
    private static void BuildPacakgeAsync(ref ResNode result, Dictionary <int, ResNode> reslutTable, ResConfigData config, System.Action <ResourcePackageCallBackObj> resourcePackageCallBack,
                                          System.Action <ResConfigData, ResNode, System.Object> UserCallBack, System.Object userDataObj, bool isPrefabResNode = false)
    {
        string patch = AssetBundleManager.FullAssetPackagePathRoot + config.AssetBundleName;

        UnionResConfigData unionRes = config as UnionResConfigData;
        string             abPath   = config.AssetBundleName;

        if (unionRes != null)
        {
            patch  = unionRes.UnionFilePath;
            abPath = unionRes.ShortUnionFilePath;
        }
        if (!m_RespackageTable.ContainsKey(abPath))
        {
            AssetBudleLog("AssetBundle文件不存在!,路径:" + patch);
            return;
        }

        result = AllocResNode(config.AssetGUID);

        result.StartLoadedTime();

        //预制体是预先创建好ResNode的,所以不能清除和增加引用,直接使用外部的即可
        if (!isPrefabResNode)
        {
            result.Clear();
            result.AddRef();
        }

        result.config  = config;
        result.isAsync = true;
        result.status  = ResNodeStatus.WatingForLoad;

        AssetRequest are = null;

        are = AllocAssetRequest(result.instanceID);
        m_LoadingAssetList.Add(result.instanceID);
        are.Clear();

        reslutTable.Add(result.instanceID, result);

        GenerateResCallBack(result, config, UserCallBack, userDataObj);

        ResourcePackage pakg = AllocResourcePackage(config.AssetBundleName);

        pakg.priority = config.priority;
        //已经有了
        if (m_LoadedResourcePackage.Contains(pakg.instanceID))
        {
            pakg.AddRef();
            pakg.AddAsyncCallBackData(resourcePackageCallBack, BuildResourcePackageCallBackObj(pakg, result, config, UserCallBack, userDataObj));

            PushToResourcePackageCallBackList(pakg.instanceID);
        }
        else
        {
            //如果卸载列表里,先移除掉,避免加载出来就被卸载了
            RemoveNeedToUnLoadPackage(pakg.instanceID);
            //没有开启异步加载
            if (!enabledAsyncLoadAssetFile)
            {
                pakg = GetResourcePackge(config);
                pakg.AddAsyncCallBackData(resourcePackageCallBack, BuildResourcePackageCallBackObj(pakg, result, config, UserCallBack, userDataObj));
                PushToResourcePackageCallBackList(pakg.instanceID);
                return;
            }

            //全新的包
            if (!m_ResourcePackageRequestTable.Contains(pakg.instanceID))
            {
                pakg.Clear();
                pakg.isAsync   = true;
                pakg.filePatch = patch;

                FillUnioFileInfo(config as UnionResConfigData, pakg);
                EnQueueWaitForUpLoadAssetsFileAsyncRequestTable(pakg.instanceID);
                m_ResourcePackageRequestTable.Add(pakg.instanceID);
            }

            pakg.AddAsyncCallBackData(resourcePackageCallBack, BuildResourcePackageCallBackObj(pakg, result, config, UserCallBack, userDataObj));
            pakg.AddRef();
        }
        return;
    }