HybridCLR hot update configuration
Prepare before starting
- unity、vs
- hybridclr
- hybridclr_trial
- hybridclr_unity
- YooAsset
Configuring HybridCLR
1. Create a new unity project.
2. Install hybridclr_unity
- Click on the menu Windows/Package Manager popup
- Click the plus sign in the upper left corner, select
Add package from git url...
https://gitee.com/focus-creative-games/hybridclr_unity
- Enter the above url, click
Add
or回车
press the button , and wait for the loading to complete.
If it cannot be loaded due
to network problems , clone or download the hybridclr_unity library locally, select, find package.jsonAdd package from disk...
in the library , and select it to open it.
3. Configure Player Settings
- Turn off the incremental GC(
Use Incremental GC
) option. Because incremental GC is not currently supported. WebGL platforms ignore this option. Scripting Backend
Switch toil2cpp
. WebGL platform does not need to set this option.Api Compatability Level
Switch to.Net 4
or.Net Framework
(can be used when the main package is opened.net standard
, but must be switched to.Net 4
or when using the script Compile hot update dll.Net Framework
).If you must use the hot update part,.net standard
you can also use it. The official said that you should find them for commercial services.
Note: No matter which platform is built, it must be set.
4. Install HybridCLR
- Click the menu HybridCLR/Installer... to pop up the installation interface. Click
安装
and wait for the installation to complete.
5. Import 2 tool libraries
- Download the official example hybridclr_trial
- Copy the com.gwiazdorrr.betterstreamingassets and Unity-Logs-Viewer folders in the Packages to the Packages of the new project .
com.gwiazdorrr.betterstreamingassets : load plugin
Unity-Logs-Viewer : log plugin
- Copy the Editor , HotUpdate , Images , Main , Prefabs , Scenes folders and link.xml files under Assets to the Assets of the new project .
- Wait for compilation to complete.
Here you can organize the projects.
Delete redundant scenes: SampleScene,
delete redundant nodes: GameObject, ScreenLog
, delete Reporter nodes, and create a new one to prevent errors from being reported later.
6. Create Hotfix.dll
- Select the HotUpdate folder, right-click, and select Creator/Assembly Definition to create the Hotfix.dll file.
- Select the Hotfix.dll file and
Inspector
checkAllow 'unsafe' Code
the option on the panel. Use GUIDs
AddMain
,HybridCLR.Runtime
, andBetterStreamingAssets
references below, and then clickApply
Save.
7. Configure HybridCLR
- Click the menu HybridCLR/Settings to pop up the setting interface.
- Find
热更新Assembly Definitions(Hot Update Assembly Definitions)
and add the Hotfix.dll file. - Find it
补充元数据AOT dlls(Patch AOT Assemblies)
, and addmscorlib
,System
,System.Core
name into it.
8. Install YooAsset
- Open the management interface Edit/Project Settings/Package Manager , enter the following content, and click
Save
Save.
Name: package.openupm.cn
URL: https://package.openupm.cn
Scope(s): com.tuyoogame.yooasset
-
Open the management interface Windows/Package Manager , click the button to the right of the plus sign, select YooAsset under My Registries , click , and wait for the installation to complete.
Install
-
Add references to YooAsset in Hotfix.dll and Main.dll files respectively .
YooAsset : This is a plug-in for resource packaging management, which is used in detail to turn right when going out ( portal ).
9. Modify LoadDll.cs
- Modified LoadDll.cs ( portal )
- Copy all the code to LoadDll.cs in the project .Note: The LoadDll.cs code in the project is all covered, so don't.
- Open the LoadDll.cs script, and change the value of
DefaultHostServer
andFallbackHostServer
to the address of the AB package on the resource server. - Open the Main scene, select the LoadDll node, and
Inspector
modify it on the panelPlay Mode
toHost Play Mode
Play Mode: resource operation mode
EditorSimulateMode: editor mode
OfflinePlayMode: offline mode
HostPlayMode: online mode
10. Configure YooAsset
There is not much to say about the use of YooAsset , here is just a simple use. Before configuration, create a new folder DllBytes under Assets .
- Click the menu YooAsset/AssetBundle Collector to open the resource bundle collection tool pop-up window.
- Tick the first three options
- Add Packages
- Add Groups
Group Name: ABGroup
Group Desc: AB package resource
point[+]
, drag the Prefabs folder into it - Add Groups
Group Name: DllGroup
Group Desc: Dll file
point[+]
, drag the DllBytes folder in, change the third option to打包原生文件
- Click
Save
save in the upper right corner
11. Generate/All
andBuild
- Click the menu HybridCLR/Generate/All and wait for compilation.
- On line 20 of the BuildAssetsCommand.cs script ,add code
public static string DllBytesOutputDir => Application.dataPath + "/DllBytes";
- On line 72 of the BuildAssetsCommand.cs script ,Change the code
[MenuItem("HybridCLR/Build/BuildAssetsAndCopyToStreamingAssets")]
// 改为
[MenuItem("HybridCLR/Build/BuildDllsAndCopyDllBytesToOutputDir")]
- On line 76 of the BuildAssetsCommand.cs script ,comment code
//BuildAssetBundleByTarget(target); //因为使用了YooAsset,所以Build AssetBundle不需要在这里进行。
- On line 83 of the BuildAssetsCommand.cs script ,comment code
//CopyAssetBundlesToStreamingAssets(target); //前边没了Build,这里就没有要复制的对象了。
- On line 99 of the BuildAssetsCommand.cs script ,Change the code
string aotAssembliesDstDir = Application.streamingAssetsPath;
// 改为
string aotAssembliesDstDir = DllBytesOutputDir;
- On line 120 of the BuildAssetsCommand.cs script ,Change the code
string hotfixAssembliesDstDir = Application.streamingAssetsPath;
// 改为
string hotfixAssembliesDstDir = DllBytesOutputDir;
- On line 24 of the BuildPlayerCommand.cs script ,comment code
//[MenuItem("HybridCLR/Build/Win64")] //经上面改动这里可能存在问题。
- In line 16 of the HotUpdateMain.cs script ,comment code
//gameObject.AddComponent<CreateByCode>(); //等下做热更新测试会取消注释。
- Click the menu HybridCLR/Build/BuildDllsAndCopyDllBytesToOutputDir and wait for compilation.
- Click the menu YooAsset/AssetBundle Builder to open the resource bundle builder popup window.
Build Mode : Select for the first time or when necessaryForce Rebuild
, select at other timesIncremental Build
, set the version number, clickSave
,构建
, and the packaging output folder will pop up when completed.
Force Rebuild - Force Rebuild
Incremental Build - Incremental Build
Dry Run Build - Drill Build
Simulate Build - Simulate Build
12. Verify success
- Put the packaged file on the resource server, run unity directly, and there will be download related logs in the Console.
- Pack the PC package, run it, and use the mouse to draw a circle on the screen to view the log, and there will also be related download logs.
After running the above two methods, you will see the following words in the last log:
=======看到此条日志代表你成功运行了示例项目的热更新代码=======
- On the HotUpdatePrefab prefab, make some modifications, such as: create
Image
,Text
etc. - On line 16 of the HotUpdateMain.cs script , uncomment the code
- In the last line of the Start function of the HotUpdateMain.cs script , add a custom log (anything is fine, as long as no error is reported).
These operations are to simulate the modifications made by the usual development.
- Click the menu HybridCLR/Build/BuildDllsAndCopyDllBytesToOutputDir and wait for compilation.
- Click the menu YooAsset/AssetBundle Builder to open the resource bundle building tool pop-up window, select Build Mode
Incremental Build
, set the version number, and click构建
. - Put the newly packaged files on the resource server and run the PC package test. In the log, you will see the output log in CreateByCode.cs , your customized output log, and your modification of the HotUpdatePrefab prefab.
- At this point, if there is no problem with the above operations, it means that the HybridCLR hot update configuration is complete.
Finish
The above is the record of configuring HybridCLR hot update
. If there is any infringement, please contact to delete.
If there is any error or inappropriateness, please guide.
If there is a better way to build AssetBundle and dll files, you can contact us to discuss and learn together.