Beispiel #1
0
    private void DownloadHot()
    {
        state = STATE.DOWNLLOAD_HOT;

        hotUI.HOT_InitHot();

        //内存判断
        if (PGameTools.GetStorageSize() < updateSize)
        {
            hotUI.OutOfMemory(updateSize);
            return;
        }

        currentUpdateVersionFileIndex = updateVersionFileCount - updateVersionFileList.Count + 1;

        var fileInfo  = updateVersionFileList[0];
        var url       = FormatUrl(serverUrl, GetRouteRoot() + fileInfo.WebPath);
        var localPath = fileInfo.DataLocalPath;

        if (download == null)
        {
            download = HotDownload.Create();
        }

        download.Download(url, localPath,
                          () =>
        {
            RGLog.Log("热更新下载 url : " + url);
        },
                          () =>
        {
            updateVersionFileList.RemoveAt(0);
            if (updateVersionFileList.Count > 0)
            {
                DownloadHot();
            }
            else
            {
                hotUI.HOT_HotFinished();
                EnterGame();
            }
        }, (progress) =>
        {
            hotUI.HOT_SetHotProgress(updateVersionFileCount, currentUpdateVersionFileIndex, progress);
        }, (error) =>
        {
            hotUI.HOT_HotError(error, this);
        });
    }
Beispiel #2
0
    /// <summary>
    /// 打包UPK
    /// </summary>
    /// <param name="infoList"></param>
    /// <param name="upkPath"></param>
    /// <param name="infoPath"></param>
    public static void Pack(List <UPKInfo> infoList, string upkPath, string infoPath)
    {
        //检查upk目录
        var dirUpk = Path.GetDirectoryName(upkPath);

        if (!Directory.Exists(dirUpk))
        {
            Directory.CreateDirectory(dirUpk);
        }
        if (File.Exists(upkPath))
        {
            File.Delete(upkPath);
        }

        //检查 info 目录
        string dirInfo = Path.GetDirectoryName(infoPath);

        if (!Directory.Exists(dirInfo))
        {
            Directory.CreateDirectory(dirInfo);
        }
        if (File.Exists(infoPath))
        {
            File.Delete(infoPath);
        }

        // 打包UPK
        FileStream upkStream = new FileStream(upkPath, FileMode.Create);

        for (int i = 0; i < infoList.Count; i++)
        {
            var        info           = infoList[i];
            FileStream fileStreamRead = new FileStream(info.absolutePath, FileMode.Open, FileAccess.Read);
            if (fileStreamRead == null)
            {
                RGLog.Log("读取文件失败:" + info.relativePath);
                return;
            }

            byte[] fileData = new byte[info.length];
            fileStreamRead.Read(fileData, 0, (int)info.length);
            fileStreamRead.Close();

            upkStream.Write(fileData, 0, (int)info.length);
        }
    }
Beispiel #3
0
    // 下载首包
    private void DownloadFirstUpk()
    {
        state = STATE.DOWNLOAD_FIRST_ZIP;

        hotUI.HOT_InitDownloadFirst();

        // 内存判断
        if (PGameTools.GetStorageSize() < DownloadFirstMemorySize)
        {
            hotUI.OutOfMemory(DownloadFirstMemorySize);
            return;
        }

        var url       = string.Format("{0}{1}/{2}/{3}", serverUrl, GetRouteRoot().TrimStart('/'), VersionInfo.BundleVersion, "first.upk");
        var localPath = Path.Combine(Util.DataPath, "first.upk");

        // 需要下载首包
        if (download == null)
        {
            download = HotDownload.Create();
        }
        download.Download(url, localPath, () =>
        {
            RGLog.Log("首包开始下载");
        },
                          () =>
        {
            hotConfig.first_upk_download = HOT_STATE.SUCCEED;
            hotConfig.Save();

            hotUI.HOT_DownloadFirstFinished();

            //解首包 upk
            UnpackFirstUpk();
        },
                          (progress) =>
        {
            hotUI.HOT_SetDownloadFirstProgress(progress);
        },
                          (error) =>
        {
            hotUI.HOT_DownloadFirstError(error, this);
        });
    }
Beispiel #4
0
    // 保存开发模式下开发人员配置
    public void SaveDevelop()
    {
        RGLog.Log("保存 Develop Hot Config 配置 :" + configPath);

        if (File.Exists(configPath))
        {
            File.Delete(configPath);
        }

        StringBuilder hotSb = new StringBuilder();

        hotSb.AppendLine("{");
        hotSb.AppendFormat("\t\"{0}\":{1},\n", "first_upk_download", HOT_STATE.SUCCEED);
        hotSb.AppendFormat("\t\"{0}\":{1},\n", "first_upk_unpack", HOT_STATE.SUCCEED);
        hotSb.AppendFormat("\t\"{0}\":{1},\n", "streaming_upk_unpack", HOT_STATE.SUCCEED);
        hotSb.AppendLine("}");

        File.WriteAllText(configPath, hotSb.ToString());
    }
Beispiel #5
0
    private static void LoadAssetAsync(string packageName, string assetName, Action <UnityEngine.Object, LoadEventData> loadComplete, LoadEventData evData = null)
    {
        var package = PackageManager.CreatePackage(packageName);

        if (evData != null)
        {
            if (evData.data.Length > 0)
            {
                if (evData.data[0].ToString().Equals(RGResource.PRESTRAIN_FLAG))
                {
                    package.IsAutoRelease = true;
                }
                else if (evData.data[0].ToString().Equals(RGResource.LOAD_BUNDLE_FOREVER_FLAG))
                {
                    package.IsAutoRelease = false;
                }
            }
        }

        // 场景
        if (package.IsScene)
        {
            package.LoadSceneAsync(loadComplete, evData);
            return;
        }

        // 获取资源,如果已经缓存,就直接返回
        var asset = package.GetAsset(assetName);

        if (asset != null)
        {
            if (loadComplete != null)
            {
                loadComplete(asset, evData);
                RGLog.DebugResLoad("<color=yellow>[ Read Cache Res]</color>" + assetName);
                return;
            }
        }
        RGLog.Log(" 111111111111 " + loadComplete);
        //bundle没有加载到内存,需要先加载bundle
        if (!package.IsLoadPackage)
        {
            package.LoadBundleAsync(assetName, loadComplete, evData);
            RGLog.DebugResLoad("<color=yellow>[ load bundle ]</color>" + assetName);
        }
        else
        {
            //bundle已经加载了,资源还没有加载
            if (package.IsUI || package.IsForverBundle)
            {
                if (loadComplete != null)
                {
                    loadComplete(package.GetBundle(), evData);
                    RGLog.DebugResLoad("<color=yellow>[ Read Cache Res ]</color>" + assetName);
                    return;
                }
            }
            package.LoadAssetAsync(assetName, loadComplete, evData);
            RGLog.DebugResLoad("<color=yellow>[ Load Asset ] </color>" + assetName);
        }
    }
Beispiel #6
0
 public void GetPoolNum(PoolType type)
 {
     RGLog.Log("type :" + type + " Num :" + poolDict[type].GetPoolNum());
 }
 public void OnStart()
 {
     GameManager.Instance.PressSweet(this);
     RGLog.Log(ToString());
 }