Integrate ET 7.2 + HybridCLR 0.10.4 + XAsset 2022.2 + EUI in Unity2022.3.7 to realize ECS coding, C# code hot update, resource hot update, the basic framework of UI management system

Tool introduction

ET 7.2 

        ET is an open source game client (based on unity3d) server-side dual-end framework. The server is a distributed game server developed using C#.net core. It is characterized by high development efficiency, strong performance, and double-end shared logic code. The hot update mechanism of the client and server is complete, and at the same time supports reliable udp tcp websocket protocol, supports 3D recast pathfinding on the server, etc.

 HybridCLR

        HybridCLR is a nearly perfect native c# hot update solution for Unity full platform with complete features, zero cost, high performance and low memory .

XAsset 2022.2

        xasset is a professional Unity resource system.

        xasset provides out-of-the-box packaging, subpackaging, encryption, downloading while playing, and cross-platform loading technologies to make the development of Unity projects faster and easier!

  ET-EUI   (When the article was released, the author of ET-GUI has matched to ET-7.0, and the article will be modified to match to ET-7.2 based on this)

       ​​​​ET  -EUI is a simple UI module based on the ET framework

build process

  • ET
  1. Download the ET 7.2 version  from github  , and use Unity to open the project directory named Unity in the project.
    For the operation steps, please refer to  the ET6.0 framework - development environment construction , and the latest operation guide.md under the Book directory   .
     
  2. Switch to the Android platform

     
  3. Modify the "Select platforms for plugin" property setting of Mongo-related Dll:


    Otherwise, after clicking the "BuildModelAndHotfix" command, an error message that the relevant Mongo dll cannot be found will appear:

    ( Assets\Scripts\Codes\Model\Server\Module\DB\ DBComponent.cs(1,15): error CS0234: The type or namespace name 'Driver' does not exist in the namespace 'MongoDB' (are you missing an assembly reference?) (at DBComponent.cs) )

     
  4. Before running the project, you need to execute the "BuildModelAndHotfix" command to compile the code and start the built-in server (select the ClientServer mode); if you need to run the server separately, select the Client mode, and then refer to   the instructions in the document Operation Guide.md to start the server separately.
      
     
  5. After the compilation is successful, it can be started normally.

     
  •  HybridCLR
  1.  After installing ET, follow the official tutorial  to install HybridCLR | Focus Creative  to add the HybridCLR package, and then install:

      
  2. Download the official  HybridCLR sample project  , copy all the files in the Assets directory to the Assets directory of Unity in the ET project, and then open the main scene in it.

  3. Before starting the demo scene, you need to execute the following commands respectively;

        

    after execution, the following files will be generated in the StreamingAssets directory normally:


    If all the above files are not generated or if you encounter a prompt that you need to pack first, you need to pack the apk once and then try again Execute command operations. Finally, after the file list in the above picture is generated, it can be started normally.
  • The installation of XAsset 2022.2 free version of

    XAsset is simple, just import and install the package directly. For details, please browse the  official document . Here is a brief introduction to the usage matters that need to be paid attention to:
  1.  The 2022.2 version has made many changes compared to the 2022.1 version. First, from the packaged and exported version control files, the original two files (manifest.json, versions_v?.json) are increased to 2+n files (updateinfo.json, versions_v? .json, [resource classification file.json,...] ), and the resource classification file is generated through configuration, eliminating the need to customize the assetbundle name for the resource.

     
     
  2. In the 2022.2 version, the file breakpoint resume function has been changed from native C# code to be realized through UnityWebRequest.

         

        Two requests are involved in the implemented download logic: one is to obtain information such as the size of the file, and the other is to download the content of the file. When downloading a text configuration file in a format such as json through the CDN, if the object storage method is used to store such files on the CDN, when the size information of the file is obtained through the UnityWebRequest request, the correct size value may be obtained. The correct file information can be obtained through HttpWebRequest:

        

  •  ET-I
  1. The ET-EUI7.0 version is currently still based on the directory structure of the ET6.x framework. To use it in the ET7.2 framework, you need to manually move the relevant EUI code directory (such as
    ET-EUI_70\Unity\Codes\ModelView\Module\EUI,
    ET-EUI_70\Unity\Codes\HotfixView\Module\EUI,
    ET-EUI_70\Unity\Assets\Editor\EUI,
    ET-EUI_70\Unity\Assets\Mono\LoopScrollRect, etc.)

    to the directory corresponding to the ET7.2 framework (such as
    ET_72\Unity\Assets\Scripts\Codes\HotfixView\Client\Module\EUI,
    ET_72\Unity\Assets\Scripts\Codes\ModelView\Client\Module\EUI,
    ET_72\Unity\Assets\Scripts\Editor\EUI,
    ET_72\ Unity\Assets\Scripts\Core\Module\EUI, etc.)
     
  2. After the direct copy is completed, due to the update of the directory structure of the ET7.2 framework, there will be some duplicate files. It is necessary to check the differences and integrate them, and delete unnecessary files with the same name.
     
  3. In addition, the names of some attribute definition classes in the ET7.2 framework have also changed. For example, FriendClassArrbite is changed to FriendOfAttribute, ChildTypeAttribute is changed to ChildOfAttribute, etc. Correspondingly, the definition logic of automatically generating UI classes in the UICodeSpawner code of EUI also needs to be updated synchronously.

        

 ET generates and loads hot code via HybridCLR

  1. Add ET macro definition ENABLE_CODES

     
  2. Change the platform attribute of the ET hot update module to full platform

     
  3. Add Assembly Definitions that need to be updated in HybridCLR Settings
      
  4. Implement a new BuildETAssetsAndCopyToStreamingAssets command referring to HybridCLR's BuildAndCopyABAOTHotUpdateDlls command

      
     
  5. Execute the BuildPackage command of ET to package resources, and the resources will be stored in the StreamingAssets directory

      
  6. Then execute the three commands of HybridCLR in sequence to generate the hot update code. After the execution is successful, the generated files are also stored in the StreamingAssets directory

             
     
  7. Refer to the logic of loading the hot update code in the LoadDll.cs file of HybridCLR and the logic of starting the hot update code in the CodeLoader.cs file of ET to realize the logic of loading the HybridCLR hot update of ET.
     
    		System.Collections.IEnumerator DownLoadAssets(Action onDownloadComplete)
    		{
    
    			var assets = HotfixDll.Concat(AOTMetaAssemblyNames);
    
    			foreach (var asset in assets)
    			{
    				string dllPath = GetWebRequestPath(asset);
    				Debug.Log($"start download asset:{dllPath}");
    				UnityWebRequest www = UnityWebRequest.Get(dllPath);
    				yield return www.SendWebRequest();
    
    #if UNITY_2020_1_OR_NEWER
    				if (www.result != UnityWebRequest.Result.Success)
    				{
    					Debug.Log(www.error);
    				}
    #else
                if (www.isHttpError || www.isNetworkError)
                {
                    Debug.Log(www.error);
                }
    #endif
    				else
    				{
    					// Or retrieve results as binary data
    					byte[] assetData = www.downloadHandler.data;
    					Debug.Log($"dll:{asset}  size:{assetData.Length}");
    					s_assetDatas[asset] = assetData;
    				}
    			}
    
    			onDownloadComplete();
    		}
    		void StartGame()
    		{
    			LoadMetadataForAOTAssemblies();
    
    			List<Assembly> listAssembly = new List<Assembly>();
    			foreach (var item in HotfixDll)
    			{
    				byte[] assModelBytes = GetAssetData(item);
    				var assembly = Assembly.Load(assModelBytes);
    				if (item == "Unity.Model.Codes.dll")
    				{
    					this.model = assembly;
    				}
    				listAssembly.Add(assembly);
    			}
    
    			listAssembly.Add(typeof(Game).Assembly);
    			listAssembly.Add(typeof(Init).Assembly);
    
    			Dictionary<string, Type> types = AssemblyHelper.GetAssemblyTypes(listAssembly.ToArray());
    			EventSystem.Instance.Add(types);
    
    			IStaticMethod start = new StaticMethod(this.model, "ET.Entry", "Start");
    			start.Run();
    		}
  8. Generate the Apk package, and test the hotfix on the mobile phone or emulator startup program (the log shows an error after startup, the reason is that the server code is also added to the hotfix code, and then only need to define the Hotfix and Model Server code in Just in the new Assembly)
     

                   

 The entire project code and the UnityEditor.CoreModule.dll file that needs to be modified involving HybridCLR (in the Tools directory of the project) are all placed on Github , and can be downloaded directly!

Guess you like

Origin blog.csdn.net/veimen/article/details/127789745