HybridCLR hot update configuration

Prepare before starting

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, selectAdd package from git url...
https://gitee.com/focus-creative-games/hybridclr_unity
  • Enter the above url, click Addor 回车press the button , and wait for the loading to complete.
    insert image description here

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 BackendSwitch to il2cpp. WebGL platform does not need to set this option.
  • Api Compatability LevelSwitch to .Net 4or .Net Framework(can be used when the main package is opened .net standard, but must be switched to .Net 4or when using the script Compile hot update dll .Net Framework).If you must use the hot update part, .net standardyou 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 .
    insert image description here

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 Inspectorcheck Allow 'unsafe' Codethe option on the panel.
  • Use GUIDsAdd Main, HybridCLR.Runtime, and BetterStreamingAssetsreferences below, and then click ApplySave.
    Hotfix.dll

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 add mscorlib, System, System.Corename into it.
    Configuring HybridCLR

8. Install YooAsset

  • Open the management interface Edit/Project Settings/Package Manager , enter the following content, and click SaveSave.

Name: package.openupm.cn
URL: https://package.openupm.cn
Scope(s): com.tuyoogame.yooasset

ProjectSettings/PackageManager

  • 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
    PackageManager

  • 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 DefaultHostServerand FallbackHostServerto the address of the AB package on the resource server.
  • Open the Main scene, select the LoadDll node, and Inspectormodify it on the panel Play ModetoHost Play Mode
    LoadDll node

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 Savesave in the upper right corner
    resource pack collection tool

11. Generate/AllandBuild

  1. Click the menu HybridCLR/Generate/All and wait for compilation.
  2. On line 20 of the BuildAssetsCommand.cs script ,add code
public static string DllBytesOutputDir => Application.dataPath + "/DllBytes";
  1. On line 72 of the BuildAssetsCommand.cs script ,Change the code
[MenuItem("HybridCLR/Build/BuildAssetsAndCopyToStreamingAssets")]
// 改为
[MenuItem("HybridCLR/Build/BuildDllsAndCopyDllBytesToOutputDir")]
  1. On line 76 of the BuildAssetsCommand.cs script ,comment code
//BuildAssetBundleByTarget(target); //因为使用了YooAsset,所以Build AssetBundle不需要在这里进行。
  1. On line 83 of the BuildAssetsCommand.cs script ,comment code
//CopyAssetBundlesToStreamingAssets(target); //前边没了Build,这里就没有要复制的对象了。
  1. On line 99 of the BuildAssetsCommand.cs script ,Change the code
string aotAssembliesDstDir = Application.streamingAssetsPath;
// 改为
string aotAssembliesDstDir = DllBytesOutputDir;
  1. On line 120 of the BuildAssetsCommand.cs script ,Change the code
string hotfixAssembliesDstDir = Application.streamingAssetsPath;
// 改为
string hotfixAssembliesDstDir = DllBytesOutputDir;
  1. On line 24 of the BuildPlayerCommand.cs script ,comment code
//[MenuItem("HybridCLR/Build/Win64")] //经上面改动这里可能存在问题。
  1. In line 16 of the HotUpdateMain.cs script ,comment code
//gameObject.AddComponent<CreateByCode>(); //等下做热更新测试会取消注释。
  1. Click the menu HybridCLR/Build/BuildDllsAndCopyDllBytesToOutputDir and wait for compilation.
  2. 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 times Incremental Build, set the version number, click Save, 构建, 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, Textetc.
  • 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 ModeIncremental 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.

Guess you like

Origin blog.csdn.net/weixin_43830069/article/details/129855550