Exemplo n.º 1
0
    private static void UnLoadAssetBundle(int bundleID, bool toUnLoadAllAssets = true)
    {
        ResourcePackage pkg = AllocResourcePackage(bundleID);

        if (m_LoadedResourcePackage.Contains(bundleID))
        {
            if (pkg.AssetBundleInstance)
            {
                pkg.AssetBundleInstance.Unload(toUnLoadAllAssets);
            }
            m_LoadedResourcePackage.Remove(bundleID);
            pkg.Clear();
        }
    }
Exemplo n.º 2
0
    private static ResourcePackage AllocResourcePackage(int instanceID)
    {
        ResourcePackage reslut = null;

        if (AssetBundleNameInstanceIDList.Contains(instanceID))
        {
            if (!allCreatedResourcePackage.TryGetValue(instanceID, out reslut))
            {
                reslut = new ResourcePackage();
                reslut.Clear();
                reslut.instanceID = instanceID;
                allCreatedResourcePackage.Add(instanceID, reslut);
            }
        }

        return(reslut);
    }
Exemplo n.º 3
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;
    }