Ejemplo n.º 1
0
        void CollectAssetBundle()
        {
            List <string> names = new List <string>(LoadedAssetBundles.Keys);

            for (int i = 0; i < names.Count; i++)
            {
                if (LoadedAssetBundles[names[i]].m_ReferencedCount == 0)
                {
                    LoadedAssetBundles[names[i]].m_AssetBundle.Unload(false);
                    LoadedAssetBundles.Remove(names[i]);
                    BundleDependencies.Remove(names[i]);
                }
            }
            Resources.UnloadUnusedAssets();
        }
Ejemplo n.º 2
0
        void DecreaseRefrenceCount(string assetBundlePath)
        {
            if (LoadedAssetBundles.ContainsKey(assetBundlePath))
            {
                LoadedAssetBundles[assetBundlePath].m_ReferencedCount -= 1;
                var dependencies = BundleDependencies[assetBundlePath];
                for (int index = 0; index < dependencies.Length; index++)
                {
                    DecreaseRefrenceCount(dependencies[index]);
                }

                if (LoadedAssetBundles[assetBundlePath].m_ReferencedCount == 0)
                {
                    LoadedAssetBundles[assetBundlePath].m_AssetBundle.Unload(false);
                    LoadedAssetBundles.Remove(assetBundlePath);
                    BundleDependencies.Remove(assetBundlePath);
                }
            }
        }
Ejemplo n.º 3
0
        AssetBundle LoadAssetBundle(string path)
        {
            path = GeneratePathString(path);
            LoadedAssetBundle loadedAssetBundel = null;
            AssetBundle       assetBundle;

            if (LoadedAssetBundles.TryGetValue(path, out loadedAssetBundel))
            {
                loadedAssetBundel.m_ReferencedCount++;
                assetBundle = loadedAssetBundel.m_AssetBundle;
            }
            else
            {
                Debug.Log("LoadAssetBundleFromDisk" + path);
                assetBundle = LoadAssetBundleFromDisk(path);
            }

            if (assetBundle != null)
            {
                Debug.Log(assetBundle.name);
                var dependencies = BundleDependencies[path];
                if (dependencies != null)
                {
                    var itr = dependencies.GetEnumerator();
                    for (int i = 0; i < dependencies.Length; i++)
                    {
                        LoadAssetBundle(dependencies[i]);
                    }
                }
            }
            else
            {
                Debug.LogWarning("failed to load " + path);
            }
            return(assetBundle);
        }