Exemplo n.º 1
0
        //加载ABConfig配置表
        public bool LoadAssetBundleConfig()
        {
            m_resourceItemDict.Clear();

            string      configPath = GlobalConfigData.DependenceFile4AssetBundle;
            AssetBundle configAB   = AssetBundle.LoadFromFile(configPath);
            TextAsset   textAsset  = configAB.LoadAsset <TextAsset>(GlobalConfigData.DependenceFileName);

            if (textAsset == null)
            {
                Debug.LogError("AssetBundleConfig is not exists!");
                return(false);
            }
            MemoryStream      ms       = new MemoryStream(textAsset.bytes);
            BinaryFormatter   bf       = new BinaryFormatter();
            AssetBundleConfig abConfig = (AssetBundleConfig)bf.Deserialize(ms);

            ms.Close();

            for (int i = 0; i < abConfig.ABList.Count; i++)
            {
                ResourceItem item   = new ResourceItem();
                ABBase       abBase = abConfig.ABList[i];
                item.Crc          = abBase.Crc;
                item.AssetName    = abBase.AssetName;
                item.ABName       = abBase.ABName;
                item.DependABList = new List <string>(abBase.DependABList);
                if (m_resourceItemDict.ContainsKey(item.Crc) == false)
                {
                    m_resourceItemDict.Add(item.Crc, item);
                }
                else
                {
                    Debug.Log("重复的Crc, 资源名: " + item.AssetName + ", AB包名: " + item.ABName);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        //加载ResourceItem
        public ResourceItem LoadResourceAssetBundle(uint crc)
        {
            ResourceItem resourceItem = null;

            m_resourceItemDict.TryGetValue(crc, out resourceItem);
            if (resourceItem == null)
            {
                Debug.LogError("在AssetBundle中, 没有找到Crc: " + crc.ToString() + "对应的资源!");
                return(null);
            }
            if (resourceItem.Ab != null)
            {
                return(resourceItem);
            }
            if (resourceItem.DependABList != null)
            {
                for (int i = 0; i < resourceItem.DependABList.Count; i++)
                {
                    LoadAssetBundle(resourceItem.DependABList[i]);
                }
            }
            resourceItem.Ab = LoadAssetBundle(resourceItem.ABName);
            return(resourceItem);
        }