[Game Development][Unity]Assetbundle Download (7) Get the download list at runtime (download while playing)

Table of contents

Packaging and resource loading framework directory

text

What is the runtime download manifest? Most mobile games now have a function of downloading while playing, which will prompt the user whether to enable downloading, XXX traffic is required, and if you finish downloading, there may be rewards.

 

Question: Why is there a function of downloading while playing?

Answer: The size of the package for sending the package is small, and the smaller the better!

If our game wants to make money, the first step is to let users download your game, and the second is to consider the issue of retention.

If your first package is 10G, the user will start scolding directly, wanting me to download a 10G package, how much face do you have.

How big should the first package be, how much needs to be updated, and how much needs to be downloaded in the game is a question of metaphysics, and there is no standard answer.

I think the resources of the first pack should at least ensure that new players can play for a day or two without downloading.

There are also some companies that are rude enough, the first package only has the framework, and all resources and business codes are hot updated.

In addition to prompting users to download, I don’t know if any company will secretly download without prompting, or detect that if it is in the WIFI state, secretly downloading, if the user wastes data without prompting, it may be suspected of breaking the law.


How does the AB package distinguish whether it is hot update at startup or download while playing?

I pasted the content of the first article and the AB package list,

The first line is the SVN version number

The second line is the number of AB packages

Starting from the third line is the resource package information, and the effective data is separated by the = sign, which are

MD5.unity3d = resource path = HashId of resource path = package body KB size = SVN version number = start hot update mode

The hot update startup mode mentioned above is specially used to mark this. In our project, buildin means hot update at startup, and InGame means download while playing.

 The following is the code for collecting and downloading the list while playing. The code is relatively simple, which is to judge each line of the download list. If the Tag is InGame, then add it to the list while playing.

private void GetDownloadList(PatchManifest target)
{
    string style = PatchHelper.GetPackStyle();
    MotionLog.Log(ELogLevel.Log, $"getDownloadList style is {style}");
    if (style == PATCH_STYLE.INGAME && _patcher.DownloadInGame)
    {
    _patcher.InGameDownloadList.Clear();

        // 临时下载列表
		List<PatchElement> downloadList = new List<PatchElement>(1000);

		// 准备下载列表
		foreach (var pair in target.Elements)
		{
			PatchElement element = pair.Value;
			if (element.Tag == PATCH_STYLE.INGAME)
			{
				downloadList.Add(element);
				// yield return 0;
				}
			}

		// 如果下载列表为空
		MotionLog.Log(ELogLevel.Log, $"FsmGetInGameDownloadList count is {downloadList.Count}");
		if (downloadList.Count > 0)
		{
			// 最后添加到正式下载列表里
			_patcher.InGameDownloadList.AddRange(downloadList);
			downloadList.Clear();

			// 发现新更新文件后,挂起流程系统
			_patcher.inGameCnt = _patcher.InGameDownloadList.Count;
			_patcher.inGameSizeKB = 0;
			foreach (var element in _patcher.InGameDownloadList)
			{
				_patcher.inGameSizeKB += element.SizeKB;
				// yield return 0;
			}

			// PatchEventDispatcher.SendFoundUpdateFilesMsg(totalDownloadCount, totalDownloadSizeKB);
		}
	}

	_patcher.SwitchNext();
}

Guess you like

Origin blog.csdn.net/liuyongjie1992/article/details/131112987