当前位置:网站首页>Detailed explanation of unity hot update knowledge points and introduction to common solution principles
Detailed explanation of unity hot update knowledge points and introduction to common solution principles
2022-07-07 15:45:00 【Listen to the rain outside the window】
Unity Detailed explanation of hot update knowledge points and introduction of common solution principles
Hot update knowledge points summary
The concept of hot renewal
When the game or software is updated , There is no need to download the client again for installation , But when the application starts ,
Internal resource or code updates .
Advantages of hot renewal
- Quick fix Bug – Avoid downloading the installation package again , Update the game in time Bug
- Reduce the size of the package – Non core resource upload server , Dynamically load remaining resources at runtime
- Change the game quickly " kernel " – Civet for Prince , Bypass audit , Update the game quickly
Hot update solutions
be based on Lua Hot update solution
principle : In essence, it is to use related plug-ins (
xlua,tolua) Provide a Lua Operating environment ( virtual machine ), by Unity Provide Lua The ability to program , Give Way C# and Lua Can call and access each other .advantage :
- Lua from C Language writing Strong commonality It can run on almost any operating system .
- Lua As a lightweight and compact scripting language , from Lua Virtual machine interpretation execution , Hotter only needs simple file replacement , No need to compile .
- Strong development experience , There are many mature projects and schemes .
shortcoming :
- Unity Native use C#, Use one more door Lua Language will increase the cost of learning and development
- Lua Is a weakly typed, non object-oriented language , When facing large projects, it will not be like traditional OOP Language, layered and modular development , It is easy to cause code structure confusion and maintenance difficulties .
- You need to use plug-ins in C# Provide... In an environment Lua Running environment , And also need to be Lua and C# Provide data communication and related conversion between , inefficiency , It's far better to use native C# Development .
Solution
XLuaThe basic principle :
XLuaThe foundation of the framework is the implementation of running in C# Environmental Lua Virtual machines make Lua You can talk to C# Realize mutual call and access .C# call Lua principle :Lua from C Language implementation comes with C/C++ Communication mechanism interface ,C# Can use C And Lua Data communication , Data exchange in memory . Data references directly obtained from memory need to be further converted into C# Can be used ,
xLuastaycastersMapIt definesluaData type to C# Type conversion function , After conversion, it can be realized C# call Lua.Lua call C# principle : The principle of data communication is the same as above , Simple basic value types pass C API Easy delivery , But complex objects require adopt Lua Of
userdataTable and C# Object mapping implementation , Every C# The objects are all in Lua Corresponding to one inuserdatasurface , thenluaWould beuserdataSet meta table , The meta table represents the type information of the actual object , stay C# Object passed to Lua After that, you need to tell the type of object , static state / Member method 、 Properties and other information are registered to Lua after ,Lua In order to correctly call C# Related object functions, etc .Meta table can be understood as C# Medium Type class , all C# Objects have a type object pointer , There is a method table in the type object , Static fields and other information ,
userdataThe table only contains the specific members of the class , You also need a meta table to act as a type object in order to correctly and C# Object mapping succeeded .Hot patch principle : utilize IL Inject , To achieve Lua Function substitution C# Primitive function . The basic principle of implementation is : according to Lua Script hot patch command Generate matching files (
DelegatesGensBridge.cs) It's inside Lua Hot patch function reference provided , Then according to the annotation of characteristics [Hotfix] etc. , Locate on the objective function Create static variablesDelegateBridge. When Lua It provides a hot patch function , Then this variable is not empty, otherwise it is empty , Then use this variable to judge the condition , When the implementation is not empty, according to the matching file Lua Function reference to execute , Do not continue to execute the original C# function . If it is empty, execute the original C# Functional logic .
ToLua- The basic principle :
ToLuaThe framework is mainly through Static binding To achieve C# And Lua Interaction between . - C# call Lua principle : Data communication and
xLuasimilar , After obtaining the data reference in memory, it also needs to be converted , Change the way andXLuaSomewhat different ,ToLuaRealizedLuaInterfaceEstablished Lua And C# Mapping between , Use C# The type of establishesluaBasic data model , Then the operation rules are established on this basis . - Lua call C# principle : What is different from other frameworks is the characteristics of its static binding , stay Lua call C# when , It provides a C# file (
CustomSettings.cs) Show registration C# Components , When starting the virtual machine, it will take advantage ofLuaInterfaceWill register C# Components map to Lua On , Including the conversion of basic types 、 Custom type to table Transformation 、 Function conversion , Finally, they are registered to Lua The big G surface (global table) To realize Lua call C#.
- The basic principle :
Two kinds of Lua Comparison of solutions
ToLuaThe warm update provided is not perfect ,C# Project transfer Lua Recommended for hot updateXLuaHot patch for .ToLuaStatic binding is used to display the registration in the file, which reduces the number of reflections ,XLuaIt provides a series of features and reduces the number of reflections to a certain extent .ToLuaPoor support for generics , There will be a lot of disassembly and assembly process , Low efficiency .XLuaImproved support for generics , Reduce the times of disassembling and assembling the box .
be based on C# Hot update solution
- principle : In essence, use the compiled new DLL Replace the old that needs to be updated DLL. Only code hot update , We need to cooperate with AB The resources of the package are used together with hot updates .
- advantage :
- and Unity All development uses C#, Unified development language , Coding is easier .
- Use pure C# There is no need to create another environment such as virtual machine for development , Efficient , The performance is much higher than Lua
- shortcoming :
- Each scheme has its own limitations , Direct reflection not only reduces performance , No support for JIT The system of (IOS) Can't use .
ILRuntimeIt's solved JIT But not mature enough , There are many problems in using , Need high hands-on problem-solving ability .
- Solution
- DLL Reflect heat renewal : Use the compiled DLL File to replace , Use reflection to put the required C# The component is bound to the corresponding object to use .
ILRuntime: In essence DLL Replacement , But it realizes a ILR(IL Runtime ) Enable it to support JIT Hardware environment (IOS) Realize code hot update under .
Basic process of hot update
- Version number comparison , If the version number is different, continue the following process (version.txt Record version number , Optional )
- Download the Reference document (files.txt Record all documents md5 code , Sort of like a directory )
- Confirm the download list , Compare the newly downloaded reference file with the old local reference file , Record missing or different files .( utilize files.txt Medium md5 Code to realize this step )
- According to the download list , Download required resources .( Generally placed on
Application.persistentDataPath) - decompression ( If the file is compressed, you need to decompress it first , Optional )
- Ensure that the download is successful , Overwrite the local reference file with the latest reference file ( Update the catalog )
Hot update rule
Resource packaging : Code and resources that need to be updated , Must be packaged into
AssetBundle(AB package ) Download and load ,AB The characteristics of the package are suitable for hot update .( For the following reasons )- AB Package storage location customization , Then it can be put into a readable and writable path to facilitate hot update
- AB Package custom compression , You can choose not to compress or choose LZMA and LZ4 Equal compression mode , Reduce the size of the bag , Faster network transmission .
- Resources can be distributed in different AB In bag , Minimize memory pressure at runtime , It can be used and loaded immediately , Selectively load the required content .
- AB The package supports dynamic updates in the later stage , Significantly reduce the size of the initial installation package , Non core resources AB Upload the package to the server , Late runtime dynamic loading , Improve user experience .
Resource storage path : Give priority to putting the code and resources that need to be updated in
Application.persistentDataPath, Compared with other special directories , This directory is readable and writable , The runtime is effective and has no content restrictions, which is more suitable for hot update development .( The comparison of several important paths is as follows )Resources
Resources The resources under the folder will be packaged whether they are used or not
All resources are packed into a big package , Search loading is inefficient .
Resources will be compressed , Convert to binary
After packaging, the resources in the folder are read-only
Cannot dynamically change , Unable to do hot update
Use
Resources.Loadload
StreamingAssets- Cache directory of streaming data
- The resources under the folder will be packaged whether they are used or not
- Resources will not be compressed and encrypted
- After packaging, the resources in the folder are read-only , Mainly storing binary files
- Cannot modify after packaging , Unable to do hot update
- WWW Class loading ( It's usually used
CreateFromFile, If the resource isAssetBundle, Whether it is compressed depends on its packaging method ) - Relative paths , The specific path depends on the actual platform
Application.streamingAssetsPathThe path is sometimes inaccurate on different platforms
Application.dataPath- The path of the game's data folder ( For example, in Unity Editor Medium Assets)
- Unable to do hot update
Application.persistentDataPathPath to the persistent data store directory ( Sandbox catalog , Does not exist before packaging )
The resources under the folder will be packaged whether they are used or not
Run time effective , read-write
No content restrictions , from
StreamingAssetRead binary files in or fromAssetBundleRead the file to writePersistentDataPathinSuitable for hot update
边栏推荐
- 2. Basic knowledge of golang
- 【数字IC验证快速入门】23、SystemVerilog项目实践之AHB-SRAMC(3)(AHB协议基本要点)
- 【OBS】RTMPSockBuf_ Fill, remote host closed connection.
- 【数字IC验证快速入门】24、SystemVerilog项目实践之AHB-SRAMC(4)(AHB继续深入)
- Share the technical details of super signature system construction
- #HPDC智能基座人才发展峰会随笔
- 使用cpolar建立一个商业网站(2)
- Runnable是否可以中断
- 【数字IC验证快速入门】25、SystemVerilog项目实践之AHB-SRAMC(5)(AHB 重点回顾,要点提炼)
- Clang compile link ffmpeg FAQ
猜你喜欢

Streaming end, server end, player end

【深度学习】图像超分实验:SRCNN/FSRCNN
![[follow Jiangke University STM32] stm32f103c8t6_ PWM controlled DC motor_ code](/img/8d/a6d477a8679ca4f3885b1a7b542437.png)
[follow Jiangke University STM32] stm32f103c8t6_ PWM controlled DC motor_ code
![[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering](/img/a4/7320f5d266308f6003cc27964e49f3.png)
[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering

Monthly observation of internet medical field in May 2022

【兰州大学】考研初试复试资料分享

The difference between full-time graduate students and part-time graduate students!

HW primary flow monitoring, what should we do
使用Scrapy框架爬取网页并保存到Mysql的实现

简述keepalived工作原理
随机推荐
【搞船日记】【Shapr3D的STL格式转Gcode】
Zhongang Mining: Fluorite continues to lead the growth of new energy market
有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
[original] all management without assessment is nonsense!
Super signature principle (fully automated super signature) [Yun Xiaoduo]
Pit avoidance: description of null values in in and not in SQL
[quick start of Digital IC Verification] 18. Basic grammar of SystemVerilog learning 5 (concurrent threads... Including practical exercises)
【跟着江科大学Stm32】STM32F103C8T6_PWM控制直流电机_代码
Excerpted words
Write sequence frame animation with shader
Unity's ASE achieves full screen sand blowing effect
Vertex shader to slice shader procedure, varying variable
2. Basic knowledge of golang
2. 堆排序『较难理解的排序』
[Data Mining] Visual Pattern Mining: Hog Feature + cosinus Similarity / K - means Clustering
Android -- jetpack: the difference between livedata setValue and postvalue
OpenGL's distinction and understanding of VAO, VBO and EBO
Write a ten thousand word long article "CAS spin lock" to send Jay's new album to the top of the hot list
Getting started with webgl (2)
微信小程序 01