Data synchronization method, device, storage medium and program product based on Unity engine
By introducing a third-party two-dimensional physics engine and intermediate layer based on fixed-point number calculations in the Unity game engine, the problem of inconsistent physical collision calculations in the Unity game engine is solved, and the physical simulation consistency and data interaction overhead of multi-client platforms are achieved.
Patent Information
- Application Number
- CN202411914794.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2025-04-04
AI Technical Summary
When using the Unity game engine to develop games with physical collisions, a third-party physics engine based on floating-point calculations results in inconsistent game status calculation results for multiple players, and relying on server synchronization increases data interaction overhead.
Design a middle layer of a third-party two-dimensional physics engine and Unity game engine based on fixed-point number calculation. The physics manager of the logic layer obtains the motion state description data of the application layer object and passes it to the third-party two-dimensional physics engine. The third-party two-dimensional physics engine updates the state of the physical body based on this data and passes the results back to the application layer.
By using a third-party two-dimensional physics engine based on fixed-point number calculations, we ensure that the physical simulation results of multi-client platforms are consistent, and the game status of all players is synchronized without server synchronization, reducing data interaction overhead.
Smart Images

Figure CN119746413A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of game development technology, and in particular to a data synchronization method, device, storage medium and program product based on the Unity engine. Background Art
[0002] When using the Unity game engine to develop games with physical collisions, you need to ensure that the game states of all players are synchronized. However, the third-party physics engine based on floating-point calculations integrated into Unity will cause inconsistent game state calculation results for multiple players.
[0003] Currently, the game data of all players can be uniformly received and processed through the server, so that each player can update his or her own game status according to the server scheduling results to avoid the calculation difference problem caused by the third-party physics engine based on floating-point calculation.
[0004] However, this synchronization technology relies on data stream interaction between the client and the server, which increases the overhead of data interaction.
[0005] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0006] The main purpose of this application is to provide a data synchronization method, device, storage medium and computer program product based on the Unity engine, aiming to solve the technical problem of high data interaction overhead when relying on a server to synchronize player status.
[0007] To achieve the above purpose, the present application proposes a data synchronization method based on the Unity engine, which is applied to a data synchronization system. The data synchronization system includes a physics manager arranged at a logical layer, and a third-party two-dimensional physics engine based on fixed-point number calculation. The data synchronization method includes:
[0008] If the value of the clock of the logic layer can divide the predetermined time step, the physical manager of the logic layer obtains the motion state description data of the application layer object, and transmits the motion state description data to the third-party two-dimensional physical engine;
[0009] The third-party two-dimensional physics engine determines the physical body data of the physical body corresponding to the application layer object based on the motion state description data, and transmits the physical body data to the physics manager;
[0010] The application layer receives the physics volume data from the physics manager and uses the physics volume data to update the position and angle of the application layer objects.
[0011] In one embodiment, before the step of the physical manager of the logic layer obtaining the motion state description data of the application layer object and transmitting the motion state description data to the third-party two-dimensional physical engine, the following step is further included:
[0012] The logic layer determines the creation attribute parameters passed by the application layer;
[0013] Based on the creation attribute parameters, a rigid body entity and a collision body entity are created in a third-party two-dimensional physics engine, and the collision body entity is bound to the rigid body entity to obtain a physical body.
[0014] In one embodiment, based on the creation attribute parameters, a rigid body entity and a collision body entity are created in a third-party two-dimensional physics engine, and the collision body entity is bound to the rigid body entity. After the step of obtaining the physics body, the step further includes:
[0015] After the attribute parameters of the physical body are passed to the application layer, an application layer object corresponding to the physical body is created in the application layer.
[0016] In one embodiment, the creation attribute parameters include mass, linear resistance, angular resistance, gravity release factor, and whether it is a fast object.
[0017] In one embodiment, after the third-party two-dimensional physics engine determines the physics volume data of the physics volume corresponding to the application layer object based on the motion state description data, the method further includes:
[0018] The third-party two-dimensional physics engine performs collision detection between physical bodies and obtains collision detection results;
[0019] If a collision event is determined between physical bodies based on the collision detection result, the corresponding callback function is executed for the physical bodies that collided;
[0020] The callback function is obtained by corresponding to the application layer object of the application layer, and the application layer object is controlled to execute the collision logic in the callback function.
[0021] In one embodiment, if it is determined based on the collision detection result that there is a collision event between physical bodies, the step of executing a corresponding callback function on the physical bodies where the collision occurs includes:
[0022] If it is determined based on the collision detection result that there is a collision event between the physical bodies, the callback function corresponding to the trigger condition is executed for the physical bodies that collide.
[0023] In one embodiment, the collision logic includes one of playing a sound, generating a particle effect, and changing a state of an application layer object.
[0024] In addition, to achieve the above-mentioned purpose, the present application also proposes a data synchronization device based on the Unity engine, the device including: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the data synchronization method based on the Unity engine as described above.
[0025] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the data synchronization method based on the Unity engine as described above are implemented.
[0026] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the data synchronization method based on the Unity engine are implemented as described above.
[0027] This application designs an intermediate layer between a third-party two-dimensional physics engine based on fixed-point number calculation and the Unity game engine. If the value of the clock of the logic layer can divide the predetermined time step, the physical manager of the logic layer obtains the motion state description data of the application layer object and passes the motion state description data to the third-party two-dimensional physics engine; the third-party two-dimensional physics engine determines the physical body data of the physical body corresponding to the application layer object based on the motion state description data, and passes the physical body data to the physical manager; the application layer receives the physical body data from the physical manager and uses the physical body data to update the position and angle of the application layer object. Since a third-party two-dimensional physics engine based on fixed-point number calculation is used to simulate the physical behavior of the physical body, the physical simulation calculation results of multiple client platforms are consistent, so that the game status of all players can be synchronized without using a server to synchronize the status of all players, reducing data interaction overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0029] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0030] Figure 1 This is a schematic diagram of the data synchronization system structure based on the Unity engine for this application;
[0031] Figure 2A flowchart of the first embodiment of the data synchronization method based on the Unity engine of this application is provided;
[0032] Figure 3 A flowchart of the second embodiment of the data synchronization method based on the Unity engine of the present application is provided;
[0033] Figure 4 A flowchart of the fourth embodiment of the data synchronization method based on the Unity engine of the present application is provided;
[0034] Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the data synchronization method based on the Unity engine in the embodiment of the present application.
[0035] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0036] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0037] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0038] When using the Unity game engine to develop games with physical collisions, it is necessary to ensure that the game states of all players can be synchronized. However, the third-party physics engine based on floating-point calculations integrated into Unity will cause inconsistent calculation results for multiple players' game states. Currently, the game data of all players can be uniformly received and processed by the server, so that each player can update his or her own game state according to the server scheduling results to avoid the calculation difference problem caused by the third-party physics engine based on floating-point calculations. However, this synchronization technology relies on the data stream interaction between the client and the server, which increases the overhead of data interaction.
[0039] In response to the above problems, the main solution of this application is: if the value of the clock of the logical layer can divide the predetermined time step, the physical manager of the logical layer obtains the motion state description data of the application layer object, and passes the motion state description data to the third-party two-dimensional physics engine; the third-party two-dimensional physics engine determines the physical body data of the physical body corresponding to the application layer object based on the motion state description data, and passes the physical body data to the physical manager; the application layer receives the physical body data from the physical manager, and uses the physical body data to update the position and angle of the application layer object.
[0040] The solution of the present application uses a third-party two-dimensional physics engine based on fixed-point number calculations to simulate the physical behavior of physical bodies, so that the physical simulation calculation results of multiple client platforms are consistent, and the game status of all players can be synchronized without using a server to synchronize the status of all players, thereby reducing data interaction overhead.
[0041] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a data synchronization system, etc. The following takes the data synchronization system as an example to illustrate this embodiment and the following embodiments.
[0042] It should be noted that the application scenario of this embodiment includes the Unity game engine platform.
[0043] It should be noted that, refer to Figure 1 , a schematic diagram of the data synchronization system structure of this embodiment, wherein the data synchronization system includes an application layer, a logic layer, and a third-party two-dimensional physical engine based on fixed-point number calculations, and the physical manager in the logic layer manages the data interaction between the application layer and the third-party two-dimensional physical engine.
[0044] Based on this, the embodiment of the present application provides a data synchronization method based on the Unity engine, referring to Figure 2 , Figure 2 This is a flow chart of the first embodiment of the data synchronization method based on the Unity engine of the present application.
[0045] In this embodiment, the data synchronization method based on the Unity engine includes steps S10 to S30:
[0046] Step S10: If the value of the clock of the logic layer can divide the predetermined time step, the physical manager of the logic layer obtains the motion state description data of the application layer object, and transmits the motion state description data to the third-party two-dimensional physical engine.
[0047] It should be noted that the physics manager refers to the module responsible for managing the physical body in the logical layer, and is mainly responsible for managing and processing all objects and systems related to physical behaviors in the game. Its main function is to pass the results of the physical simulation behavior in the game to the application layer objects, so that the performance of the application layer objects is closer to the real physical rules. Among them, the physical simulation behavior can be motion, collision, gravity, etc. The motion state description data can be the position, angle, speed, acceleration, collision information, physical properties, force and torque, shape and size of the application layer objects.
[0048] In this embodiment, a timer is set in the logic layer system. When the value of the timer reaches a predetermined time step, the physical manager obtains the motion state description data such as position, angle, speed, acceleration, force, etc. of the application layer object through the data interface, and transmits the above motion state description data to the third-party two-dimensional physics engine, so that the motion state description data of the application layer object can be transmitted to the third-party two-dimensional physics engine at intervals, so that the third-party two-dimensional physics engine can obtain the motion state description data of the application layer object in time to perform physical behavior simulation.
[0049] Step S20: The third-party two-dimensional physics engine determines the physics volume data of the physics volume corresponding to the application layer object based on the motion state description data, and transmits the physics volume data to the physics manager.
[0050] It should be noted that the physical volume data can be any parameter that can describe the state of an object, such as mass, friction coefficient, size, shape, speed, angle, etc.
[0051] In a feasible implementation, the third-party two-dimensional physics engine sets the initial information such as the initial position, speed and direction of the physics body corresponding to the application layer object according to the motion state description data of the application layer object, and performs physical simulation on the physics body according to a predetermined time step interval to obtain new state data of the physics body after the physics simulation is completed, and transmits the new state data as physics body data to the physics body manager.
[0052] In this embodiment, the third-party two-dimensional physics engine receives the motion state description data of the application layer object through the data interface, uses the motion state description data to update the physical body data of the physical body corresponding to the application layer object, and calculates the physical body data after the physical body simulates the physical behavior within a predetermined time step. The third-party two-dimensional physics engine then passes the physical body data to the physics manager through the application programming interface, so that the data after the third-party two-dimensional physics engine runs the physical simulation can be set to the application layer object through the physics manager in a timely manner, so as to truly simulate the physical behavior of the application layer object and improve the authenticity of the behavior of the application layer object.
[0053] Step S30: The application layer receives the physical volume data from the physical manager, and uses the physical volume data to update the position and angle of the application layer object.
[0054] In this embodiment, the application layer object and its corresponding physical body are connected through a unique entity identifier. The application layer finds the application layer object corresponding to the physical body in the application layer based on the current position and current angle data of the physical body received from the physical manager and the entity identifier of the physical body, and synchronously updates the current position and current angle data of the application layer object, so that the physical behavior data of the physical body can be accurately updated to its corresponding application layer object, thereby improving development efficiency.
[0055] This embodiment is implemented based on the first embodiment. In the second embodiment of the present application, refer to Figure 3 , before step S10 of the data synchronization method based on the Unity engine, it also includes steps A01 to A02:
[0056] Step A01: The logic layer determines the creation attribute parameters passed by the application layer.
[0057] It should be noted that the creation attribute parameters are the data values used to define the initial characteristics and behaviors of an object when creating it, such as a physical body, a game character, a graphic element, etc. It includes parameters related to rigid body properties and parameters related to collision body properties, such as mass, linear resistance, angular resistance, gravity release factor, whether it is a fast object, etc. It is mainly passed from the application layer to the logic layer to initialize various properties and states of the physical body.
[0058] In a feasible implementation, the logic layer may obtain the creation attribute parameters passed by the application layer through a custom script or a constructor.
[0059] In this embodiment, a script is created that declares variables such as mass, angle, angular resistance, etc. of the application layer object, and the application layer object with this script is mounted on the corresponding scene node. The logic layer can obtain the creation attribute parameters through the public variables in the script to create a physical body corresponding to the application layer object in the third-party two-dimensional physics engine.
[0060] Step A02: based on the creation attribute parameters, a rigid body entity and a collision body entity are created in a third-party two-dimensional physics engine, and the collision body entity is bound to the rigid body entity to obtain a physics body.
[0061] It should be noted that a physical body refers to an object that can participate in physical behavior in a physical simulation environment. It is an abstract representation of an object with physical properties in the real world, and is used to simulate physical phenomena such as the movement, collision, and force of an object. It can have both rigid body properties and collision body properties to achieve realistic physical behavior and collision detection.
[0062] In addition, a rigid body is a component that gives an object physical properties, allowing it to move under the influence of forces in a physical simulation environment. A collision body is a component used to define the shape and collision range of an object. It itself is not affected by physical forces, but is only used to detect whether there is a collision between objects. By combining a rigid body and a collision body to create a physical body, the physical body can have both physical properties and collision conditions to ensure that objects in the game can react and interact with each other in the real physical world.
[0063] In this embodiment, the third-party two-dimensional physics engine first creates a rigid body entity according to the parameters related to the rigid body in the creation attribute parameters, and then creates a collision body entity according to the parameters related to the collision body in the creation attribute parameters, and finally binds the collision body entity to the rigid body entity to obtain a physical body, so that the physics engine can realistically simulate the movement and force of the object and perform collision processing, so that the application layer objects can achieve realistic and reasonable game performance in the game.
[0064] This embodiment is implemented based on the first and second embodiments. In the third embodiment of the present application, after step A02 of the data synchronization method based on the Unity engine, step A021 is further included:
[0065] Step A021, after the attribute parameters of the physical body are passed to the application layer, an application layer object corresponding to the physical body is created in the application layer.
[0066] It should be noted that application layer objects are objects that are directly related to business logic and user interaction during the game development process. These objects are usually characters, props, etc. in the game. They constitute the parts that players can directly see, operate or interact with in the game.
[0067] In addition, attribute parameters refer to the real-time status and event information generated by the physical body during the physical simulation process returned by the logic layer, which is used to update the performance of the corresponding application layer object and process related logic. It can be a physical state parameter, such as the current position, current speed, current acceleration, etc., or a joint connection parameter, such as joint angle, joint force, etc.
[0068] In this embodiment, the application layer receives the attribute parameters of the physical body transmitted by the physical engine through the physical manager, and creates corresponding application layer objects according to the information in the attribute parameters to achieve mapping between the application layer objects and the physical body for subsequent use of the physical body simulation.
[0069] This embodiment is implemented based on the first embodiment. In the fourth embodiment of the present application, refer to Figure 4 , after step S20 of the data synchronization method based on the Unity engine, further comprising steps S21 to S23:
[0070] Step S21: The third-party two-dimensional physics engine performs collision detection between physical bodies to obtain collision detection results.
[0071] It should be noted that collision detection is a key function in the physics engine, which is mainly used to determine whether two or more objects in the physical simulation environment are in contact or intersecting. The collision detection results include no collision and collision.
[0072] In a feasible implementation, the third-party two-dimensional physics engine can determine whether there is a collision event between physical bodies by means of ray detection, physical query function or callback function, and obtain a collision detection result.
[0073] In this embodiment, there are colliders on the physical body, and the collision detection system in the third-party physics engine will check the intersection between all colliders in the scene in each physical simulation frame. If an intersection between the colliders is detected, the collision detection result is determined to be a collision.
[0074] Step S22: If it is determined based on the collision detection result that there is a collision event between the physical bodies, a corresponding callback function is executed on the physical bodies where the collision occurs.
[0075] It should be noted that collision events include multiple collision scenarios, which can be a physical body stepping into a specific area or colliding with other physical bodies. The callback function is used to execute the corresponding event based on the collision detection result. The event to be executed by the callback function is pre-defined and can be called at different stages of the collision. At the same time, the callback function needs to be defined on the object in advance so that it can be triggered to perform the corresponding operation when a collision event occurs on the object.
[0076] In a feasible implementation, there is a collision event in the physical world of the third-party physics engine, and the physical body where the collision event occurs is determined. If the physical body where the collision event occurs has a corresponding callback function, the callback function corresponding to the physical body is executed.
[0077] In this embodiment, physical body C and physical body D collide in the physical world of a third-party physics engine. Physical body C has a corresponding callback function, but physical body D does not have a corresponding callback function. The callback function on physical body C is called and executed at the moment of collision, thereby accessing data such as the speed and position of physical body C and performing corresponding operations. This method of dynamically setting callback functions eliminates the need for the third-party physics engine to allocate resources to physical bodies that do not require callback functions, which not only improves the processing efficiency of the third-party physics engine, but also enriches the game interaction level.
[0078] Step S23, obtaining the application layer object of the application layer corresponding to the callback function, and controlling the application layer object to execute the collision logic in the callback function.
[0079] It should be noted that collision logic refers to a series of rules and operations that need to be executed when two or more objects collide in a game or physical simulation. It is built based on collision events and is used to determine the behavior, state changes, and other related game events that may be triggered by the objects after the collision.
[0080] In addition, the physical body can be associated with its corresponding application layer object through a callback function. This association can be done by referencing the relevant components of the application layer object through the callback function, or by referencing the application layer object through the callback function, or through event delegation.
[0081] In this embodiment, there is a reference to the application layer object in the callback function, and the third-party physics engine can operate the application layer object corresponding to the physics body through the callback function. In the collision event of the ball physics body and the block physics body, the transformation component of the application layer object corresponding to the ball physics body can be obtained through the callback function of the ball physics body, and then the position or rotation and other properties of the application layer object can be modified. This method allows the physical simulation behavior of the physics body and the performance of the application layer object to be closely integrated, and realizes the timely response to the game vision and interaction after the physical event is triggered, thereby providing a more realistic and rich game experience.
[0082] This embodiment is implemented based on the first and fourth embodiments. In the fifth embodiment of the present application, step S22 of the data synchronization method based on the Unity engine includes step S221:
[0083] Step S221: If it is determined based on the collision detection result that there is a collision event between the physical bodies, a callback function corresponding to the trigger condition is executed on the physical bodies where the collision occurs.
[0084] It should be noted that a physics body can have multiple callback functions, each callback function has a set trigger condition, where the trigger condition can be the moment when the physics body starts to collide, the moment when the physics body ends the collision, the moment when the physics body starts to enter the trigger area of another object, the moment when the physics body completely exits the trigger area of another object, the moment when the collision body collides with another object and maintains contact, and the moment when the collision body exists in a specific area.
[0085] In this embodiment, in a racing game, when a racing car collides with an obstacle such as a stone or an abandoned vehicle, a callback function corresponding to the collision obstacle on the racing car's physics body will be called, and the callback function will reduce the speed of the racing car; when the racing car enters the acceleration zone, the callback function corresponding to the acceleration zone on the racing car's physics body will be called, causing the racing car to accelerate.
[0086] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the data synchronization method of the present application based on the Unity engine. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0087] The present application provides a data synchronization device based on the Unity engine, and the data synchronization device based on the Unity engine includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data synchronization method based on the Unity engine in the above-mentioned embodiment one.
[0088] Reference below Figure 5 , which shows a schematic diagram of the structure of a data synchronization device based on the Unity engine suitable for implementing the embodiment of the present application. The data synchronization device based on the Unity engine in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The data synchronization device based on the Unity engine shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0089] like Figure 5As shown, the data synchronization device based on the Unity engine may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the data synchronization device based on the Unity engine are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 can allow the data synchronization device based on the Unity engine to communicate wirelessly or wired with other devices to exchange data. Although the data synchronization device based on the Unity engine with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.
[0090] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0091] The data synchronization device based on the Unity engine provided by the present application adopts the data synchronization method based on the Unity engine in the above embodiment, which can solve the problem of high data interaction overhead when relying on the server to synchronize the player status. Compared with the prior art, the beneficial effects of the data synchronization device based on the Unity engine provided by the present application are the same as the beneficial effects of the data synchronization method based on the Unity engine provided by the above embodiment, and the other technical features of the data synchronization device based on the Unity engine are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0092] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0093] The above are only specific implementations of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0094] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the data synchronization method based on the Unity engine in the above-mentioned embodiment.
[0095] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0096] The computer-readable storage medium may be included in a data synchronization device based on the Unity engine; or may exist independently without being assembled into a data synchronization device based on the Unity engine.
[0097] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by a data synchronization device based on the Unity engine, the data synchronization device based on the Unity engine: if the value of the clock of the logical layer can divide the predetermined time step, the physical manager of the logical layer obtains the motion state description data of the application layer object, and passes the motion state description data to the third-party two-dimensional physics engine; the third-party two-dimensional physics engine determines the physical body data of the physical body corresponding to the application layer object based on the motion state description data, and passes the physical body data to the physical manager; the application layer receives the physical body data from the physical manager, and uses the physical body data to update the position and angle of the application layer object.
[0098] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0099] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0100] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0101] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned data synchronization method based on the Unity engine, and can solve the technical problem of high data interaction overhead when relying on the server to synchronize the player status. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the data synchronization method based on the Unity engine provided by the above-mentioned embodiment, and will not be repeated here.
[0102] The present application also provides a program product, including a computer program, which implements the steps of the data synchronization method based on the Unity engine as described above when the computer program is executed by a processor.
[0103] The computer program product provided by the present application can solve the technical problem of high data interaction overhead when relying on the server to synchronize the player status. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the data synchronization method based on the Unity engine provided by the above embodiment, and will not be repeated here.
[0104] The above are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A data synchronization method based on Unity engine, characterized in that: Applied to a data synchronization system, the data synchronization system includes a physical manager arranged at a logic layer, and a third-party two-dimensional physical engine based on fixed-point number calculation, and the data synchronization method includes: If the value of the clock of the logic layer can divide the predetermined time step, the physics manager obtains the motion state description data of the application layer object, and transmits the motion state description data to the third-party two-dimensional physics engine; The third-party two-dimensional physics engine determines the physical volume data of the physical volume corresponding to the application layer object based on the motion state description data, and transmits the physical volume data to the physics manager; The application layer receives the physics volume data from the physics manager and uses the physics volume data to update the position and angle of the application layer object.
2. The data synchronization method based on the Unity engine according to claim 1, characterized in that: Before the step of the physical manager of the logical layer acquiring the motion state description data of the application layer object and transmitting the motion state description data to the third-party two-dimensional physical engine, the method further includes: The logic layer determines the creation attribute parameters transmitted by the application layer; Based on the creation attribute parameters, a rigid body entity and a collision body entity are created in the third-party two-dimensional physics engine, and the collision body entity is bound to the rigid body entity to obtain the physics body.
3. The data synchronization method based on the Unity engine as claimed in claim 2, characterized in that: After the step of creating a rigid body entity and a collision body entity in the third-party two-dimensional physics engine based on the creation attribute parameters and binding the collision body entity to the rigid body entity to obtain the physics body, the method further includes: After the attribute parameters of the physical body are transferred to the application layer, the application layer object corresponding to the physical body is created in the application layer.
4. The data synchronization method based on the Unity engine as claimed in claim 2, characterized in that: The creation attribute parameters include mass, linear resistance, angular resistance, gravity release factor, and whether it is a fast object.
5. The data synchronization method based on the Unity engine according to claim 1, characterized in that: After the step of determining, by the third-party two-dimensional physical engine, the physical body data of the physical body corresponding to the application layer object based on the motion state description data, the method further includes: The third-party two-dimensional physics engine performs collision detection between physical bodies to obtain collision detection results; If a collision event is determined between physical bodies based on the collision detection result, a corresponding callback function is executed on the physical bodies where the collision occurs; The application layer object of the application layer corresponding to the callback function is obtained, and the application layer object is controlled to execute the collision logic in the callback function.
6. The data synchronization method based on the Unity engine as claimed in claim 5, characterized in that: If it is determined based on the collision detection result that there is a collision event between the physical bodies, the step of executing a corresponding callback function on the physical bodies where the collision occurs comprises: If it is determined based on the collision detection result that there is a collision event between the physical bodies, a callback function corresponding to the trigger condition is executed on the physical bodies where the collision occurs.
7. The data synchronization method based on the Unity engine according to claim 5, characterized in that: The collision logic includes one of playing a sound, generating a particle effect, and changing the state of the application layer object.
8. A data synchronization device based on Unity engine, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the data synchronization method based on the Unity engine as claimed in any one of claims 1 to 7.
9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the data synchronization method based on the Unity engine as described in any one of claims 1 to 7 are implemented.
10. A program product, characterized in that The program product comprises a computer program, and when the computer program is executed by a processor, the steps of the data synchronization method based on the Unity engine as claimed in any one of claims 1 to 7 are implemented.