Beispiel #1
0
 //单个节点
 static AssetBundle LoadResNodeInternal(ReferenceNode node)
 {
     if (node == null)
     {
         return(null);
     }
     if (Bundle.ContainsKey(node.strResources))
     {
         return(Bundle[node.strResources]);
     }
     if (File.Exists(ResMng.GetResPath() + "/" + node.strResources))
     {
         FileStream fs     = new FileStream(ResMng.GetResPath() + "/" + node.strResources, FileMode.Open, FileAccess.Read);
         byte[]     buffer = new byte[fs.Length];
         fs.Read(buffer, 0, buffer.Length);
         fs.Close();
         AssetBundle ab = AssetBundle.LoadFromMemory(buffer);
         Bundle.Add(node.strResources, ab);
         return(ab);
     }
     return(null);
 }
Beispiel #2
0
    //这个是热更新打包系统支持的更新,由每一次新打包与上次打包的文件对比组成的
    //这个热更新系统不好维护,仅支持一些资源文件的更新等
    IEnumerator CheckNeedUpdate()
    {
        //仅在局域网下可用
        if (Application.internetReachability == NetworkReachability.NotReachable)
        {
            //不可用
            GameStart();
            yield break;
        }
        else if (Application.internetReachability == NetworkReachability.ReachableViaCarrierDataNetwork && GameStateMgr.gameStatus.OnlyWifi)
        {
            //3G-4G流量套餐
            //别更新
            GameStart();
            yield break;
        }
        else
        if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork || !GameStateMgr.gameStatus.OnlyWifi)
        {
            //Debug.LogError("download:" + string.Format(strVFile, strHost, Main.port, strProjectUrl, strPlatform, strVFileName));
            UnityWebRequest vFile = new UnityWebRequest();
            vFile.url     = string.Format(strFile, strHost, Main.port, strProjectUrl, strVFileName);
            vFile.timeout = 5;
            DownloadHandlerBuffer dH = new DownloadHandlerBuffer();
            vFile.downloadHandler = dH;
            yield return(vFile.Send());

            if (vFile.isError || vFile.responseCode != 200)
            {
                Debug.LogError(string.Format("update version file:{0} error:{1} or responseCode:{2}", vFile.url, vFile.error, vFile.responseCode));
                vFile.Dispose();
                GameStart();
                yield break;
            }

            if (vFile.downloadHandler.data != null && vFile.downloadedBytes != 0)
            {
                if (File.Exists(ResMng.GetResPath() + "/" + strVFileName))
                {
                    File.Delete(ResMng.GetResPath() + "/" + strVFileName);
                }
                if (File.Exists(ResMng.GetResPath() + "/" + strVerFile))
                {
                    File.Delete(ResMng.GetResPath() + "/" + strVerFile);
                }
                Debug.Log(ResMng.GetResPath() + "/" + strVFileName);
                File.WriteAllBytes(ResMng.GetResPath() + "/" + strVFileName, vFile.downloadHandler.data);
                ZipUtility.UnzipFile(ResMng.GetResPath() + "/" + strVFileName, ResMng.GetResPath() + "/");
                vFile.Dispose();
            }
            else
            {
                GameStart();
                yield break;
            }
            List <VersionItem> v = ReadVersionJson(File.ReadAllText(ResMng.GetResPath() + "/" + strVerFile));
            //从版本信息下载指定压缩包
            for (int i = 0; i < v.Count; i++)
            {
                if (v[i].strVersion == AppInfo.AppVersion() && v[i].strVersionMax != v[i].strVersion)
                {
                    UpdateHelper.ApplyVersion(v[i], this);
                    yield break;
                }
            }

            GameStart();
            yield break;
        }
        else
        {
            Log.WriteError("Application.internetReachability != NetworkReachability.ReachableViaLocalAreaNetwork");
            GameStart();
            yield break;
        }
    }