Exemplo n.º 1
0
    /// <summary>
    /// 查找差异hash
    /// </summary>
    /// <param name="oldPath">旧文件</param>
    /// <param name="newPath">新文件</param>
    /// <returns></returns>
    public static List <string> GetDiffHashList(string oldPath, string newPath)
    {
        List <string> result = new List <string>();

        if (!File.Exists(oldPath))
        {
            Debug.LogError(oldPath + "不存在");
            return(result);
        }
        if (!File.Exists(newPath))
        {
            Debug.LogError(newPath + "不存在");
            return(result);
        }

        Dictionary <string, string> oldDic = new Dictionary <string, string>();
        //比较新旧差异
        List <AssetBundleHashInfo> oldList = JsonMapper.ToObject <List <AssetBundleHashInfo> >(File.ReadAllText(oldPath));

        for (int i = 0; i < oldList.Count; i++)
        {
            AssetBundleHashInfo info = oldList[i];
            oldDic.Add(info.abName, info.hash);
        }

        List <AssetBundleHashInfo> newList = JsonMapper.ToObject <List <AssetBundleHashInfo> >(File.ReadAllText(newPath));

        for (int i = 0; i < newList.Count; i++)
        {
            AssetBundleHashInfo info = newList[i];
            //相同
            if (oldDic.ContainsKey(info.abName) && oldDic[info.abName].Equals(info.hash))
            {
                continue;
            }
            result.Add(AssetBundleLoad.FolderName + "/" + info.abName);
        }
        return(result);
    }
Exemplo n.º 2
0
    /// <summary>
    /// 查找在新hash中没有的文件,需要删除
    /// </summary>
    /// <param name="oldPath"></param>
    /// <returns></returns>
    public static List <string> GetZipDeleteList(string oldPath, string newPath)
    {
        List <string> result = new List <string>();

        if (!File.Exists(oldPath))
        {
            Debug.LogError(oldPath + "不存在");
            return(result);
        }
        if (!File.Exists(newPath))
        {
            Debug.LogError(newPath + "不存在");
            return(result);
        }

        List <AssetBundleHashInfo>  newList = JsonMapper.ToObject <List <AssetBundleHashInfo> >(File.ReadAllText(newPath));
        Dictionary <string, string> newDic  = new Dictionary <string, string>();

        for (int i = 0, count = newList.Count; i < count; i++)
        {
            AssetBundleHashInfo info = newList[i];
            newDic.Add(info.abName, info.hash);
        }

        //比较新旧差异, 自动找出更新包
        List <AssetBundleHashInfo> oldList = LitJson.JsonMapper.ToObject <List <AssetBundleHashInfo> >(File.ReadAllText(oldPath));

        for (int i = 0; i < oldList.Count; i++)
        {
            AssetBundleHashInfo info = oldList[i];
            if (!newDic.ContainsKey(info.abName))
            {
                result.Add(AssetBundleLoad.FolderName + "/" + info.abName);
                Debug.Log("删除文件==" + info.abName);
            }
        }
        return(result);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 拿到所有ab的hash
    /// </summary>
    /// <returns></returns>
    public static List <AssetBundleHashInfo> GetAllAssetbundleHashList()
    {
        AssetBundle                assetBundle             = AssetBundle.LoadFromFile(AssetBundleLoad.GetAbPath() + AssetBundleLoad.FolderName);
        AssetBundleManifest        manifest                = assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
        List <AssetBundleHashInfo> assetbundleHashInfoList = new List <AssetBundleHashInfo>();

        string[] allAssetbundleNames = manifest.GetAllAssetBundles();
        for (int i = 0; i < allAssetbundleNames.Length; i++)
        {
            string abName            = allAssetbundleNames[i];
            AssetBundleHashInfo info = new AssetBundleHashInfo();
            info.abName = abName;
            info.hash   = manifest.GetAssetBundleHash(abName).ToString();
            assetbundleHashInfoList.Add(info);
        }
        //Manifest别忘了加
        AssetBundleHashInfo info2 = new AssetBundleHashInfo();

        info2.abName = AssetBundleLoad.FolderName;
        info2.hash   = manifest.GetHashCode().ToString();
        assetbundleHashInfoList.Add(info2);
        assetBundle.Unload(true);
        return(assetbundleHashInfoList);
    }