The Architecture and Design of Unity Multiplayer Online Massive Player Characters

Unity multiplayer online games will have a large map, a large number of players will be online at the same time, and players will have different game occupations. How should we design the client for such a large number of players' game characters? This article shares the following points:

right! There is a game development exchange group here , which gathers a group of zero-based beginners who love to learn Unity, and there are also some technical bigwigs who are engaged in Unity development. You are welcome to exchange and learn.

Each network player character is a GhostCharactor

Online games with multiple people online at the same time (2000+ players play on the same map) are processed based on state synchronization. Players in this type of game can be divided into two categories: one is controlled by other players through the network The character , a class is the character controlled by the current player (we call the self player). Our multiplayer online games are all based on state synchronization, that is, a complete game logic will run on the server, and then if the state changes, the "latest state" will be sent to other network players who can see the player. After the client receives the latest state of the data packet, it performs corresponding actions and processing according to the content of the data packet, such as receiving a state event of death, and playing a death animation. That is to say, all roles are ultimately driven by network events sent from the server. An online game character is actually a character image driven by network events (we call it ghost in the following).

The creation and deletion of a large number of player characters are managed by GhostEntityMgr

It has been analyzed above that each character in the multiplayer online game can be controlled by GhostCharactor, then these characters can be constructed and recycled through the GhostEntityMgr management object. When a multiplayer game is online at the same time, a large number of players will be created and deleted. At this time, we use GhostEntityMgr memory pool to create and delete online game characters .

Creating a network player character requires the following:

d: The client GhostCharactor uniformly processes the network events of the corresponding roles sent from the server;

e: For network characters operated by local players, in addition to adding GhostCharactor to this node, GhostEntityMgr also adds a player operation component PlayerOpt, mainly to send player operations to the server. After the server receives the event, it calculates the latest state and notifies interested clients of the changed state.

f: GhostCharactor design a data structure to save the player's game data, such as hp, attack, etc.,

Take a look at the entire architecture diagram, as follows:

Some things to pay attention to when optimizing the performance of online players

When the Unity client is multiplayer online, we need to pay attention to the following points when optimizing:

a:  memory pool to manage player objects;

Because MMORPG and other multiplayer online games will have AOI areas, network players will frequently enter the AOI area and leave the AOI area, which will lead to frequent creation and deletion of a network player object node on the client side, so generally we Player objects are managed based on a memory pool, so that player objects can be created and deleted quickly.

b:  Optimization of UI elements such as player's health bar nickname

Pay attention to the drawcall of the player's UI elements, and reduce the drawcall of the UI elements in batches as much as possible. At the same time, the health bar and the player's nickname will change, so it is best to put the character UI elements under a separate Canvas.

e:  Make logs and videos during the battle to facilitate bug tracking and analysis.

A large number of players online games will be created and deleted by a large number of players at the same time. At the same time, a large amount of data will come over. When processing network data, we must make a log of the status to facilitate our analysis.

f:  According to the high, middle and low end of the mobile phone device, the rendering effect is customized for performance .

Obtain the current model of the mobile phone, determine which type of machine it belongs to, and determine whether details such as special effects and shadows are displayed according to the high, medium and low classification of the machine, so as to maximize the smoothness of the game.

There are other optimization matters, which are analyzed and optimized according to the problems in specific actual projects.

The content of this section is shared here, pay attention to me and learn more about online game development.

Guess you like

Origin blog.csdn.net/voidinit/article/details/126378052