public static void LoadAndVerions(BuildTarget buildTargetGroup, bool isUpdate = false,
                                      int version = 10000)
    {
        m_isUpdateShader = false;
        m_curVersion     = version;
        if (isUpdate)
        {
            m_currentCache = ABAssetDataUtil.ReloadCache(buildTargetGroup);
            if (m_curVersion <= m_currentCache.firstVersion || m_curVersion <= m_currentCache.newVersion)
            {
                m_curVersion = m_currentCache.newVersion + 1;
            }
            for (int i = 0; i < m_currentCache.assetList.Count; i++)
            {
                if (!m_oldDic.ContainsKey(m_currentCache.assetList[i].filePath))
                {
                    m_oldDic.Add(m_currentCache.assetList[i].filePath, m_currentCache.assetList[i]);

                    if (!m_abbuildDic.ContainsKey(m_currentCache.assetList[i].bundleId))
                    {
                        ABBundleInfo buildInfo = new ABBundleInfo();
                        buildInfo.bundleId     = m_currentCache.assetList[i].bundleId;
                        buildInfo.firstVersion = m_currentCache.firstVersion;
                        m_abbuildDic.Add(buildInfo.bundleId, buildInfo);
                    }
                }
            }
        }
        else
        {
            m_currentCache = new ABAssetDataList();

            m_currentCache.firstVersion = m_curVersion;
        }
    }
 private static void AddAsset(ABBundleInfo buildInfo, ABAssetData cacheData)
 {
     if (buildInfo != null && cacheData != null &&
         buildInfo.bundleId.version >= cacheData.version)
     {
         cacheData.bundleId = buildInfo.bundleId;
     }
 }
    private static ABAssetInfo ColloectDependecies(string prefabPath, string fileName = "")
    {
        prefabPath = prefabPath.ToLower();
        string[] depends = AssetDatabase.GetDependencies(prefabPath, false);
        //场景比较特殊是因为场景ab不能包含其他的资源,场景自己一个ab,所以得把场景引用的资源挪到scenemodle_ab中去
        if (prefabPath.EndsWith(".unity"))
        {
            if (fileName.Contains("."))
            {
                fileName = fileName.Substring(0, fileName.IndexOf("."));
            }
            m_curretBundleID = new BundleID(m_currentCache.firstVersion, EnumAB.scene_ab, fileName);
            if (!m_abbuildDic.ContainsKey(m_curretBundleID))
            {
                ABBundleInfo buildInfo = new ABBundleInfo();
                buildInfo.bundleId     = m_curretBundleID;
                buildInfo.firstVersion = m_currentCache.firstVersion;
                m_abbuildDic.Add(m_curretBundleID, buildInfo);
            }
        }
        ABAssetInfo parentAssetInfo = null;

        if (!m_dependsDic.ContainsKey(prefabPath))
        {
            parentAssetInfo = LoadAssetData(prefabPath);
            m_dependsDic.Add(prefabPath, parentAssetInfo);
            if (depends != null)
            {
                for (int i = 0; i < depends.Length; i++)
                {
                    depends[i] = depends[i].ToLower().Replace("\\", "/");
                    if (!depends[i].EndsWith("dll") && !depends[i].EndsWith("cs") && !depends[i].EndsWith("js"))
                    {
                        //场景比较特殊是因为场景ab不能包含其他的资源,场景自己一个ab,所以得把场景引用的资源挪到scenemodle_ab中去
                        if (prefabPath.EndsWith(".unity"))
                        {
                            m_curretBundleID = new BundleID(m_currentCache.firstVersion, EnumAB.scenemodle_ab);
                        }
                        var childAssetInfo = ColloectDependecies(depends[i]);
                        parentAssetInfo.AddChild(childAssetInfo);
                    }
                }
            }
        }
        else
        {
            parentAssetInfo = m_dependsDic[prefabPath];
        }
        return(parentAssetInfo);
    }
    /// <summary>
    /// 收集资源
    /// </summary>
    /// <param name="path"></param>
    /// <param name="isUpdate"></param>
    /// <param name="endWith"></param>
    static void CollectFromDirectinfo(string path,
                                      bool isUpdate = false, string endWith = "prefab")
    {
        if (!m_abbuildDic.ContainsKey(m_curretBundleID))
        {
            ABBundleInfo buildInfo = new ABBundleInfo();
            buildInfo.bundleId     = m_curretBundleID;
            buildInfo.firstVersion = m_currentCache.firstVersion;
            m_abbuildDic.Add(m_curretBundleID, buildInfo);
        }

        DirectoryInfo direc;

        direc = new DirectoryInfo(Application.dataPath + "/" + path);
        if (!direc.Exists)
        {
            direc = new DirectoryInfo(path);
            if (!direc.Exists)
            {
                return;
            }
            //return;
        }
        FileInfo[] fileArray = direc.GetFiles("*.*", SearchOption.AllDirectories);
        if (fileArray == null)
        {
            return;
        }
        for (int fileIndex = 0; fileIndex < fileArray.Length; fileIndex++)
        {
            FileInfo file       = fileArray[fileIndex];
            string   fileName   = file.FullName.Replace("\\", "/");
            string   prefabName = fileName.Substring(fileName.IndexOf("Assets"));
            if (prefabName.Contains("GameRoot.unity"))
            {
                continue;
            }
            if (prefabName.EndsWith(".meta"))
            {
                continue;
            }
            if (prefabName.EndsWith(endWith) || prefabName.EndsWith("shader") || prefabName.EndsWith("cginc") ||
                prefabName.EndsWith("ttf") ||
                prefabName.EndsWith("shadervariants") ||
                prefabName.EndsWith("png"))
            {
                ColloectDependecies(prefabName, file.Name);
            }
        }
    }
    private static ABBundleInfo GetUpdateABBuild(EnumAB bundleType, string sceneName = "")
    {
        ABBundleInfo build    = null;
        var          bundleId = new BundleID(m_curVersion, bundleType, sceneName);

        if (m_abbuildDic.ContainsKey(bundleId))
        {
            build = m_abbuildDic[bundleId];
        }
        else
        {
            build          = new ABBundleInfo();
            build.bundleId = bundleId;
            m_abbuildDic.Add(bundleId, build);
        }
        return(build);
    }
    public static void ProcessCacheDic(bool isUpdate = false)
    {
        List <ABAssetData> shaderlist = new List <ABAssetData>();

        foreach (var keyvalue in m_abbuildDic)
        {
            keyvalue.Value.fileList.Clear();
        }

        foreach (var keyvalue in m_dependsDic)
        {
            if (!isUpdate)
            {
                if (m_abbuildDic.ContainsKey(keyvalue.Value.m_cacheData.bundleId))
                {
                    var buildInfo = m_abbuildDic[keyvalue.Value.m_cacheData.bundleId];
                    if (buildInfo != null)
                    {
                        AddAsset(buildInfo, keyvalue.Value.m_cacheData);
                    }
                }
            }
            else
            {
                ABAssetData oldCache  = null;
                var         newCache  = keyvalue.Value.m_cacheData;
                var         assetInfo = keyvalue.Value;

                ABBundleInfo build = null;
                if (!m_abbuildDic.TryGetValue(newCache.bundleId, out build))
                {
                    build          = new ABBundleInfo();
                    build.bundleId = newCache.bundleId;
                    m_abbuildDic.Add(newCache.bundleId, build);
                }
                m_oldDic.TryGetValue(keyvalue.Key, out oldCache);
                ABBundleInfo oldBuild = null;
                if (oldCache != null && m_abbuildDic.ContainsKey(oldCache.bundleId))
                {
                    oldBuild = m_abbuildDic[oldCache.bundleId];
                }
                if (newCache.bundleType == EnumAB.shaders_ab)
                {
                    if (oldCache != null)
                    {
                        continue;
                    }

                    //shader有修改  重新build所有shader就好
                    if (!newCache.Equals(oldCache))
                    {
                        //重新打 将已经处理过的shader都移动到最新的version
                        m_isUpdateShader = true;
                        if (shaderlist.Count != 0)
                        {
                            foreach (var shader in shaderlist)
                            {
                                build.bundleId = new BundleID(m_curVersion, EnumAB.shaders_ab);
                                AddAsset(build, shader);
                            }
                            shaderlist.Clear();
                        }
                    }
                    if (m_isUpdateShader)
                    {
                        build.bundleId = new BundleID(m_curVersion, EnumAB.shaders_ab);
                        AddAsset(build, newCache);
                    }
                    else
                    {
                        // shaderlist 用来处理原来的没有修改过的shader,当后面发现有shader修改,那么需要把之前觉得不需要的改的shader都修改了
                        shaderlist.Add(newCache);
                        AddAsset(oldBuild, newCache);
                    }
                }
                else if (newCache.bundleType == EnumAB.uialtas_ab)
                {
                    //图集的定义是图集除了引用shader之外不会引用任何其他图集,而且有另外一套图集引用关系
                    var newBuildCache = assetInfo.m_cacheData;
                    if (newBuildCache.Equals(oldCache))
                    {
                        AddAsset(oldBuild, newCache);
                    }
                    else
                    {
                        //图集有修改  新建一个 version_uiAtlas_ab的assetbundle 并且把所有相关的放到这儿来
                        build = GetUpdateABBuild(EnumAB.uialtas_ab);
                        AddAsset(build, newBuildCache);
                        TransToSelf(assetInfo, EnumAB.uialtas_ab);
                    }
                }
                else if (newCache.bundleType == EnumAB.scene_ab)
                {
                    var newBuildCache = assetInfo.m_cacheData;
                    if (newBuildCache.Equals(oldCache))
                    {
                        AddAsset(oldBuild, newCache);
                    }
                    else
                    {
                        //场景有改变 需要重新打包这个场景它的和它的子引用,要更新它的子引用是怕它有增加一个模型
                        build = GetUpdateABBuild(EnumAB.scene_ab, newCache.bundleId.sceneName);
                        AddAsset(build, newBuildCache);
                        var scenePrefabBuild = GetUpdateABBuild(EnumAB.scenemodle_ab);
                        foreach (var child in assetInfo.m_children)
                        {
                            AddAsset(scenePrefabBuild, child.m_cacheData);
                        }
                    }
                }
                else if (newCache.bundleType == EnumAB.scenemodle_ab)
                {
                    var newBuildCache = assetInfo.m_cacheData;
                    if (newBuildCache.Equals(oldCache))
                    {
                        AddAsset(oldBuild, newCache);
                    }
                    else
                    {
                        TransToParent(assetInfo, EnumAB.scenemodle_ab);
                    }
                }
                else
                {
                    var newBuildCache = assetInfo.m_cacheData;
                    if (newBuildCache.Equals(oldCache))
                    {
                        AddAsset(oldBuild, newCache);
                    }
                    else
                    {
                        //上面是三个并不通用的规则,这里是通用规则,如果一个文件有改变,那么谁引用它,那么谁就要重新build咯
                        TransToParent(assetInfo, assetInfo.m_cacheData.bundleId.buildType);
                    }
                }
                //以上结构不好,我就不整理了
            }
        }
        foreach (var keyvalue in m_dependsDic)
        {
            if (!m_abbuildDic.ContainsKey(keyvalue.Value.m_cacheData.bundleId))
            {
                var ab = new ABBundleInfo();
                ab.bundleId = keyvalue.Value.m_cacheData.bundleId;
                m_abbuildDic.Add(keyvalue.Value.m_cacheData.bundleId, ab);
            }
            m_abbuildDic[keyvalue.Value.m_cacheData.bundleId].fileList.Add(keyvalue.Key);
        }
    }