Пример #1
0
    private static void PushToNeedToUnLoadPakage(int instanceID)
    {
        ResourcePackage req = AllocResourcePackage(instanceID);

        //如果加载列表里有他
        if (m_ResourcePackageRequestTable.Contains(instanceID))
        {
            int refcout = req.Release();
            if (refcout <= 0)
            {
                m_ResourcePackageRequestTable.Remove(instanceID);
                RemoveFromAssetsFileUpLoadQueue(instanceID);
                req.ResetPriority();
                if (req.isUpLoadToLoadingThread)
                {
                    //加入到将要卸载的列表
                    m_NeedToUnLoadResourcePackageTable.Add(instanceID);
                }
                else
                {
                    RemoveAssetsFileProcessingList(req.instanceID);
                }
            }
        }
    }
    private static void ReleaseAssetBundleIfNeed(ResNode res)
    {
        if (!isOnRunTimeMode)
        {
            return;
        }
        if (res.assetType == AssetType.Asset_FBX)
        {
            return;
        }
        if (res.assetType != AssetType.Asset_Prefab && !IsUnionDependenicesAssetBundle(res.AssetBundleName))
        {
            return;
        }

        if (res.isBeReleaseAssetBundleIfNeed)
        {
            return;
        }
        res.isBeReleaseAssetBundleIfNeed = true;
        ResourcePackage pkg = AllocResourcePackage(res.AssetBundleName);

        if (m_LoadedResourcePackage.Contains(pkg.instanceID))
        {
            int refcout = pkg.Release();
            if (refcout <= 0)
            {
                UnLoadAssetBundle(pkg.instanceID, false);
            }
        }
    }
Пример #3
0
 /// <summary>
 /// 释放资源包
 /// </summary>
 /// <param name="assetBundleName"></param>
 private static void ReleaseAssetBundle(string assetBundleName)
 {
     //非编辑器下,还有AssetBundle
     if (isOnRunTimeMode)
     {
         ResourcePackage pkg = AllocResourcePackage(assetBundleName);
         //如果这个ab没有被加载出来.
         if (!m_LoadedResourcePackage.Contains(pkg.instanceID))
         {
             PushToNeedToUnLoadPakage(pkg.instanceID);
         }
         else
         {
             //baundle的引用减少
             int assetBundleRefCount = pkg.Release();
             //如果这个bundle已经没有引用了,卸载bundle
             if (assetBundleRefCount <= 0)
             {
                 RemoveAllResourcePackageCallBackList(assetBundleName);
                 //移除加载
                 UnLoadAssetBundle(pkg.instanceID);
             }
         }
     }
 }