Beispiel #1
0
    public static void OutputXml()
    {
        if (ABSH == null)
        {
            ABSH = AssetBundleSettingHelperEditor.GetABSH(out ABPHInfo);
            if (ABPHInfo == null)
            {
            }
        }
        Selection.activeObject = ABSH;

        var abpi = ABSH.GetDataAnalysisXmlABPI();

        if (!Directory.Exists(abpi.Dir_Relative))
        {
            Directory.CreateDirectory(abpi.Dir_Relative);
        }
        XmlDocument doc     = new XmlDocument();
        XmlElement  AllRoot = doc.CreateElement(AssetBundleSettingHelper.xmlNode_PhaseRoot);

        doc.AppendChild(AllRoot);
        foreach (var p in PhaseABPreloadInfos_EditorAnalysis)
        {
            p.Value.OutputXMlNode(doc, AllRoot);
        }

        doc.Save(abpi.FullName_RelativePath);
    }
Beispiel #2
0
    /// <summary>
    /// 根据build assetbundle后返回的AssetBundleManifest 生成一个本次AssetBundle的信息文件,包含所有的AssetBundle文件名与其hash值。
    /// </summary>
    /// <param name="mf">build assetbundle后返回的manifest对象</param>
    /// <param name="versionName">一般是平台名字,也可以加其他文件夹在</param>
    private static void GenABVersionInfo(AssetBundleManifest mf, string versionName)
    {
        var         abpi   = ABSH.GetABInfoXmlPath(versionName);
        XmlDocument xmlDoc = null;

        //创建XML文档实例
        xmlDoc = new XmlDocument();
        XmlElement AllRoot = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_AssetBundles);

        //创建个时间属性,可以更直观的对比不同版本的
        AllRoot.SetAttribute(AssetBundleSettingHelper.xmlAttribute_CreateTime, VersionInfo.GetVersionString());
        xmlDoc.AppendChild(AllRoot);

        //输出结果按名字排序,以后要对比两个文件也方面一些
        var abNames = mf.GetAllAssetBundles().OrderBy(n => n).Select(key => AssetBundleSettingHelper.PathToPlatformFormat(key).ToLower());
        List <KeyValuePair <long, XmlElement> > allE = new List <KeyValuePair <long, XmlElement> >();

        foreach (var abName in abNames)
        {
            //bundle大小也输出一下
            FileInfo fi = new FileInfo(AssetBundleSettingHelper.Combine(abpi.Dir_Relative, abName));
            {
                //把bundle大小也写到AB依赖中
                string name = abName.Substring(0, abName.IndexOf(ABSH.AssetBundelExtName));
                var    drac = ABDependenciesPositive.GetDRAC(name, true);
                if (drac != null)
                {
                    drac.FinalSize = fi.Length;
                }
            }
            var        hash = mf.GetAssetBundleHash(abName);
            XmlElement node = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_AB);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_Name, abName);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_Hash, hash.ToString());
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSize, fi.Length.ToString());
            if (fi.Length < 1024)
            {
                node.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)fi.Length).ToString() + " B");
            }
            else if (fi.Length >= 1024 && fi.Length < 1024 * 1024)
            {
                node.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)fi.Length / 1024).ToString("f3") + " KB");
            }
            else
            {
                node.SetAttribute(AssetBundleSettingHelper.xmlNode_ABSizeXB, ((float)fi.Length / (1024 * 1024)).ToString("f3") + " MB");
            }
            allE.Add(new KeyValuePair <long, XmlElement>(fi.Length, node));
        }
        foreach (var node in allE.OrderByDescending(k => k.Key).ThenBy(k => k.Value.GetAttribute(AssetBundleSettingHelper.xmlNode_Name)))
        {
            AllRoot.AppendChild(node.Value);
        }
        //同名文件直接覆盖
        xmlDoc.Save(abpi.FullName);

        xmlDoc = VersionInfo.OutputXmlDoc();
        abpi   = ABSH.GetABXmlPath(versionName, VersionXmlInfo.FileName);
        xmlDoc.Save(abpi.FullName);
    }
 public static void ABSHInitAndSelect()
 {
     if (ABSH == null)
     {
         ABSH = AssetBundleSettingHelperEditor.GetABSH(out ABPHInfo);
     }
     Selection.activeObject = ABSH;
 }
Beispiel #4
0
 DependenciesRefAndCount(string sKey)
 {
     sKey      = AssetBundleSettingHelper.PathToPlatformFormat(sKey).ToLower();
     key       = sKey;
     count     = 0;
     finalSize = 0;
     refs      = new List <string>();
 }
Beispiel #5
0
    public string Dir_Relative;                    //相对路径,例如"assets\\streamingassets\\apple\\assets\\resources\\prefabs"
    #endregion
    public ABPInfo(string name, string extName, string path = "", bool bFindPath = false, string relativePath = "", bool bFindRelativePath = false)
    {
        name         = AssetBundleSettingHelper.PathToPlatformFormat(name.ToLower());
        path         = AssetBundleSettingHelper.PathToPlatformFormat(path.ToLower());
        relativePath = AssetBundleSettingHelper.PathToPlatformFormat(relativePath.ToLower());

        ExtName = extName.ToLower();;
        string tmpRP = "";

        if (!name.Equals(""))
        {
            //name中可能自己就带有路径,所以要剥离出来
            char slash = AssetBundleSettingHelper.GetSlash();
            int  idxLS = name.LastIndexOf(slash);
            if (idxLS > 0)
            {
                //名字里包含路径
                tmpRP = name.Substring(0, idxLS);
                Name  = name.Substring(idxLS + 1);
            }
            else
            {
                Name = name;
            }
            //名字最末端如果正是扩展名,那么把它干掉,所以一定不能出现连续相同扩展名在结尾,如XXXXX.assetbundle.assetbundle
            if (!ExtName.Equals(""))
            {
                if (Name.EndsWith(ExtName))
                {
                    Name = Name.Substring(0, Name.Length - ExtName.Length);
                }
            }
            NameWithExt = Name + ExtName;
        }

        AssetName = name;
        if (!AssetName.Equals(""))
        {
            if (AssetName.EndsWith(ExtName))
            {
                AssetName = AssetName.Substring(0, AssetName.Length - ExtName.Length);
            }
            DependencyName = AssetName + ExtName;
        }

        if (!path.Equals("") || bFindPath)
        {
            SetPath(Path.Combine(path, tmpRP));
        }
        else if (!relativePath.Equals("") || bFindRelativePath)
        {
            SetRelativePath(Path.Combine(relativePath, tmpRP));
        }



        CaseToLower();
    }
 public static void SaveABSH(AssetBundleSettingHelper absh, ABPInfo abpi)
 {
     EditorUtility.SetDirty(absh);
     AssetDatabase.SaveAssets();
     //      EditorApplication
     //          Application
     //          Editor.
     //absh.SetDirty();
 }
    public static ABPInfo GetABOutputABPIByVersion(this AssetBundleSettingHelper absh, string versionName, string name, string extName = "")
    {
        if (extName.Equals(""))
        {
            extName = absh.AssetBundelExtName;
        }
        string  path = Path.Combine(absh.ABOutputPath, versionName);
        ABPInfo abpi = new ABPInfo(name, extName, relativePath: path);

        return(abpi);
    }
Beispiel #8
0
 public DependenciesRefAndCount this[string key]
 {
     get
     {
         key = AssetBundleSettingHelper.PathToPlatformFormat(key).ToLower();
         return(dic[key]);
     }
     set
     {
         key      = AssetBundleSettingHelper.PathToPlatformFormat(key).ToLower();
         dic[key] = value;
     }
 }
Beispiel #9
0
 private void DeleteFile(List <string> deleteList, AssetBundleSettingHelper ABSettingHelper)
 {
     if (deleteList == null || deleteList.Count == 0)
     {
         return;
     }
     foreach (var f in deleteList)
     {
         var abpi = ABSettingHelper.GetCurPlatformABPath(f);
         File.Delete(abpi.FullName);
         StageInfo.AddUC();
     }
 }
Beispiel #10
0
 public DependenciesRefAndCount GetDRAC(string key, bool dontAdd = false)
 {
     key = AssetBundleSettingHelper.PathToPlatformFormat(key).ToLower();
     if (!allDic.ContainsKey(key))
     {
         if (dontAdd)
         {
             return(null);
         }
         var d = DependenciesRefAndCount.GetNew(key);
         allDic.Add(key, d);
     }
     return(allDic[key]);
 }
Beispiel #11
0
    private void UpdateFile(ABPInfo abpi, byte[] bytes, AssetBundleSettingHelper ABSettingHelper)
    {
        if (!Directory.Exists(abpi.Dir_Full))
        {
            Directory.CreateDirectory(abpi.Dir_Full);
        }
        if (File.Exists(abpi.FullName))
        {
            File.Delete(abpi.FullName);
        }
        FileStream fsDes = File.Create(abpi.FullName);

        fsDes.Write(bytes, 0, bytes.Length);
        fsDes.Flush();
        fsDes.Close();
    }
Beispiel #12
0
    public void SetRelativePath(string rPath)
    {
        Dir_Relative = AssetBundleSettingHelper.PathToPlatformFormat(rPath);

        var rootPath = AssetBundleSettingHelper.PathToPlatformFormat(Application.dataPath);

        rootPath = rootPath.Substring(0, rootPath.Length - AssetBundleSettingHelper.Asset_RelativePath.Length);
        Dir_Full = Path.Combine(rootPath, Dir_Relative);
        if (NameWithExt != null)
        {
            FullName_RelativePath = (Path.Combine(Dir_Relative, NameWithExt));
            FullName = Path.Combine(rootPath, FullName_RelativePath);
            URI      = AssetBundleSettingHelper.PathToFileUri(FullName);
            FullNameWithoutExtName_Relative = FullName_RelativePath.Substring(0, FullName_RelativePath.Length - ExtName.Length);
        }
    }
Beispiel #13
0
 /// <summary>
 /// 整个文件夹拷贝功能
 /// </summary>
 /// <param name="srcPath">源文件夹</param>
 /// <param name="tarPath">目标文件夹</param>
 private static void CopyFolder(string srcPath, string tarPath)
 {
     if (!Directory.Exists(srcPath))
     {
         return;
     }
     if (!Directory.Exists(tarPath))
     {
         Directory.CreateDirectory(tarPath);
     }
     CopyFile(srcPath, tarPath);
     string[] directionName = Directory.GetDirectories(srcPath);
     foreach (string dirPath in directionName)
     {
         string directionPathTemp = AssetBundleSettingHelper.Combine(tarPath, dirPath.Substring(srcPath.Length + 1));
         CopyFolder(dirPath, directionPathTemp);
     }
 }
Beispiel #14
0
 /// <summary>
 /// 文件夹下具体文件的拷贝,.meta .manifest和xml文件目前不拷贝
 /// </summary>
 /// <param name="srcPath">源文件夹</param>
 /// <param name="tarPath">目标文件夹</param>
 private static void CopyFile(string srcPath, string tarPath)
 {
     string[] filesList = Directory.GetFiles(srcPath);
     //.meta文件会自动生成,不需要拷贝
     //.manifest对于实际加载AB没有意义,不需要拷贝
     //.xml目前是用来记录AB信息的,不需要运行时加载,不需要拷贝
     foreach (string f in filesList.Where(f => !f.EndsWith(".meta") && !f.EndsWith(".manifest") && (!f.EndsWith(".xml") || f.EndsWith(VersionXmlInfo.FileName + AssetBundleSettingHelper.xmlExtName))))
     {
         string fTarPath = AssetBundleSettingHelper.Combine(tarPath, f.Substring(srcPath.Length + 1));
         if (File.Exists(fTarPath))
         {
             File.Copy(f, fTarPath, true);
         }
         else
         {
             File.Copy(f, fTarPath);
         }
     }
 }
Beispiel #15
0
 /// <summary>
 /// 整个文件夹拷贝功能
 /// </summary>
 /// <param name="srcPath">源文件夹</param>
 /// <param name="tarPath">目标文件夹</param>
 private static void CopyFolder(string srcPath, string tarPath)
 {
     if (!Directory.Exists(srcPath))
     {
         AssetBundleHelper.TestLog("!Directory.Exists(srcPath):" + srcPath);
         return;
     }
     if (!Directory.Exists(tarPath))
     {
         AssetBundleHelper.TestLog("Directory.CreateDirectory(tarPath)" + tarPath);
         Directory.CreateDirectory(tarPath);
     }
     string[] directionName = Directory.GetDirectories(srcPath);
     foreach (string dirPath in directionName)
     {
         string directionPathTemp = AssetBundleSettingHelper.Combine(tarPath, dirPath.Substring(srcPath.Length + 1));
         CopyFolder(dirPath, directionPathTemp);
     }
     //让最外层在最后拷贝
     CopyFile(srcPath, tarPath);
 }
Beispiel #16
0
    /// <summary>
    /// 删除指定名称的文件
    /// 会处理相关的相对路径
    /// </summary>
    /// <param name="path">搜索的目录</param>
    /// <param name="versionName">一般是平台名字,也可以加其他文件夹在</param>
    /// <param name="fileNames">需要删除的文件名字,相对路径,斜杠为/</param>
    private static void DeleteAssetBundleFiles(string path, string versionName, Dictionary <string, string> fileNames)
    {
        DirectoryInfo fileDir = new DirectoryInfo(path);

        FileInfo[] files = fileDir.GetFiles();
        foreach (var file in files)
        {
            //绝对路径转换为相对路径,并且转换为UNIX的斜杠‘/’
            var abpi = ABSH.GetAssetBundleOutputPath(versionName);
            //路径里可千万别有相同的目录结构啊……比如 Assets/AssetBundles/Windows64/XXXXXX/Assets/AssetBundles/Windows64/
            int index = file.FullName.LastIndexOf(abpi.Dir_Relative) + abpi.Dir_Relative.Length + 1;
            if (index >= 0)
            {
                if (index < file.FullName.Length)
                {
                    var relativePath = AssetBundleSettingHelper.PathToPlatformFormat(file.FullName.Substring(index));
                    //Debug.Log(relativePath);
                    if (fileNames.ContainsKey(relativePath.ToLower()))
                    {
                        DeleteFileAndManifest(file.FullName);
                    }
                }
                else
                {
                    Debug.LogError("DeleteAssetBundleFiles Error:" + file.FullName + " :abpi.Dir_Relative:" + abpi.Dir_Relative);
                }
            }
        }
        var dirs = fileDir.GetDirectories();

        foreach (var dir in dirs)
        {
            //递归调用
            DeleteAssetBundleFiles(dir.FullName, versionName, fileNames);
        }
    }
    public static AssetBundleSettingHelper GetABSH(out ABPInfo abpInfo)
    {
        AssetBundleSettingHelper absh = null;

        abpInfo = GetABPInfo();
        var fi = new FileInfo(abpInfo.FullName);

        if (fi.Exists)
        {
            absh = AssetDatabase.LoadAssetAtPath <AssetBundleSettingHelper>(abpInfo.FullName_RelativePath);
            if (absh == null)
            {
                Debug.LogError("Not found :" + abpInfo.FullName + " then create");
            }
            else
            {
                return(absh);
            }
        }

        absh = ScriptableObject.CreateInstance <AssetBundleSettingHelper>();
        CreateABSH(absh, abpInfo);
        return(absh);
    }
Beispiel #18
0
    public void SetPath(string path)
    {
        path = AssetBundleSettingHelper.PathToPlatformFormat(path);;
        var rootPath = AssetBundleSettingHelper.PathToPlatformFormat(Application.dataPath);

        rootPath = rootPath.Substring(0, rootPath.Length - AssetBundleSettingHelper.Asset_RelativePath.Length);
        if (NameWithExt != null)
        {
            FullName = AssetBundleSettingHelper.PathToPlatformFormat(Path.Combine(path, NameWithExt));
            var index = FullName.IndexOf(rootPath) + rootPath.Length;
            if (index < FullName.Length)
            {
                FullName_RelativePath           = FullName.Substring(index);
                FullNameWithoutExtName_Relative = FullName_RelativePath.Substring(0, FullName_RelativePath.Length - ExtName.Length);
            }
            else
            {
                Debug.LogError("ABPInfo::SetPath Error:" + FullName + " :pathPrefix:" + rootPath);
            }
            URI = AssetBundleSettingHelper.PathToFileUri(FullName);
        }
        Dir_Relative = path.Substring(path.IndexOf(rootPath) + rootPath.Length + 1);
        Dir_Full     = path;
    }
Beispiel #19
0
 public void AddRef(string sRef)
 {
     sRef = AssetBundleSettingHelper.PathToPlatformFormat(sRef).ToLower();
     count++;
     refs.Add(sRef);
 }
 public static ABPInfo GetABXmlPath(this AssetBundleSettingHelper absh, string versionName, string name)
 {
     return(absh.GetABOutputABPIByVersion(versionName, name, AssetBundleSettingHelper.xmlExtName));
 }
Beispiel #21
0
    /// <summary>
    /// 对比上次打包结果,输出新增,删除和改变的部分。
    /// </summary>
    /// <param name="oldABVersionInfo">GetABVersionInfo返回的值,也就是上一次打包的结果信息</param>
    /// <param name="newMf">build assetbundle后返回的manifest对象</param>
    /// <param name="versionName">一般是平台名字,也可以加其他文件夹在</param>
    private static void CompareOldInfoAndNewManifest(Dictionary <string, string> oldABVersionInfo, AssetBundleManifest newMf, string versionName,
                                                     out Dictionary <string, string> newAB, out Dictionary <string, string> delAB, out Dictionary <string, KeyValuePair <string, string> > changedAB)
    {
        //临时记录新增的AssetBundle
        newAB = new Dictionary <string, string>();
        //临时记录删除的AssetBundle,这里返回后可以查找已经不需要存在的assetbundle,可以手动删除
        delAB = new Dictionary <string, string>();
        //临时记录改变的AssetBundle
        changedAB = new Dictionary <string, KeyValuePair <string, string> >();
        var abNames = newMf.GetAllAssetBundles().Select(key => AssetBundleSettingHelper.PathToPlatformFormat(key).ToLower());

        foreach (var name in abNames)
        {
            var newHash = newMf.GetAssetBundleHash(name).ToString();
            if (oldABVersionInfo.ContainsKey(name))
            {
                if (!oldABVersionInfo[name].Equals(newHash))
                {
                    //changedAB
                    changedAB.Add(name, new KeyValuePair <string, string>(oldABVersionInfo[name], newHash));
                }
                else
                {
                    //not changed
                }
                oldABVersionInfo.Remove(name);
            }
            else
            {
                //newAB
                newAB.Add(name, newHash);
            }
        }
        foreach (var name in oldABVersionInfo)
        {
            delAB.Add(name.Key, name.Value);
        }
        //对结果进行排序
        newAB.OrderBy(n => n);
        delAB.OrderBy(n => n);
        changedAB.OrderBy(n => n);

        //创建XML文档实例
        var abpi = ABSH.GetDifferXmlPath(versionName);
        //string filepath = ABSH.GetDifferXmlPath(versionName);
        XmlDocument xmlDoc  = new XmlDocument();
        XmlElement  AllRoot = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_AssetBundles);

        xmlDoc.AppendChild(AllRoot);

        //创建个时间属性,可以更直观的对比不同版本的
        AllRoot.SetAttribute(AssetBundleSettingHelper.xmlAttribute_CreateTime, VersionInfo.GetVersionString());

        XmlElement NewRoot = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_NewAssetBundles);

        AllRoot.AppendChild(NewRoot);
        foreach (var nAB in newAB)
        {
            XmlElement node = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_AB);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_Name, nAB.Key);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_Hash, nAB.Value);
            NewRoot.AppendChild(node);
        }
        XmlElement ChangedRoot = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_ChangedAssetBundles);

        AllRoot.AppendChild(ChangedRoot);
        foreach (var cAB in changedAB)
        {
            XmlElement node = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_AB);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_Name, cAB.Key);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_OldHash, cAB.Value.Key);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_NewHash, cAB.Value.Value);
            ChangedRoot.AppendChild(node);
        }
        XmlElement DelRoot = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_DelAssetBundles);

        AllRoot.AppendChild(DelRoot);
        foreach (var dAB in delAB)
        {
            XmlElement node = xmlDoc.CreateElement(AssetBundleSettingHelper.xmlNode_AB);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_Name, dAB.Key);
            node.SetAttribute(AssetBundleSettingHelper.xmlNode_Hash, dAB.Value);
            DelRoot.AppendChild(node);
        }
        //直接覆盖上次结果
        xmlDoc.Save(abpi.FullName);
    }
Beispiel #22
0
    /// <summary>
    /// 获得路径下所有非meta文件,递归搜索文件夹
    /// </summary>
    /// <param name="path">搜索的目标文件夹</param>
    /// <returns>返回一个序列,包含每一个文件的信息和相对于assets文件夹的路径</returns>
    private static List <KeyValuePair <string, FileInfo> > GetAllFilesWithoutMeta(string path)
    {
        var list = new List <KeyValuePair <string, FileInfo> >();

        if (Directory.Exists(path))
        {
            DirectoryInfo fileDir = new DirectoryInfo(path);
            var           files   = fileDir.GetFiles();

            list.AddRange(files.Where(f => !f.Name.Contains(".meta")).Select(
                              //这里文件名进行了转换,windows下都变成\\,OSX下都是/
                              f => new KeyValuePair <string, FileInfo>(f.FullName.Substring(f.FullName.IndexOf(AssetBundleSettingHelper.PathToPlatformFormat(ABSH.NeedBuildABPath))).ToLower(), f)
                              ));
            var dirs = fileDir.GetDirectories();
            foreach (var dir in dirs)
            {
                //递归
                var tmpList = GetAllFilesWithoutMeta(dir.FullName);
                list.AddRange(tmpList);
            }
        }
        return(list);
    }
Beispiel #23
0
    public IEnumerator CheckAndUpdateABToPD(AssetBundleSettingHelper ABSettingHelper, AssetBundleHelper abh, Action callback = null)
    {
        StageInfo.ToStage(UpdaterStage.CheckCopySAToPD);
        {
            //先大致写下思路,android下,streamingAssets目录是在jar包里的,所以不能直接操作文件和路径,得www或者assetbundle.loadfromfile去读取,但是其他地方可以直接读,所以为了照顾android,SA目录下都改用www和assetbundle.loadfromfile
            //但是有些地方需要搞复制这种事,所以WWW后可以直接写入到新文件中。所以可以发现很多地方用了www


            //如果使用AB,检查一下自己的私有目录下是否有assetbundle的拷贝,如果没有则把所有的AB拷过去
            //bool bCopySAToPDFinished = false;
            if (!ABSettingHelper.UseAssetBundle || ABSettingHelper.UseSteamingAssetRes)
            {
                StageInfo.ToStage(UpdaterStage.NotNeedUpdater);
                if (callback != null)
                {
                    callback.Invoke();
                }
                yield break;
            }
            var abpiSrc = ABSettingHelper.GetCurABVersionXmlStreamingAssetPath();
            var abpiDst = ABSettingHelper.GetCurABVersionXmlPersistentDataPath();
            //首先检查目标文件是否存在
            if (!File.Exists(abpiDst.FullName))
            {
                //不存在,这个时候无脑删除文件夹,然后拷贝,防止文件夹里残留了奇怪的东西
                abh.StartCoroutine(CopyAllABToPD(ABSettingHelper, abh, () => StageInfo.ToStage(UpdaterStage.Copy_Over)));

                AssetBundleHelper.TestLog("!File.Exists(abpiDst.FullName):" + abpiDst.FullName);
            }
            else
            {
                //虽然存在,但是对比一下版本号,如果不如SA目录下的新,也是要覆盖过去的
                VersionXmlInfo verSrc = null;
                //AssetBundleHelper.TestLog("abpiSrc.URI:" + abpiSrc.URI);
                using (WWW www = new WWW(abpiSrc.URI))
                {
                    bool bFind = false;
                    while (true)
                    {
                        if (www.error != null)
                        {
                            Debug.LogError(www.error);
                            AssetBundleHelper.TestLog(www.error);
                            bFind = true;
                            break;
                        }
                        else if (www.isDone)
                        {
                            break;
                        }
                        yield return(null);
                    }
                    if (!bFind)
                    {
                        verSrc = GetVersion(www.bytes);
                    }
                }
                if (verSrc != null)
                {
                    //AssetBundleHelper.TestLog("abpiDst.URI:" + abpiDst.URI);
                    VersionXmlInfo verDst = null;

                    verDst = GetVersion(abpiDst.FullName);

                    //AssetBundleHelper.TestLog("verDst.IsUpTodate(verSrc)");
                    if (verDst.IsUpTodate(verSrc))
                    {
                        //目标版本比较新,所以什么都不用干
                        //AssetBundleHelper.TestLog("Is Up To Date");
                        StageInfo.ToStage(UpdaterStage.Copy_Over);
                    }
                    else
                    {
                        //无脑拷过去覆盖
                        //CopyAllABToPD(ABSettingHelper);

                        //AssetBundleHelper.TestLog("Copy all:");
                        abh.StartCoroutine(CopyAllABToPD(ABSettingHelper, abh, () => StageInfo.ToStage(UpdaterStage.Copy_Over)));
                    }
                }
                else
                {
                    StageInfo.ToStage(UpdaterStage.Copy_Over);
                }
            }
            //AssetBundleHelper.TestLog("Wait bCopySAToPDFinished");
            while (!StageInfo.IsStage(UpdaterStage.Copy_Over))
            {
                yield return(null);
            }
        }


        StageInfo.ToStage(UpdaterStage.DownloadRes);
        //然后检查网络上是否有更新的版本
        //尝试从网络上获得version的xml
        string VersionABPrefixUrl = Path.Combine(UrlPrefix, ABSettingHelper.GetPlatformPathName());
        string manifestUrl        = Path.Combine(VersionABPrefixUrl, ABSettingHelper.GetPlatformPathName());
        var    VersionUrl         = Path.Combine(VersionABPrefixUrl, VersionXmlInfo.FileName + AssetBundleSettingHelper.xmlExtName);

        //AssetBundleHelper.TestLog(@"Begin WWW VersionUrl:"+ VersionUrl);
        using (WWW www = new WWW(VersionUrl))
        {
            while (true)
            {
                yield return(null);

                //AssetBundleHelper.TestLog(@"Begin www Time:" + DateTime.Now.ToString());
                if (www.error != null)
                {
                    //Debug.Assert(false, "www.error != null " + www.error);
                    AssetBundleHelper.TestLog(@"www.error != null " + www.error);
                    StageInfo.ToStage(UpdaterStage.DownloadRes_Error);
                    if (callback != null)
                    {
                        callback.Invoke();
                    }

                    yield break;
                }
                else if (www.isDone)
                {
                    break;
                }
            }
//			AssetBundleHelper.TestLog(@"Begin etVersion(www.bytes):");
            var versionOnline = GetVersion(www.bytes);
/*			AssetBundleHelper.TestLog(@"Begin e11111111111:"+ versionOnline.GetVersionString());*/
            var abpiDst = ABSettingHelper.GetCurABVersionXmlPersistentDataPath();
//          AssetBundleHelper.TestLog(@"Begin 222222222222222222:"+ abpiDst.FullName);
//          AssetBundleHelper.TestLog(@"Begin 333333333333:" + Application.persistentDataPath);
            VersionXmlInfo verDst = null;
            try
            {
                verDst = GetVersion(abpiDst.FullName);
            }
            catch (Exception e)
            {
                AssetBundleHelper.TestLog(e.Message);
            }
            AssetBundleHelper.TestLog(@"Begin abpiDst.FullName:" + abpiDst.FullName);
            if (verDst != null && verDst.IsUpTodate(versionOnline))
            {
                AssetBundleHelper.TestLog(@"Up To Date Online:" + abpiDst.FullName);
                StageInfo.ToStage(UpdaterStage.ResIsUpToDate);
                //本地的是最新的,不需要更新
                if (callback != null)
                {
                    callback.Invoke();
                }
                yield break;
            }

            //Debug.Log("需要更新");
            //先下载manifest,然后下载所有需要更新的AB
            AssetBundleHelper.TestLog(@"Begin WWW manifestUrl:" + manifestUrl);
            using (WWW wwwMF = new WWW(manifestUrl))
            {
                while (true)
                {
                    yield return(null);

                    if (wwwMF.error != null)
                    {
                        AssetBundleHelper.TestLog(@"wwwMF.error != null " + wwwMF.error);
                        StageInfo.ToStage(UpdaterStage.DownloadRes_Error);
                        if (callback != null)
                        {
                            callback.Invoke();
                        }
                        yield break;;
                    }
                    else if (wwwMF.isDone)
                    {
                        break;
                    }
                }

                var           newManifest       = GetPathManifest(wwwMF.bytes);
                var           localManifestABPI = ABSettingHelper.GetCurPlatformManifestPath();
                var           localManifest     = GetPathManifest(localManifestABPI.FullName);
                List <string> updateList        = null;
                List <string> deleteList        = null;
                GetNeedUpdateList(localManifest, newManifest, out updateList, out deleteList);
                int needUpdateCount = 0;
                if (updateList != null)
                {
                    needUpdateCount += updateList.Count();
                }
                if (deleteList != null)
                {
                    needUpdateCount += deleteList.Count();
                }
                {
                    StageInfo.SetNUC(needUpdateCount);
                    DeleteFile(deleteList, ABSettingHelper);

                    if (updateList != null && updateList.Count > 0)
                    {
                        foreach (var f in updateList)
                        {
                            string dlUrl = Path.Combine(VersionABPrefixUrl, f);
                            using (WWW wwwUPDATE = new WWW(dlUrl))
                            {
                                while (true)
                                {
                                    yield return(null);

                                    if (wwwUPDATE.error != null)
                                    {
                                        AssetBundleHelper.TestLog(@"wwwUPDATE.error != null " + wwwUPDATE.error);
                                        StageInfo.ToStage(UpdaterStage.DownloadRes_Error);
                                        if (callback != null)
                                        {
                                            callback.Invoke();
                                        }
                                        yield break;;
                                    }
                                    else if (wwwUPDATE.isDone)
                                    {
                                        break;
                                    }
                                }
                                var abpi = ABSettingHelper.GetCurPlatformABPath(f);
                                UpdateFile(abpi, wwwUPDATE.bytes, ABSettingHelper);

                                if (wwwUPDATE.assetBundle != null)
                                {
                                    wwwUPDATE.assetBundle.Unload(false);
                                }
                            }
                            StageInfo.AddUC();
                            yield return(null);
                        }
                    }
                }
                //保存manifest
                UpdateFile(localManifestABPI, wwwMF.bytes, ABSettingHelper);
                if (wwwMF.assetBundle != null)
                {
                    wwwMF.assetBundle.Unload(false);
                }
                StageInfo.AddUC();
                yield return(null);
            }
            //最后需要保存version。xml
            UpdateFile(abpiDst, www.bytes, ABSettingHelper);
            if (www.assetBundle != null)
            {
                www.assetBundle.Unload(false);
            }

            StageInfo.AddUC();
            yield return(null);
        }

        StageInfo.ToStage(UpdaterStage.Download_Over);
        if (callback != null)
        {
            callback.Invoke();
        }
    }
 /// <summary>
 /// 把AB目录和版本信息组合成一个运行时能找到的目录
 /// </summary>
 /// <param name="versionName">版本信息,这是一个能区分各大主流平台的名字</param>
 /// <returns></returns>
 public static ABPInfo GetAssetBundleOutputPath(this AssetBundleSettingHelper absh, string versionName)
 {
     return(absh.GetABOutputABPIByVersion(versionName, ""));
 }
Beispiel #25
0
    /// <summary>
    /// 这是无脑拷贝StreamingAssets资源到PD目录
    /// </summary>
    private IEnumerator CopyAllABToPD(AssetBundleSettingHelper ABSettingHelper, AssetBundleHelper abh, Action callback = null)
    {
        StageInfo.ToStage(UpdaterStage.CopySAToPD);
        //这里是无脑拷贝版本,为了防止资源出错,可以重新搞一次
        var abpiSrc = ABSettingHelper.GetCurABVersionXmlStreamingAssetPath();
        var abpiDst = ABSettingHelper.GetCurABVersionXmlPersistentDataPath();

        //不存在,这个时候无脑删除文件夹,然后拷贝,防止文件夹里残留了奇怪的东西
        if (Directory.Exists(abpiDst.Dir_Full))
        {
            Directory.Delete(abpiDst.Dir_Full, true);
        }
//      AssetBundleHelper.TestLog("abpiSrc.Dir_Full:" + abpiSrc.Dir_Full);
//      AssetBundleHelper.TestLog("abpiSrc.FullName:" + abpiSrc.FullName);
//      AssetBundleHelper.TestLog("Application.dataPath:" + Application.dataPath);
//      AssetBundleHelper.TestLog("Application.streamingAssetsPath:" + Application.streamingAssetsPath);
//      AssetBundleHelper.TestLog("Application.persistentDataPath:" + Application.persistentDataPath);

        var localSAManifestABPI = ABSettingHelper.GetCurPlatformStreamingAssetManifestPath();
        var localSAManifest     = GetPathManifest(localSAManifestABPI.FullName);

        AssetBundleHelper.TestLog("ia am here *****" + localSAManifestABPI.FullName);
        if (localSAManifest != null)
        {
            //AssetBundleHelper.TestLog("if(localManifest != null) )))))))))))))))))))))))))))))))))))))))))))");
            var ABs = localSAManifest.GetAllAssetBundles();
            StageInfo.SetNUC(ABs.Length);
            foreach (var f in ABs)
            {
                var abpi    = ABSettingHelper.GetCurPlatformStreamingABPath(f);
                var abpiTar = ABSettingHelper.GetCurPlatformABPath(f);
                using (WWW www = new WWW(abpi.URI))
                {
                    while (true)
                    {
                        if (www.error != null)
                        {
                            Debug.LogError(www.error);
                            AssetBundleHelper.TestLog(www.error);
                            throw new NullReferenceException(www.url);
                        }
                        else if (www.isDone)
                        {
                            break;
                        }
                        yield return(null);
                    }
                    CreateFile(abpiTar, www.bytes);
                    if (www.assetBundle != null)
                    {
                        www.assetBundle.Unload(false);
                    }
                }
                StageInfo.AddUC();
                yield return(null);
            }


            //最后把manifeat和version也拷过去
            //manifest
            using (WWW www = new WWW(localSAManifestABPI.URI))
            {
                while (true)
                {
                    if (www.error != null)
                    {
                        Debug.LogError(www.error);
                        AssetBundleHelper.TestLog(www.error);
                        throw new NullReferenceException(www.url);
                    }
                    else if (www.isDone)
                    {
                        break;
                    }
                    yield return(null);
                }
                var localManifestABPI = ABSettingHelper.GetCurPlatformManifestPath();
                CreateFile(localManifestABPI, www.bytes);
                if (www.assetBundle != null)
                {
                    www.assetBundle.Unload(false);
                }
                StageInfo.AddUC();
                yield return(null);
            }
            //version XML
            using (WWW www = new WWW(abpiSrc.URI))
            {
                while (true)
                {
                    if (www.error != null)
                    {
                        Debug.LogError(www.error);
                        AssetBundleHelper.TestLog(www.error);
                        throw new NullReferenceException(www.url);
                    }
                    else if (www.isDone)
                    {
                        break;
                    }
                    yield return(null);
                }
                //var localManifestABPI = ABSettingHelper.GetCurPlatformManifestPath();
                CreateFile(abpiDst, www.bytes);

                StageInfo.AddUC();
                yield return(null);
            }
        }
        else
        {
            //SA目录里没有manifest的时候就什么都别干了
        }
        //CopyFolder(abpiSrc.Dir_Full, abpiDst.Dir_Full);
        if (callback != null)
        {
            callback.Invoke();
        }
    }
Beispiel #26
0
    /// <summary>
    /// 根据versionName获取需要打包的所有资源并返回AssetBundleBuild数组
    /// </summary>
    /// <param name="versionName">一般是平台名字,也可以加其他文件夹在</param>
    /// <returns>返回一个数组,可以直接用于BuildPipeline.BuildAssetBundles</returns>
    private static AssetBundleBuild[] GetBuildMapByVersion(string versionName)
    {
        List <AssetBundleBuild> list = new List <AssetBundleBuild>();

        if (!Directory.Exists(ABSH.NeedBuildABPath))
        {
            return(null);
        }
        var NeedBuildABFileList = GetAllFilesWithoutMeta(ABSH.NeedBuildABPath);
        var dicDependencies     = new Dictionary <string, string>();

        //遍历这些文件去找到所有的依赖项
        foreach (var file in NeedBuildABFileList)
        {
            //添加正向依赖,这个不可能会重复,所以不用判断ContainsKey
            ABDependenciesPositive.Add(file.Key, ABDependenciesPositive.GetDRAC(file.Key));
            //var relativePath = Path.Combine();
            var dps = AssetDatabase.GetDependencies(file.Key);
            //                                                                         这里文件名进行了转换,windows下都变成\\,OSX下都是/
            //也转换了一下小写
            foreach (var dp in dps.Where(d => !d.EndsWith(".cs")).Select(d => AssetBundleSettingHelper.PathToPlatformFormat(d.ToLower())))           //脚本文件排除
            {
                {
                    //增加反向依赖,这个会统计数量
                    if (!file.Key.Equals(dp))
                    {
                        if (!ABDependenciesReverse.ContainsKey(dp))
                        {
                            ABDependenciesReverse.Add(dp, ABDependenciesReverse.GetDRAC(dp));
                        }
                        ABDependenciesReverse[dp].AddRef(file.Key);

                        //正向依赖
                        ABDependenciesPositive[file.Key].AddRef(dp);
                    }
                }
                if (dicDependencies.ContainsKey(dp))
                {
                    continue;
                }
                else
                {
                    dicDependencies.Add(dp, dp);
                }
            }
        }
        //这里根据依赖关系,把只被一个单独AB依赖的资源不设置单独打包
        foreach (var abd in ABDependenciesReverse.GetDic().Where(dr => dr.Value.Count == 1))
        {
            if (dicDependencies.ContainsKey(abd.Key))
            {
                dicDependencies.Remove(abd.Key);
            }
        }
        //这里已经获得了所有的资源名称,可以直接生成AssetBundleBuild了
        foreach (var file in dicDependencies)
        {
            //目前先把所有资源单独打包,不做任何合并处理
            var tmp = new AssetBundleBuild();
            {
                tmp.assetBundleName = ABSH.ResourceNameToBundleName(file.Key);
                string[] assets = new string[1] {
                    file.Key
                };
                tmp.assetNames = assets;
            }
            list.Add(tmp);
        }

        return(list.ToArray());
    }
 public static void CreateABSH(AssetBundleSettingHelper absh, ABPInfo abpi)
 {
     AssetDatabase.CreateAsset(absh, abpi.FullName_RelativePath);
 }
Beispiel #28
0
 public static DependenciesRefAndCount  GetNew(string sKey)
 {
     sKey = AssetBundleSettingHelper.PathToPlatformFormat(sKey).ToLower();
     return(new DependenciesRefAndCount(sKey));
 }
Beispiel #29
0
 public bool ContainsKey(string key)
 {
     key = AssetBundleSettingHelper.PathToPlatformFormat(key).ToLower();
     return(dic.ContainsKey(key));
 }
Beispiel #30
0
 public void Add(string key, DependenciesRefAndCount value)
 {
     key = AssetBundleSettingHelper.PathToPlatformFormat(key).ToLower();
     dic.Add(key.ToLower(), value);
 }