예제 #1
0
        //加载AssetBundle
        public AssetBundle LoadAssetBundle(string name)
        {
            AssetBundleItem abItem = null;
            uint            crc    = Crc.StringToCRC32(name);

            if (!m_assetBundleItemDict.TryGetValue(crc, out abItem) || abItem == null)
            {
                AssetBundle assetBundle = null;
                string      fullPath    = GlobalConfigData.AssetBundleBuildTargetPath + "/" + name;
                if (File.Exists(fullPath))
                {
                    assetBundle = AssetBundle.LoadFromFile(fullPath);
                }
                if (assetBundle == null)
                {
                    Debug.LogError("Load AssetBundle Error: " + fullPath);
                    return(null);
                }
                abItem             = m_AssetBundleItemPool.Spawn(true);
                abItem.assetBundle = assetBundle;
                abItem.refCount++;

                m_assetBundleItemDict.Add(crc, abItem);
            }
            else
            {
                abItem.refCount++;
            }
            return(abItem.assetBundle);
        }
예제 #2
0
        //卸载AssetBundle
        private void UnloadAssetBundle(string abName)
        {
            AssetBundleItem abItem = null;
            uint            crc    = Crc.StringToCRC32(abName);

            if (m_assetBundleItemDict.TryGetValue(crc, out abItem) && abItem != null)
            {
                abItem.refCount--;
                if (abItem.refCount <= 0 && abItem.assetBundle != null)
                {
                    abItem.assetBundle.Unload(true);
                    abItem.Reset();
                    m_AssetBundleItemPool.Recycle(abItem);
                    m_assetBundleItemDict.Remove(crc);
                }
            }
        }