当前位置:网站首页>Unity Huatuo example project source code analysis and inspiration
Unity Huatuo example project source code analysis and inspiration
2022-07-27 02:05:00 【Clank's game stack】
In the last section, we installed huatuo Development environment of , Then run the sample project , Experienced huatuo Make a hot update , In this lesson, we will analyze the source code of the example project , master huatuo The main steps of hot update , Make your own project well based on huatuo To organize hot updates . There are several huatuo The principles should be clear :
Here is a Game development communication group You can get video tutorials and source materials
- Unity ADF Mechanism to sub project , It can be divided into several projects , Avoid a lot of code compiling for a long time , At the same time, heat regeneration can be done according to smaller particle size .
- In general development , Will be able to Unity The code of the project is passed through IL2CPP All into static binary instruction code , If so IL2CPP_huatuo Loaded a IL Code .dll( both AOT Static code , The corresponding IL Code ),huatuo Priority will be given to explaining the implementation of loading IL Code . Each version puts .dll Generate , compare , Which? .dll Changed , Just use il2cpp_huatuo download , Reprint and execute .
- Code of any project ( Framework code + The game logic ) Can be based on huatuo To do hot updates .
- huatuo Provide a hotter mechanism , As for how hot it is , What is hot is completely under your control ;
We take these principles to analyze the source code of the example project and get the inspiration from our own development project .
inspire 1: How to divide the game code into projects and projects
Traditionally, our hot update projects are divided into : Framework code + The game logic . You can also divide according to this standard , You can also continue to divide into smaller particle sizes , Such as game logic , It can be divided into : fighting , Task, etc . So we're using huatuo When doing hot update, the first thing it does is to split the project , Use Unity Of ADF Mechanism , The project is divided into several projects as follows :
Assembly-CSharp.csproj: Default code engineering , The new code will be pulled into this project by default ;
Assembly-CSharp-Editor.csproj: Editor Editor The code will be pulled into this project to compile ;
BetterStreamingAssets.csproj: Resources in the sample project ab Package loading project ;
HotFix.csproj: In the example project, the test project that is more popular ;
HotFix2.csproj: The second test project in the example project ;
Main.csproj: In the example project, the main project of the entrance , The example project starts from the code of the entry project ;
Here is our inspiration , When we are doing our own game projects , You can also use it according to your own project needs Unity ADF Mechanism , To divide the project into several projects , And these projects , It can be generated separately IL Of .dll Code instructions . So you can give IL2CPP_huatuo To explain the implementation . Inspired by this , We use it huatuo When doing projects, I will divide the projects as follows , For your reference :
Assembly-CSharp.csproj: Default code engineering , Put the startup code here , Exothermic update version detection code , What are detected .dll You need to update , Download updates incrementally , Compare which ones don't need to be updated and use the original ones AOT Internal code , What needs to be updated , Need to update with il2cpp_huatuo To load in , Priority is given to the loaded .dll Instructions .
Main.csproj: It can be used for frame engineering , Implement each framework module , Initialization framework , Enter the specific game logic , Provide basic services , Such as SDK Service etc. . This is the traditional hot frame layer , Generally speaking, it's better not to be hot , Use AOT The later code is ok , In case it gets hotter , It can also be directly generated by heat main.dll.
Several business logic projects : Distinguish several game items according to the type of game , These are determined by version comparison .dll Need to be il2cpp_huatuo Virtual machine mount .
inspire 2: Extend the editor to generate all .dll
from huatuo Characteristics of , Which one do you load .dll, You can dynamically interpret and execute the corresponding .dll Code instructions for . So we can get inspiration , Divide everything in our project by Assembly-CSharp.dll Outside of the .dll All come out . such as 1.0 edition : Main.dll( Game framework ), game.dll( The main logic of the game ), task.dll( Mission system ), … such as 2.0 edition : main.dll, game.dll, task.dll, …. So every time you package and publish , We can use this editor to extend , Compile all the projects .dll, And generate an all .dll Of md5 List of file changes . Take the latest one .dll And md5 Put the file list on the server , The local md5 Put the document list in the bag , Each run , We download the latest version incrementally .dll after , We just need to compare the servers .dll md5 File list , Corresponding to the current version .dll Of md5 File list , Decide which .dll Need to load into il2cpp_huatuo, Just load directly to realize hot update , Those that have not changed .dll, Indicates that it can be used directly AOT Machine instructions in mode , No need to explain the implementation IL The directive .dll. Let's take a look at how our sample project compiles .dll The directive , Refer to the extension code of the corresponding editor . Open the Editor/Huatuo The folder EditorHelper.cs, Pictured :


There is nothing to say , call API, pack .dll, direct copy Just come here . According to our analysis above , Yes .dll Generate different versions of .dll md5 The file list needs to be expanded , There is no .
inspire 3: Which part of the code should be hotter , Just load the code
Use huatuo The last thing you need to master to do hot update is , How to load .dll Code for , When we know what the current system needs to be loaded .dll Give Way huatuo Explain after execution , The last step is to let huatuo To load , We can see from the code of this sample project il2cpp_huatuo How to load a .dll Of , When this .dll After being loaded , The functions of this part are explained and implemented .Huatuo How to load code , We can refer to the following examples ( Code from LoadDll.cs):

It is divided into release mode and Edtior Pattern , The release mode is to directly .dll Load in il2cpp_huatuo Of vm in , call API function : System.Reflection.Assembly.Load(.dll Binary contents of ), In the underlying huatuo Made modifications . In Editor Mode , call AppDomain Just load it , So we can refer to this code directly , Compare which .dll Be hotter , I'll just reprint it .

边栏推荐
- 2022年T2I文本生成图像 中文期刊论文速览-1(ECAGAN:基于通道注意力机制的文本生成图像方法+CAE-GAN:基于Transformer交叉注意力的文本生成图像技术)
- JS逻辑运算符
- 科学计算库 —— Matplotlib
- Connect mysql detailed graphic operations in ECs docker (all)
- mysql存储引擎及其区别
- Acwing 1057. stock trading IV
- Transport layer --------- TCP (II)
- Docter的安装和基础操作
- Fastjson handles string escape characters
- Text to image论文精读RAT-GAN:文本到图像合成中的递归仿射变换 Recurrent Affine Transformation for Text-to-image Synthesis
猜你喜欢
随机推荐
事务数据库及其四特性,原理,隔离级别,脏读,幻读,不可重复读?
Fastjson handles string escape characters
Talking about server virtualization & hyper convergence & Storage
[reprint] 6. Tensorrt advanced usage
虚拟化技术KVM
25pxe efficient batch network installation
行,表,页,共享,排他,悲观,乐观,死锁
[paddleseg source code reading] paddleseg export static graph export Trace in py file
Use of shell (11) brackets
JS逻辑运算符
[translation] reduced precision in tensorrt
Proxmox ve installation and initialization
GAN的训练技巧:炼丹师养成计划 ——生成式对抗网络训练、调参和改进
解决方案:Win10如何使用bash批处理命令
Docker高级篇之Mysql主从复制、Redis集群扩容缩容配置案例详解
(atcoder contest 144) f - fork in the road (probability DP)
Hands on experiment of network and VPC
(codeforce 807div2)C. Mark and his unfinished essay (thinking)
Initial experience of cloud database management
Summary and review of key points of digital image processing

![[untitled]](/img/2a/53327cd39db7871fa780ed599420d0.png)







