Exemplo n.º 1
0
 public void CalculateProcess(string ResClass, string ABKey,
                              double process, bool isFinish)
 {
     allprocess = (CurSize + process * newClassInfo.ABName[ABKey]) / totalSize;
     if (isFinish)
     {
         CurSize += newClassInfo.ABName[ABKey];
         if (oldClassInfo != null)
         {
             oldClassInfo.ABName[ABKey] = newClassInfo.ABName[ABKey];
         }
         Debug.Log("CurSize : " + CurSize + " totalSize:" + totalSize);
         if (CurSize.Equals(totalSize))
         {
             //覆盖本地info.txt
             FileHelper.CreatFile(ABHotUpdate.Instance.GetSavePathByClass(ResClass, false),
                                  System.Text.Encoding.UTF8.GetBytes(SerializeHelper.ToJson(newClassInfo)));
             ABprocessevent.InvokeGracefully(1, true, DownStatus.Sucess, "");
         }
         else
         {
             ABprocessevent.InvokeGracefully(allprocess, false, DownStatus.Downloding, "");
         }
     }
     else
     {
         ABprocessevent.InvokeGracefully(allprocess, isFinish, DownStatus.Sucess, "");
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// MD5检测回调
 /// </summary>
 public void ABMD5ResultCallback(ABClassDownInfo ABDowninfo, DownStatus downResult, string downError)
 {
     //从保存下载的字典里移除
     RemoveDownload(ABDowninfo.ResClass, true, ABDataHolder.Instance.GetMD5DownURL() + ABDowninfo.ResClass.ToString() + "Info.txt");
     AddProductDownInfo(ABDowninfo);
     //回调MD5的结果,可根据结果进行处理
     ABDowninfo.ABMD5Callback.InvokeGracefully(ABDowninfo, downResult, downError);
     if (downResult == DownStatus.Sucess)
     {
         //Debug.Log("MD5检测结果:" + ABDowninfo.aBState);
         //这里分成了产品AB包和普通AB包,如果产品AB包需要直接下载,可在ABMD5callback回调中自己实现
         if (ABDowninfo.isHasRecog)
         {
             if (ABDowninfo.aBState != ABState.Newest)
             {
                 //覆盖本地info.txt
                 FileHelper.CreatFile(GetSavePathByClass(ABDowninfo.ResClass, false),
                                      System.Text.Encoding.UTF8.GetBytes(SerializeHelper.ToJson(ABDowninfo.newClassInfo)), true);
             }
         }
         else
         {
             //Debug.Log("不是识别AB包的下载");
             if (ABDowninfo.aBState == ABState.Newest)
             {
                 //覆盖本地info.txt
                 FileHelper.CreatFile(GetSavePathByClass(ABDowninfo.ResClass, false),
                                      System.Text.Encoding.UTF8.GetBytes(SerializeHelper.ToJson(ABDowninfo.newClassInfo)), true);
                 //没有需要热更的
                 mABDownInfo[ABDowninfo.ResClass].IsDownFinish = true;     //下载完成
                 ABDowninfo.ABprocessevent.InvokeGracefully(1, true, DownStatus.Sucess, "");
             }
             else
             {
                 //计算大小并下载
                 DownClassAB(ABDowninfo.ResClass);
             }
         }
     }
 }
Exemplo n.º 3
0
        //写入数据
        //resPathDic : 路径对应的AB包
        static void WriteData(Dictionary <string, string> resPathDic, ConfigWritingMode configWritingMode, PackageABType packageABType)
        {
            AssetBundleConfig config = new AssetBundleConfig();

            config.ABList = new List <ABBase>();
            foreach (string path in resPathDic.Keys)
            {
                //进行赋值
                ABBase abBase = new ABBase();
                abBase.Path       = path;
                abBase.Crc        = Crc32.GetCrc32(path);
                abBase.ABName     = resPathDic[path];
                abBase.AssetName  = path.Remove(0, path.LastIndexOf("/", System.StringComparison.Ordinal) + 1);
                abBase.ABDependce = new List <string>();
                string[] resDependce = AssetDatabase.GetDependencies(path);
                for (int i = 0; i < resDependce.Length; i++)
                {
                    string tempPath = resDependce[i];
                    //排除自身与脚本文件
                    if (tempPath == path || path.EndsWith(".cs", System.StringComparison.Ordinal))
                    {
                        continue;
                    }

                    string abName = "";
                    //所依赖的资源是不是在其他AB包里面
                    if (resPathDic.TryGetValue(tempPath, out abName))
                    {
                        if (abName == resPathDic[path])
                        {
                            continue;
                        }
                        //判断是否已经添加到aBBase包里面
                        if (!abBase.ABDependce.Contains(abName))
                        {
                            abBase.ABDependce.Add(abName);
                        }
                    }
                }
                config.ABList.Add(abBase);
            }
            switch (configWritingMode)
            {
            case ConfigWritingMode.TXT:
                string txtPath = EditorAssetPath.ABInfoPath + buildTarget.ToString() + "/AssetbundleConfig.txt";
                if (File.Exists(txtPath))
                {
                    File.Delete(txtPath);
                }
                FileStream   fileStream1 = new FileStream(txtPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                StreamWriter sw1         = new StreamWriter(fileStream1, System.Text.Encoding.UTF8);
                string       configJson  = SerializeHelper.ToJson(config);
                sw1.Write(configJson);
                sw1.Close();
                fileStream1.Close();
                break;

            case ConfigWritingMode.XML:
                CreateXML(config, packageABType);
                break;

            case ConfigWritingMode.Binary:
                foreach (ABBase abBase in config.ABList)
                {
                    abBase.Path = "";
                }
                string     BinaryPath = "Assets/AssetbundleConfig.bytes";
                FileStream fs         = new FileStream(PathTool.ProjectPath + BinaryPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
                fs.Seek(0, SeekOrigin.Begin);
                fs.SetLength(0);
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fs, config);
                fs.Close();
                CreateXML(config, packageABType);
                AssetDatabase.Refresh();
                SetABName("assetbundleconfig", BinaryPath);
                break;
            }
        }