Unity mobile game Path & lt; 13 & gt; Discussion on mobile game code update strategies

Source: Internet
Author: User

In the past few months, the company's projects have been very busy, and there have been many household affairs, so blog updates have been put on hold. Recently, some new problems have been encountered during the project development and launch process. We will discuss and learn more in the following time. Everyone in the work encountered technical problems, or have any want to share, welcome to a lot of discussion ken@iamcoding.com.

Certificate -------------------------------------------------------------------------------------------------------------------------------------------------------------

We have learned about resource hot update strategies for mobile games before. In actual development and operation of mobile games, we need to fix bugs frequently and add new methods. These usually involve code updates. The updates of unity game code are complex and there are also different update strategies, each having its own advantages and disadvantages, and the practices on different platforms are also different. Here we will mainly discuss some common strategies and strategies on various mobile platforms. Everyone has a better idea. You are welcome to discuss it.

(Reprinted please indicate the source of http://blog.csdn.net/janeky/article/details/25923151)

  • Reflection

Most programming languages support reflection. Reflection allows you to dynamically load the required program. C # can also be implemented using reflection. To update the code, we must make a good plan at the initial stage of the project to separate some easy-to-change business logic code. During each update, the code is packaged into a dll and then packaged into a resource source file. When the program starts, check for updates to the client, and the client reloads the code to run through reflection. The following is a simple demo.

1. Create a new code library project in vs and name it test
2. Add several classes Scirpt, Scirpt2, Data
3. Generate the DLL, test. dll
4. Create a new unity project, import the DLL to Asset, and change it to test. bytes. Otherwise, an error may be reported.
5. Use the previously implemented packaging script to package test. bytes into test. assetbundle.
6. Create a CodeUpdate. cs script to Load Code resources and reflect calls.
7. to verify that the code is updated, you can directly load and use it. We can change the Data. the cs Code repeats the above process. We can see that after the code is updated and packaged, we can re-run the game to see the effect.

Data. cs

public class Data{    private int attr;    public Data()    {        attr = 2;    }    public override string ToString()    {        return attr.ToString();    }}

Script. cs

public class Script: MonoBehaviour{    void Start()    {        Debug.Log("------------------I am script 1");        Data data = new Data();        Debug.Log("-------------" + data.ToString());    }}

CodeUpdate. cs

using UnityEngine;using System.Collections;using System;public class CodeUpdate : MonoBehaviour {private static readonly string DLL_URL = "file:///c:/test.assetbundle";void Start () {StartCoroutine(loadDllScript());}private IEnumerator loadDllScript(){WWW www = new WWW(DLL_URL);yield return www;AssetBundle bundle = www.assetBundle;TextAsset asset = bundle.Load("test",typeof(TextAsset)) as TextAsset;System.Reflection.Assembly assembly = System.Reflection.Assembly.Load(asset.bytes);        Type script1 = assembly.GetType("Script");        GameObject obj = new GameObject();        obj.AddComponent(script1);Type script2 = assembly.GetType("Script2");obj.AddComponent(script2);}}

  • Complete installation package update

Most app updates use full package updates. When the program starts, check the latest version of the server. If it is newer than the local version, download the server version and reinstall and replace the local program. On the IOS platform, the App Store is centrally managed. The client only needs to check the version and jump to the app store page. The updates on the android platform are more flexible and complex. After judging the version number and determining whether to update it, You can directly download the latest apk file of the server, install and replace the local one. The code will not be demonstrated here. The process is easy to implement.

  • LUA script update
LUA has always been a magical scripting language. It can be seen everywhere on servers, clients, mainframes, and embedded devices. Although Unity3d does not officially support Lua scripts, someone has already written the lua parser of c. We can use Lua to implement the Business Code. Every time you update the code, you only need to update lua to the client as a resource file and run it.

C # edition Lua has many versions. Here we select Yunfeng's open-source UniLua. You can download it from Githunb.

Https://github.com/xebecnan/UniLua/wiki

  • IOS platform

Unfortunately, IOS is a closed platform, so it strictly monitors apps. Generally, hot updates are not run, and each version update must be submitted for review. Therefore, full package updates are used to update mobile game code. The LUA script update method has been tried by some friends (they generally use Lua update after the program is launched for a while ). However, there are also risks. If it is discovered by Apple, it is illegal. It is not recommended here.

  • Android platform

Currently, the common method is to use the code dll reflection update mechanism. In the actual process, we plan the stable underlying code separately and use it as the main game program. When all the business logic code is released, it is packaged into a dll and made into a resource file. After downloading the client, the reflection is loaded. Only when the underlying main program needs to be updated is the apk file of the main program downloaded separately, re-install and replace. You can update the code dll as needed.

  • Summary

The methods mentioned above have their own advantages and disadvantages. Policies vary across different platforms. Let's talk about my experience: Generally, the android version is first released. If there is any problem, you can hot update the code for debugging at any time. After the version is stable, release the ios jailbreak version. After all the data is stable, the app store is released. As we all know, app store has a long review cycle. It is possible that their employees will take a vacation and will not pass the review within a few weeks :). It is a long wait until the review fails. In the game industry, time is life. We try to debug the version on the android platform.

Ps. What kind of Unity3d technology do you want to discuss? please let us know. I will write more about the actual content that you are interested in the future.

Finally, I wish you a smooth job and a big sale of projects ~.

Related Article

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.