Tribute to the original 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.
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
- Public class Data
- {
- private int attr;
- Public Data ()
- {
- attr = 2;
- }
- public Override string ToString ()
- {
- return attr. ToString ();
- }
- }
Script.cs
[CSharp]View Plaincopy
- Public class Script:monobehaviour
- {
- void Start ()
- {
- Debug.Log ("------------------I am Script 1");
- Data data = new data ();
- Debug.Log ("-------------" + data. ToString ());
- }
- }
CodeUpdate.cs
[CSharp]View Plaincopy
- 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);
- }
- }
- 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 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
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.
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
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