Unity Hand Tour < 13 > Manual Tour Code Update strategy discussion

Source: Internet
Author: User
Tags lua

http://blog.csdn.net/janeky/article/details/25923151

These months the company project is very busy, plus home things also more, so the blog update has been shelved. Recently in the project development on-line process encountered a number of new issues, the next time and everyone to explore the study. Everyone in the work encountered technical problems, or have anything to share, welcome to explore [email protected]

--------------------------------------------------------------------------------------------------------------- ----------------------------------------------

We've learned about the resource hot-update strategy for mobile games before. In the actual hand-tour development operation, we need to fix bugs frequently and add new gameplay. These are usually related to code updates. Unity Game Code Update is more complex, there are different update strategies, each has its pros and cons, on different platforms are not the same approach. Here are some of the more commonly used strategies and the main mobile phone platform on the strategy. Everyone has a better idea, welcome to explore.

(reproduced please specify the source http://blog.csdn.net/janeky/article/details/25923151)

    • Reflection

Most programming languages support reflection, and with reflection, you can dynamically load the required programs. C # can also be implemented with reflection. To implement code updates, we plan early in the project to separate some easily changed business logic code. Each time the update is made, the code is packaged as a DLL and then packaged into a resource file. When the program starts, check for updates to the client and the client runs through reflection reload code. This is demonstrated by a simple demo.

1. Create a new code base project in VS, named Test
2. Add several classes Scirpt,scirpt2,data
3. Generate the Project Dll,test.dll
4. Create a new Unity project, pour the DLL into asset, change the name to Test.bytes, or you may get an error
5. Use our previously implemented packaging scripts to package the test.bytes into Test.assetbundle.
6. Create a CodeUpdate.cs script that is used to load code resources and reflect calls.
7. In order to verify the code update, can be directly loaded using, we can change the Data.cs code, repeat the above process, you can see, updated the code packaging, we rerun the game, we can see the effect

Data.cs

[CSharp]View Plaincopy
  1. Public class Data
  2. {
  3. private int attr;
  4. Public Data ()
  5. {
  6. attr = 2;
  7. }
  8. public Override string ToString ()
  9. {
  10. return attr.  ToString ();
  11. }
  12. }

Script.cs

[CSharp]View Plaincopy
    1. Public class Script:monobehaviour
    2. {
    3. void Start ()
    4. {
    5. Debug.Log ("------------------I am Script 1");
    6. Data data = new data ();
    7. Debug.Log ("-------------" + data.  ToString ());
    8. }
    9. }

CodeUpdate.cs

[CSharp]View Plaincopy
  1. Using Unityengine;
  2. Using System.Collections;
  3. Using System;
  4. Public class Codeupdate:monobehaviour {
  5. private static readonly string dll_url = "File:///c:/test.assetbundle";
  6. void Start () {
  7. Startcoroutine (Loaddllscript ());
  8. }
  9. private IEnumerator loaddllscript ()
  10. {
  11. www www = new www (dll_url);
  12. Yield return www;
  13. Assetbundle bundle = Www.assetBundle;
  14. Textasset Asset = bundle.  Load ("test",typeof (Textasset)) as Textasset;
  15. System.Reflection.Assembly Assembly = System.Reflection.Assembly.Load (asset.bytes);
  16. Type script1 = assembly.  GetType ("Script");
  17. Gameobject obj = new Gameobject ();
  18. Obj. AddComponent (SCRIPT1);
  19. Type script2 = assembly.  GetType ("Script2");
  20. Obj. AddComponent (SCRIPT2);
  21. }
  22. }

    • Full installation package update

Most app updates are made with a full package update. When the program starts, check the latest version of the server, if it is newer than the local version, download the version of the server and reinstall the replacement local program. On the iOS platform, it is managed centrally by the App Store. The client program simply checks the version and jumps to the App Store page. The Android platform updates are more flexible and slightly more complex. After judging the version number, confirm that you want to update, you can download the latest APK file of the server directly, install Replace Local. The code is not shown here. We should make clear the idea, the process, it is easy to achieve.

    • LUA Script Update

LUA has always been a magical scripting language, ubiquitous, and visible to server, client, mainframe, and embedded devices. Although Unity3d officially does not support LUA scripting, someone has written the C # version of the LUA parser. We can implement the business code in LUA. Whenever you want to update your code, simply update LUA as a resource file to the client and run.

C # version of Lua, there are many versions, here choose Cloud Wind their company open-source Unilua, we can go to Githunb download

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

    • iOS platform

Unfortunately, iOS is a closed platform, so it is very strict with the app program, generally do not run hot updates, each version of the update will need to submit a review. So it involves the update of the hand-travel code, all with the full package update. The way Lua scripts are updated, there are friends who have tried to say yes (they usually use LUA updates after the program has been online for some time). But there are risks, if found by Apple, is a violation. Not recommended for use here.

    • Android Platform

The most common way is to use code DLLs to reflect the update mechanism. In the actual process, we plan the stable underlying code separately and use it as the main program of the game. When all business logic code is released, it is packaged into a DLL and made into a resource file. After the client downloads, the reflection loads. Only if the underlying main program is to be updated is to download the main program's APK file separately and reinstall the replacement. Regular code updates, you can update the code DLL arbitrarily

    • Summarize

The above mentioned several ways, each has advantages and disadvantages. The strategy is not the same on different platforms. Tell me about my experience: it is generally a priority to release the Android version, there are problems at any time hot update code debugging. After the version is stable, release the iOS jailbreak version. When all is stable, the App Store is finally released. As we all know, the App Store has a long review cycle, and it's possible that their employees take a vacation for a few weeks before they approve it:). Each audit does not pass, but also have to revise the submission of review, but also a long wait. In the game world, Time is life. We try to debug the version on the Android platform.

PS. We have what good unity3d technical point want to discuss, welcome to inform, I will write a lot of people more interested in the actual combat content in the future.

Finally I wish you all the work smoothly, the project sells ~.

Unity Hand Tour < 13 > Manual Tour Code Update strategy discussion

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.