示例#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();
        }
示例#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);
                }
            }
        }
示例#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);
        }