"Komatsu teaches you to develop" "Unity Practical Skills" Unity bundle optimization (Android One-click Package)

Source: Internet
Author: User

Unity itself is actually very convenient to the contract, foreign games are basically the same as the unity itself.

But in the domestic game there are so many channels, this iteration of the speed of the case, you need a more efficient way to contract.

The next step is to get a little more trouble if your project has hot updates.

The goal of the contract optimization is to do one-click Contract, the general contract opportunity is a separate machine, so

First step, update svn

The second step is to configure the packaging information. Access different SDKs based on different channels

Step three, build apk.

Because we are still testing the project, we have not yet done different access to the SDK according to different channels. The specific idea is to write an XML, fill in the above various configuration information, version number, access to the SDK name and so on. This will be done later in the project.

And our project is hot updated. You need to make the code into a DLL. So there are a few more steps in the middle

First of all to illustrate, because heat more our project requires 2 projects, a solution

One is the Game Master project (all clients are in use), a packaging project (used for packaging, only initialization code, and editor packaging code). A solution to make the game code into a DLL

1. Update the Game Master project Code SVN

2.copy Game main Project code to the solution directory to hit DLL

3. Solution to play DLL

4.dll Copy to the package project.

5. Open the DLL with Textasset and reach the Assetbundle package

6. Update the Package Project SVN

7. Configure the packaging information. Access different SDKs based on different channels

8.build apk

The next step is to implement it concretely.

Because it is a one-click Package, all of the above steps need to be called in code. So the outside operation uses. bat to perform file operations

1. Update svn

First write Update SVN's. BAT code

@echo. ----------开始------------  set SVN="C:\Program Files\TortoiseSVN\bin\TprtoiseProc.exe"  %SVN% /command:update /path:"E:\xxx\Scripts" /closeonend:1  @echo. ----------完成------------  

Code to invoke the. bat file

ProcessStartInfo pInfo = new ProcessStartInfo (fileName,String.Empty);//fileName就是你的.bat文件的绝对路径名  pInfo.UseShellExecute = true;  pInfo.CreateNoWindow = true;  pInfo.WorkingDirectory = Application.data.Path.Remove(Application.dataPath.LastIndexOf(‘/‘));  Process process = Process.Start(pInfo);  process.WaitForExit();  process.Close();  
2.copy Game main Project code to the solution directory to hit DLL

This is copy, there's nothing to say.

3. Solution to play DLL

This is also done with a. bat file, so you don't have to open vs build

@echo. ----------开始------------  set devenv = "D:\VS2015\common7\IDE\devenv.exe"  %devenv% E:\xxxx\GameLib.sln /rebuild  @if not %errorlevel% == 0 echo ------失败!!!---  @if not %errorlevel% == 0 pause  @if %errorlevel% == 0 echo. -------成功------  
4.dll Copy to the package project.

Copy too, nothing to say.

5.dll Open with Textasset and hit into Assetbundle bag

Here's a point to explain. Why DLL to use Textasset open not directly after using DLL?

1. Because to do heat more, code with DLL to do, but DLL in the game can not be placed in the plugin directory, the DLL placed in the Streamingasset directory can not be used directly. So we're going to use reflection to open it in memory.

2. The Reflection Interface Assembly.Load (byte[] bytes) bytes can be obtained from the textasset.bytes, so the DLL is read into Textasset and saved into Assetbundle, After the bundle package is updated, it can be used directly with Textasset.

Explain the process:

1. Copy the DLL to a spare

File.Copy (path,topath,true);

2. Loading into memory ready to package

AssetDatabase.ImportAsset(toPath);  AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);  TextAsset temp = AssetDatabase.LoadAssetAtPath(toPath,typeof(TextAsset)) as TextAsset;  

3. Packing Assetbundle

Temp is the textasset of step 2.

6. Update the Package Project SVN

Just like the first step.

7. Configure the packaging information. Access different SDKs based on different channels

We haven't done this yet, we'll make up the back.

8.build apk
 //Simple packet name based on time order string datestr = "";  String versioncodestr = "";  String finalstr = "";  string[] scene = {"Assets/main.unity"};  Datestr = System.dateTime.Now.ToString ("YyyyMMdd");  ArrayList fileList = new ArrayList (); DirectoryInfo dir = new DirectoryInfo ("e:/xxx/apk");//apk directory fileinfo[] allfiles = dir.  GetFiles ();  Long Currentversioncode = 0; foreach (FileInfo file in allfiles) {string fileName = file.   Name.substring (0,12); if (Currentversioncode < long. Parse (fileName)) Currentversioncode = long.  Parse (FileName); } if (Currentversioncode! = 0 && Currentversioncode. ToString (). Substring (0,8) = = datestr) {Currentversioncode = long. Parse (Currentversioncode. ToString ().  Substring (8,4)) +1;    Versioncodestr = currentversioncode.tostring ("0000");  } else Versioncodestr = "0101";  Finalstr =dir + "/" Datestr + Verioncodestr + ". apk";  Buildpipeline.buildplayer (Scene,finalstr,buildtarget.android,buildoptions.none); 

Finally, add an editor button to invoke the above functions.

"Komatsu teaches you to develop" "Unity Practical Skills" Unity bundle optimization (Android One-click Package)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.