A preliminary study on the development of WeChat mini-games with Unity

foreword

Recently, due to the needs of the project, I started to study the knowledge related to the development of WeChat mini-games by Unity. During the period, I encountered various pitfalls, and the information I checked online was basically similar, and I couldn't solve the problems I encountered. This article is specially used to record the process, so that others can refer to it when they encounter the same problem.

development environment

  1. The Unity version is recommended to use version 2021.2.5 according to the WeChat mini game plug-in documentation. It is measured that versions 2021.3.x and above can be used.

  2. Install the latest long-term support version of NodeJs.

  3. For mini game account registration, please refer to WeChat Official Documentation WeChat Open Documentation

  4. WeChat Developer Tools (mini game version)

    Precautions

  5. The applet category settings must be set as shown in the figure below.
    insert image description here

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-4K6sp7Mx-1677573033113) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228152043356.png)]

  1. Otherwise, there will be no ability map function in the -> growth of the applet menu. The next steps will present a series of problems. For example, the program converted with the Unity WeChat mini-game plug-in cannot be imported into the WeChat developer tool normally. And there is an error that cannot be compiled and prompts " the entry app.json file was not found , or the file failed to read,...".

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-PCeFSpnL-1677573033114) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228152533335.png)]

  1. Enable the [High Performance Mode] and [Quick Adaptation] functions in the Mini Program->Growth->Capability Map->Production Efficiency Improvement Package. As shown below

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-nxY7TnHi-1677573033114) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228152119774.png)]

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-D4NQaHh2-1677573033114) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228152214123.png)]

development steps

Develop Unity games

It is recommended to use the simplest example first to test whether the conversion process and development environment are correct.

Install the WeChat mini game unity conversion plug-in

Download plug-in minigame-unity-webgl-transform: Unity WebGL WeChat Mini Game Adaptation Solution

In the project opened by Unity Editor, right-click on the project to import package->custom package and select the downloaded plug-in.

After the installation is successful, you will see [WeChat Mini Game] in the UnityEditor menu.
insert image description here

Compile the Unity project

This step is not repeated

Setting up Unity WebGL

File->Build settings in Unity Editor. As shown below

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-q3s9EfL7-1677573033115) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228155952307.png)]

Convert WeChat Mini Game

Set as shown below. Required fields:

  1. The game appid is the appid generated when the WeChat applet is registered
  2. Mini game project name
  3. export path. Converted program storage path
  4. The first package resource loading method. Select the small game package (the reason is that there is no own CDN server yet)

Click to export WebGL and convert to mini game. program conversion

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-ZKo6M7s2-1677573033115) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228142519984.png)]

Possible problems with the conversion process

[External link picture transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the picture and upload it directly (img-vNF7whmd-1677573033116) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228142715759.png)]

  1. The error node.exe does not exist, first check whether Nodejs is installed; if it is installed, follow the steps in the figure to set it up. Custom Node Path is set to your own Nodejs installation path.

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-K1NHj4cZ-1677573033116) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228143029833.png)]

  1. The Unity 2021 version uses Embeded Symbols, and the code package contains a large volume of function names. Please use the code subpackage tool to optimize before release. According to the error prompt, open the corresponding source code, and find that this error will definitely appear only in versions above Unity2021, and it will not affect the follow-up work. If you have obsessive-compulsive disorder like me, you can manually comment out this line of code.

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-SAfz0KEq-1677573033117) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228143328555.png)]

WeChat developer tools import project

In the mini game menu -> directory -> select the Minigame directory under the directory where Unity converts the mini game settings.

Because there is no cloud server, the back-end service chooses not to use cloud services. After confirming, you can compile normally, debug and run your own mini-game.

In the mini game menu -> directory -> select the Minigame directory under the directory where Unity converts the mini game settings.

Because there is no cloud server, the back-end service chooses not to use cloud services. After confirming, you can compile normally, debug and run your own mini-game.

[External link image transfer failed, the source site may have an anti-leeching mechanism, it is recommended to save the image and upload it directly (img-JqyvfRzJ-1677573033117) (C:\Users\lontran\AppData\Roaming\Typora\typora-user-images\ image-20230228143522190.png)]

Guess you like

Origin blog.csdn.net/allexw/article/details/129264656
Recommended