Example #1
0
    public static AssetBundleManager.BundlePack ManifestAdd(
        string manifestAssetBundleName)
    {
        if (AssetBundleManager.m_ManifestBundlePack.ContainsKey(manifestAssetBundleName))
        {
            return((AssetBundleManager.BundlePack)null);
        }
        AssetBundleManager.BundlePack bundlePack = new AssetBundleManager.BundlePack();
        AssetBundleManager.m_ManifestBundlePack.Add(manifestAssetBundleName, bundlePack);
        LoadedAssetBundle loadedAssetBundle = AssetBundleManager.LoadAssetBundle(manifestAssetBundleName, false, manifestAssetBundleName);

        if (loadedAssetBundle == null)
        {
            AssetBundleManager.m_ManifestBundlePack.Remove(manifestAssetBundleName);
            return((AssetBundleManager.BundlePack)null);
        }
        AssetBundleLoadAssetOperationSimulation operationSimulation = new AssetBundleLoadAssetOperationSimulation(loadedAssetBundle.m_AssetBundle.LoadAsset("AssetBundleManifest", typeof(AssetBundleManifest)));

        if (operationSimulation.IsEmpty())
        {
            AssetBundleManager.m_ManifestBundlePack.Remove(manifestAssetBundleName);
            return((AssetBundleManager.BundlePack)null);
        }
        bundlePack.AssetBundleManifest = operationSimulation.GetAsset <AssetBundleManifest>();
        return(bundlePack);
    }
Example #2
0
    private static bool UnloadBundle(
        string assetBundleName,
        AssetBundleManager.BundlePack targetPack,
        bool unloadAllLoadedObjects)
    {
        assetBundleName = assetBundleName ?? string.Empty;
        if (targetPack.DownloadingErrors.TryGetValue(assetBundleName, out string _))
        {
            return(false);
        }
        LoadedAssetBundle loadedAssetBundle = (LoadedAssetBundle)null;

        if (!targetPack.LoadedAssetBundles.TryGetValue(assetBundleName, out loadedAssetBundle))
        {
            return(false);
        }
        if (--loadedAssetBundle.m_ReferencedCount == 0U)
        {
            if (Object.op_Implicit((Object)loadedAssetBundle.m_AssetBundle))
            {
                loadedAssetBundle.m_AssetBundle.Unload(unloadAllLoadedObjects);
            }
            targetPack.LoadedAssetBundles.Remove(assetBundleName);
            AssetBundleManager.m_AllLoadedAssetBundleNames.Remove(assetBundleName);
        }
        return(true);
    }
Example #3
0
    protected static string RemapVariantName(string assetBundleName, string manifestAssetBundleName = null)
    {
        if (manifestAssetBundleName.IsNullOrEmpty())
        {
            manifestAssetBundleName = "abdata";
        }
        AssetBundleManager.BundlePack bundlePack = AssetBundleManager.m_ManifestBundlePack[manifestAssetBundleName];
        string[] bundlesWithVariant = bundlePack.AssetBundleManifest.GetAllAssetBundlesWithVariant();
        if (Array.IndexOf <string>(bundlesWithVariant, assetBundleName) < 0)
        {
            return(assetBundleName);
        }
        string[] strArray1 = assetBundleName.Split('.');
        int      num1      = int.MaxValue;
        int      index1    = -1;

        for (int index2 = 0; index2 < bundlesWithVariant.Length; ++index2)
        {
            string[] strArray2 = bundlesWithVariant[index2].Split('.');
            if (!(strArray2[0] != strArray1[0]))
            {
                int num2 = Array.IndexOf <string>(bundlePack.Variants, strArray2[1]);
                if (num2 != -1 && num2 < num1)
                {
                    num1   = num2;
                    index1 = index2;
                }
            }
        }
        return(index1 != -1 ? bundlesWithVariant[index1] : assetBundleName);
    }
        public static void AddAssetBundleManifest(string manifestPath)
        {
            if (!GetManifest(manifestPath, out var manifest))
            {
                return;
            }
            var bundlePack = new AssetBundleManager.BundlePack {
                AssetBundleManifest = manifest
            };
            var property = typeof(AssetBundleManager).GetProperty("manifestBundlePack", BindingFlags.NonPublic | BindingFlags.Static);
            var dict     = property.GetValue(null, null);

            property.PropertyType.GetMethod("Add")?.Invoke(dict, new object[] { manifestPath, bundlePack });
        }
Example #5
0
    public static bool LoadAssetBundleInternal(
        string assetBundleName,
        bool isAsync,
        string manifestAssetBundleName = null)
    {
        if (manifestAssetBundleName.IsNullOrEmpty())
        {
            manifestAssetBundleName = "abdata";
        }
        AssetBundleManager.BundlePack bundlePack        = AssetBundleManager.m_ManifestBundlePack[manifestAssetBundleName];
        LoadedAssetBundle             loadedAssetBundle = (LoadedAssetBundle)null;

        bundlePack.LoadedAssetBundles.TryGetValue(assetBundleName, out loadedAssetBundle);
        if (loadedAssetBundle != null)
        {
            ++loadedAssetBundle.m_ReferencedCount;
            return(true);
        }
        AssetBundleCreate assetBundleCreate = (AssetBundleCreate)null;

        bundlePack.CreateAssetBundles.TryGetValue(assetBundleName, out assetBundleCreate);
        if (assetBundleCreate != null)
        {
            ++assetBundleCreate.m_ReferencedCount;
            return(true);
        }
        if (!AssetBundleManager.m_AllLoadedAssetBundleNames.Add(assetBundleName))
        {
            Debug.LogErrorFormat("Loaded AssetBundle : {0}\nManifestName : {1}, isAsync : {2}", new object[3]
            {
                (object)assetBundleName,
                (object)manifestAssetBundleName,
                (object)isAsync
            });
            return(true);
        }
        string str = AssetBundleManager.BaseDownloadingURL + assetBundleName;

        if (!isAsync)
        {
            bundlePack.LoadedAssetBundles.Add(assetBundleName, new LoadedAssetBundle(AssetBundle.LoadFromFile(str)));
        }
        else
        {
            bundlePack.CreateAssetBundles.Add(assetBundleName, new AssetBundleCreate(AssetBundle.LoadFromFileAsync(str)));
        }
        return(false);
    }
Example #6
0
    public static AssetBundleLoadAssetOperation LoadAllAsset(
        string assetBundleName,
        System.Type type,
        string manifestAssetBundleName = null)
    {
        if (manifestAssetBundleName.IsNullOrEmpty())
        {
            manifestAssetBundleName = "abdata";
        }
        AssetBundleManager.BundlePack bundlePack         = AssetBundleManager.m_ManifestBundlePack[manifestAssetBundleName];
        AssetBundleLoadAssetOperation loadAssetOperation = (AssetBundleLoadAssetOperation)null;

        if (loadAssetOperation == null)
        {
            AssetBundleManager.LoadAssetBundle(assetBundleName, false, manifestAssetBundleName);
            loadAssetOperation = (AssetBundleLoadAssetOperation) new AssetBundleLoadAssetOperationSimulation(bundlePack.LoadedAssetBundles[assetBundleName].m_AssetBundle.LoadAllAssets(type));
        }
        return(loadAssetOperation);
    }
Example #7
0
    public static LoadedAssetBundle GetLoadedAssetBundle(
        string assetBundleName,
        out string error,
        string manifestAssetBundleName = null)
    {
        assetBundleName = assetBundleName ?? string.Empty;
        if (manifestAssetBundleName.IsNullOrEmpty())
        {
            manifestAssetBundleName = "abdata";
        }
        AssetBundleManager.BundlePack bundlePack = AssetBundleManager.m_ManifestBundlePack[manifestAssetBundleName];
        if (bundlePack.DownloadingErrors.TryGetValue(assetBundleName, out error))
        {
            return((LoadedAssetBundle)null);
        }
        LoadedAssetBundle loadedAssetBundle1 = (LoadedAssetBundle)null;

        bundlePack.LoadedAssetBundles.TryGetValue(assetBundleName, out loadedAssetBundle1);
        if (loadedAssetBundle1 == null)
        {
            return((LoadedAssetBundle)null);
        }
        LoadedAssetBundleDependencies bundleDependencies = bundlePack.Dependencies.Find((Predicate <LoadedAssetBundleDependencies>)(p => p.m_Key == assetBundleName));

        if (bundleDependencies == null)
        {
            return(loadedAssetBundle1);
        }
        foreach (string bundleName in bundleDependencies.m_BundleNames)
        {
            if (bundlePack.DownloadingErrors.TryGetValue(assetBundleName, out error))
            {
                return(loadedAssetBundle1);
            }
            LoadedAssetBundle loadedAssetBundle2;
            bundlePack.LoadedAssetBundles.TryGetValue(bundleName, out loadedAssetBundle2);
            if (loadedAssetBundle2 == null)
            {
                return((LoadedAssetBundle)null);
            }
        }
        return(loadedAssetBundle1);
    }
Example #8
0
    public static AssetBundleLoadAssetOperation LoadAllAssetAsync(
        string assetBundleName,
        System.Type type,
        string manifestAssetBundleName = null)
    {
        if (manifestAssetBundleName.IsNullOrEmpty())
        {
            manifestAssetBundleName = "abdata";
        }
        AssetBundleManager.BundlePack bundlePack         = AssetBundleManager.m_ManifestBundlePack[manifestAssetBundleName];
        AssetBundleLoadAssetOperation loadAssetOperation = (AssetBundleLoadAssetOperation)null;

        if (loadAssetOperation == null)
        {
            AssetBundleManager.LoadAssetBundle(assetBundleName, true, manifestAssetBundleName);
            loadAssetOperation = (AssetBundleLoadAssetOperation) new AssetBundleLoadAssetOperationFull(assetBundleName, (string)null, type, manifestAssetBundleName);
            bundlePack.InProgressOperations.Add((AssetBundleLoadOperation)loadAssetOperation);
        }
        return(loadAssetOperation);
    }
Example #9
0
    public static AssetBundleLoadOperation LoadLevelAsync(
        string assetBundleName,
        string levelName,
        bool isAdditive,
        string manifestAssetBundleName = null)
    {
        if (manifestAssetBundleName.IsNullOrEmpty())
        {
            manifestAssetBundleName = "abdata";
        }
        AssetBundleManager.BundlePack bundlePack          = AssetBundleManager.m_ManifestBundlePack[manifestAssetBundleName];
        AssetBundleLoadOperation      bundleLoadOperation = (AssetBundleLoadOperation)null;

        if (bundleLoadOperation == null)
        {
            AssetBundleManager.LoadAssetBundle(assetBundleName, true, manifestAssetBundleName);
            bundleLoadOperation = (AssetBundleLoadOperation) new AssetBundleLoadLevelOperation(assetBundleName, levelName, isAdditive, manifestAssetBundleName);
            bundlePack.InProgressOperations.Add(bundleLoadOperation);
        }
        return(bundleLoadOperation);
    }
Example #10
0
 protected static void LoadDependencies(
     string assetBundleName,
     bool isAsync,
     string manifestAssetBundleName = null)
 {
     if (manifestAssetBundleName.IsNullOrEmpty())
     {
         manifestAssetBundleName = "abdata";
     }
     AssetBundleManager.BundlePack bundlePack = AssetBundleManager.m_ManifestBundlePack[manifestAssetBundleName];
     if (object.ReferenceEquals((object)bundlePack.AssetBundleManifest, (object)null))
     {
         Debug.LogError((object)"Please initialize AssetBundleManifest by calling AssetBundleManager.Initialize()");
     }
     else
     {
         string[] allDependencies = bundlePack.AssetBundleManifest.GetAllDependencies(assetBundleName);
         if (allDependencies.Length == 0)
         {
             return;
         }
         for (int index = 0; index < allDependencies.Length; ++index)
         {
             allDependencies[index] = AssetBundleManager.RemapVariantName(allDependencies[index], manifestAssetBundleName);
         }
         LoadedAssetBundleDependencies bundleDependencies = bundlePack.Dependencies.Find((Predicate <LoadedAssetBundleDependencies>)(p => p.m_Key == assetBundleName));
         if (bundleDependencies != null)
         {
             ++bundleDependencies.m_ReferencedCount;
         }
         else
         {
             bundlePack.Dependencies.Add(new LoadedAssetBundleDependencies(assetBundleName, allDependencies));
         }
         for (int index = 0; index < allDependencies.Length; ++index)
         {
             AssetBundleManager.LoadAssetBundleInternal(allDependencies[index], isAsync, manifestAssetBundleName);
         }
     }
 }
Example #11
0
 private void Update()
 {
     foreach (KeyValuePair <string, AssetBundleManager.BundlePack> keyValuePair in AssetBundleManager.m_ManifestBundlePack)
     {
         AssetBundleManager.BundlePack bundlePack = keyValuePair.Value;
         foreach (KeyValuePair <string, AssetBundleCreate> createAssetBundle in bundlePack.CreateAssetBundles)
         {
             AssetBundleCreateRequest createRequest = createAssetBundle.Value.m_CreateRequest;
             if (((AsyncOperation)createRequest).get_isDone())
             {
                 bundlePack.LoadedAssetBundles.Add(createAssetBundle.Key, new LoadedAssetBundle(createRequest.get_assetBundle())
                 {
                     m_ReferencedCount = createAssetBundle.Value.m_ReferencedCount
                 });
                 this.keysToRemove.Add(createAssetBundle.Key);
             }
         }
         foreach (string key in this.keysToRemove)
         {
             bundlePack.CreateAssetBundles.Remove(key);
         }
         int index = 0;
         while (index < bundlePack.InProgressOperations.Count)
         {
             if (!bundlePack.InProgressOperations[index].Update())
             {
                 bundlePack.InProgressOperations.RemoveAt(index);
             }
             else
             {
                 ++index;
             }
         }
         this.keysToRemove.Clear();
     }
 }
Example #12
0
    public static void Initialize(string basePath)
    {
        if (AssetBundleManager.isInitialized)
        {
            return;
        }
        AssetBundleManager.m_BaseDownloadingURL = basePath;
        GameObject go = new GameObject(nameof(AssetBundleManager), new System.Type[1]
        {
            typeof(AssetBundleManager)
        });

        Object.DontDestroyOnLoad((Object)go);
        if (AssetBundleManager.MainBundle == null)
        {
            AssetBundleManager.MainBundle = AssetBundleManager.ManifestAdd("abdata");
        }
        if (Directory.Exists(basePath))
        {
            IEnumerable <string> source = ((IEnumerable <string>)Directory.GetFiles(basePath, "*.*", SearchOption.TopDirectoryOnly)).Where <string>((Func <string, bool>)(s => Path.GetExtension(s).IsNullOrEmpty()));
            // ISSUE: reference to a compiler-generated field
            if (AssetBundleManager.\u003C\u003Ef__mg\u0024cache0 == null)
            {
                // ISSUE: reference to a compiler-generated field
                AssetBundleManager.\u003C\u003Ef__mg\u0024cache0 = new Func <string, string>(Path.GetFileNameWithoutExtension);
            }
            // ISSUE: reference to a compiler-generated field
            Func <string, string> fMgCache0 = AssetBundleManager.\u003C\u003Ef__mg\u0024cache0;
            foreach (string manifestAssetBundleName in source.Select <string, string>(fMgCache0).Where <string>((Func <string, bool>)(s => s != "abdata")))
            {
                AssetBundleManager.ManifestAdd(manifestAssetBundleName);
            }
        }
        AssetBundleManager.isInitialized = true;
        InitAddComponent.AddComponents(go);
    }