CN112579062A - Data interaction method between Lua language and Unity - Google Patents
Data interaction method between Lua language and Unity Download PDFInfo
- Publication number
- CN112579062A CN112579062A CN202011544878.3A CN202011544878A CN112579062A CN 112579062 A CN112579062 A CN 112579062A CN 202011544878 A CN202011544878 A CN 202011544878A CN 112579062 A CN112579062 A CN 112579062A
- Authority
- CN
- China
- Prior art keywords
- lua
- unity
- variable
- language
- data
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
-
- A—HUMAN NECESSITIES
- A63—SPORTS; GAMES; AMUSEMENTS
- A63F—CARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
- A63F13/00—Video games, i.e. games using an electronically generated display having two or more dimensions
- A63F13/70—Game security or game management aspects
- A63F13/77—Game security or game management aspects involving data related to game devices or game servers, e.g. configuration data, software version or amount of memory
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
-
- A—HUMAN NECESSITIES
- A63—SPORTS; GAMES; AMUSEMENTS
- A63F—CARD, BOARD, OR ROULETTE GAMES; INDOOR GAMES USING SMALL MOVING PLAYING BODIES; VIDEO GAMES; GAMES NOT OTHERWISE PROVIDED FOR
- A63F2300/00—Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game
- A63F2300/50—Features of games using an electronically generated display having two or more dimensions, e.g. on a television screen, showing representations related to the game characterized by details of game servers
- A63F2300/55—Details of game data or player data management
- A63F2300/5526—Game data structure
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- General Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Multimedia (AREA)
- Computing Systems (AREA)
- Business, Economics & Management (AREA)
- Computer Security & Cryptography (AREA)
- General Business, Economics & Management (AREA)
- Stored Programmes (AREA)
Abstract
The invention discloses a data interaction method between Lua language and Unity, which comprises the following steps: s1, defining the type of the Lua variable, converting the type of the Lua variable into a Lua code with a fixed format and writing the Lua code into a Lua script file mounted on the C # intermediary component; s2, automatically assigning the Lua variables and storing the Lua variables into a data container in the C # intermediary component; s3, automatically serializing the data in the data container; s4, the C # intermediary component deserializes all the serialized data collected from the data container and assembles the serialized data into a LuaTable type variable which can be identified by the Lua language; s5, the C # broker component initializes the Lua script file and passes the LuaTable type variables to the Lua script file for use to pass the variables. The invention realizes the data interaction between the Lua and the Unity through the C # intermediary component, greatly simplifies the variable declaration and the using process of the Lua language, and simultaneously improves the game performance of the Lua language when the Unity object is used.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a data interaction method between Lua language and Unity.
Background
The hot update of the Unity engine game is an important technology of the current mobile platform network game, and the interaction flow of the C # language and the Unity object provided by the existing Unity game engine is as follows: c # declares the variable, drags the bound or edited object under the Unity editor. Different from the C # language supported by the Unity engine, the Unity does not provide the support of variable binding for the Lua language, including Lua variable identification, editing, storage and use processes, and in game development, the Lua language, the Unity object and the component can only call the C # interface "Find" (query) and "GetComponent" (obtain object) provided by the Unity to obtain the object or the component when interacting, which leads to a tedious development process, and meanwhile, the game performance is also affected in a frequent object calling process.
Disclosure of Invention
In order to solve the problems, the invention provides a data interaction method between the Lua language and the Unity, which greatly simplifies the variable declaration and the use flow of the Lua language and simultaneously improves the game performance of the Lua language when the Unity object is used.
The invention adopts the following technical scheme:
a data interaction method between Lua language and Unity comprises the following steps:
s1, defining the type of Lua variable: defining the type of the Lua local variable in a naming mode, converting the type of the Lua local variable into a Lua code with a fixed format, and writing the Lua code into a Lua script file mounted on a C # intermediate component on a corresponding Unity scene or a prefabricated body;
s2, assignment and storage of Lua variables: analyzing the Lua codes, identifying all variables and the types corresponding to the variables, traversing the stored Unity scene or prefabricated body, finding objects corresponding to the Lua variables through names, automatically assigning values to the Lua variables, and putting all the collected objects into a data container in the C # intermediary component;
s3, automatic serialization: serializing and persistently storing the data in the data container into a scene file or a prefabricated body file of Unity;
s4, deserialization: after the game runs and is activated, the C # intermediary component deserializes all the serialized data collected in the data container and assembles the serialized data into a LuaTable type variable which can be identified by Lua language;
s5, transfer variable: and the C # intermediary component initializes the self-mounted Lua script file and transmits the LuaTable type variable to the Lua script file for use.
Further, the definition of the type in the step S1 is written manually or automatically.
Further, the types include a reference type including a game object, a material, a morph, a camera, or a button, and a value type including an integer variable, a single precision floating point number, or an array.
Further, the Lua code parsing in step S2 adopts a regular expression.
Further, the assignment in step S2 may also adopt manual assignment, specifically: and the Unity calls an EditorGUILAyout-ObjectField interface to draw, and assigns the Lua variable directly on a monitor panel of the Unity.
Further, the automatic serialization in the step S3 is automatically completed by Unity.
Further, the step S3 needs to mark the scene file or the pre-form file of Unity as dirty before storing.
Further, the deserialization process in step S4 is automatically performed for Unity.
After adopting the technical scheme, compared with the background technology, the invention has the following advantages:
1. data interaction between Lua and Unity is realized through the C # intermediary component, variable declaration and using flow of Lua language are greatly simplified, and game performance of Lua language when a Unity object is used is improved;
2. the functions of type definition, identification, editing, storage and use of the Lua variable of the weak type language by the Unity are realized, and the Lua definition variable is added to automatically generate codes;
3. before the Unity scene or the prefabricated body is stored, the value of the Lua variable is automatically assigned, so that the support of C # language by the Unity is more convenient than that of C # language;
4. when the game runs, the data is deserialized and transmitted to the Lua script file, so that the development personnel can use the data conveniently.
Drawings
FIG. 1 is a schematic flow chart of the method of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Examples
As shown in fig. 1, a method for data interaction between Lua language and Unity includes the following steps:
s1, defining the type of Lua variable: defining the type of the Lua local variable in a naming mode, converting the type of the Lua local variable into a Lua code with a fixed format, and writing the Lua code into a Lua script file mounted on a C # intermediate component on a corresponding Unity scene or a prefabricated body;
for example: for the Lua variable "_ gosest" (execution test), which is defined as the Game object type of Unity, the Lua code definition declares as:
annotating the code: - @ typeGameObject @ _ goTest;
variable declaration: local _ goTest ═ bind. _ goTest;
this artificially defines the Lua variable "_ goTest" without any type as a GameObject type, whose object naming requires the beginning of "_ go" for subsequent recognition. The same holds true for common types in Unity such as: objects and components such as Materail (materials), Transform (variants), Camera (Camera), Button (buttons), etc., are also type-defined using the above method;
thus, step S1 realizes automatic writing of the corresponding Lua code by means of identifying a name.
The definition of the type described in the step S1 is written manually or automatically.
The types include a reference type including game objects, materials, morphs, cameras, buttons, etc., and a value type including integer variables, single precision floating point numbers, arrays, etc.
S2, assignment and storage of Lua variables: analyzing the Lua codes, identifying all variables and the types corresponding to the variables, traversing the stored Unity scene or prefabricated body, finding objects corresponding to the Lua variables through names, automatically assigning values to the Lua variables, and putting all the collected objects into a data container in the C # intermediary component;
and adopting a regular expression when the Lua code is analyzed in the step S2.
The assignment in step S2 may also adopt manual assignment, specifically: the Unity calls the editor guiliayout. objectfield interface to draw, and assigns the Lua variable directly on the supervisor panel (observer) of Unity. Variables of the reference type can be assigned manually or automatically, while variables of the value type are assigned manually mainly on a supervisor (observer) panel.
For example: after parsing, for the Lua variable "_ goTest", the corresponding type "GameObject" is found.
S3, automatic serialization: serializing and persistently storing the data in the data container into a scene file or a prefabricated body file of Unity; the automatic serialization in said step S3 is automatically completed by Unity. Said step S3 requires marking the scene (.unity) file or the prefabricated body (.prefab) file of said Unity as dirty "", before storing.
S4, deserialization: after the game runs and is activated, the C # intermediary component deserializes all the serialized data collected in the data container and assembles the serialized data into a LuaTable type variable which can be identified by Lua language; the deserialization process in step S4 is performed automatically for Unity.
For the LuaTable type variable "bind", we only need to correspond the LuaTable type variable "bind" to the name of the Lua variable, such as: and assigning the 'goTest' object of Unity to the 'bind. _ goTest', namely finishing the assembly.
S5, transfer variable: and the C # intermediary component initializes the self-mounted Lua script file and transmits the LuaTable type variable to the Lua script file for use.
From the above steps, the local variable "local _ goTest" of Lua can be assigned by "bind. _ goTest", and the developer can conveniently use the already assigned local variable "goTest".
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope of the present invention are included in the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims (8)
1. A data interaction method between Lua language and Unity is characterized in that: the method comprises the following steps:
s1, defining the type of Lua variable: defining the type of the Lua local variable in a naming mode, converting the type of the Lua local variable into a Lua code with a fixed format, and writing the Lua code into a Lua script file mounted on a C # intermediate component on a corresponding Unity scene or a prefabricated body;
s2, assignment and storage of Lua variables: analyzing the Lua codes, identifying all variables and the types corresponding to the variables, traversing the stored Unity scene or prefabricated body, finding objects corresponding to the Lua variables through names, automatically assigning values to the Lua variables, and putting all the collected objects into a data container in the C # intermediary component;
s3, automatic serialization: serializing and persistently storing the data in the data container into a scene file or a prefabricated body file of Unity;
s4, deserialization: after the game runs and is activated, the C # intermediary component deserializes all the serialized data collected in the data container and assembles the serialized data into a LuaTable type variable which can be identified by Lua language;
s5, transfer variable: and the C # intermediary component initializes the self-mounted Lua script file and transmits the LuaTable type variable to the Lua script file for use.
2. The method of claim 1, wherein the data interaction between the Lua language and Unity is as follows: the definition of the type described in the step S1 is written manually or automatically.
3. The method of claim 2, wherein the data interaction between the Lua language and Unity is as follows: the types include a reference type including a game object, material, morph, camera, or button, and a value type including an integer variable, a single precision floating point number, or an array.
4. The method of claim 1, wherein the data interaction between the Lua language and Unity is as follows: and adopting a regular expression when the Lua code is analyzed in the step S2.
5. The method of claim 1, wherein the data interaction between the Lua language and Unity is as follows: the assignment in step S2 may also adopt manual assignment, specifically: and the Unity calls an EditorGUILAyout-ObjectField interface to draw, and assigns the Lua variable directly on a monitor panel of the Unity.
6. The method of claim 5, wherein the data interaction between the Lua language and the Unity is as follows: the automatic serialization in said step S3 is automatically completed by Unity.
7. The method of claim 6, wherein the data interaction between the Lua language and the Unity is as follows: the step S3 needs to mark the scene file or the prefabricated file of Unity as dirty before storing.
8. The method of claim 7, wherein the data interaction between the Lua language and Unity is as follows: the deserialization process in step S4 is performed automatically for Unity.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011544878.3A CN112579062B (en) | 2020-12-23 | 2020-12-23 | Data interaction method between Lua language and Unity |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011544878.3A CN112579062B (en) | 2020-12-23 | 2020-12-23 | Data interaction method between Lua language and Unity |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112579062A true CN112579062A (en) | 2021-03-30 |
CN112579062B CN112579062B (en) | 2022-04-29 |
Family
ID=75139340
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011544878.3A Active CN112579062B (en) | 2020-12-23 | 2020-12-23 | Data interaction method between Lua language and Unity |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112579062B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113656417A (en) * | 2021-07-23 | 2021-11-16 | 厦门雅基软件有限公司 | Data processing method, device, equipment and computer readable storage medium |
CN114679493A (en) * | 2022-03-23 | 2022-06-28 | 北京睿芯高通量科技有限公司 | Safe method for transmitting data in serialization and deserialization mode |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20110184718A1 (en) * | 2010-01-25 | 2011-07-28 | Chen Chung-Ching | Interlingua, Interlingua Engine, and Interlingua Machine Translation System |
CN106325866A (en) * | 2016-08-22 | 2017-01-11 | 网易(杭州)网络有限公司 | Cross-engine calling method and cross-engine calling device |
CN111858092A (en) * | 2020-07-06 | 2020-10-30 | 北京乐学帮网络技术有限公司 | Method, device and system for communication between scripts |
-
2020
- 2020-12-23 CN CN202011544878.3A patent/CN112579062B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20110184718A1 (en) * | 2010-01-25 | 2011-07-28 | Chen Chung-Ching | Interlingua, Interlingua Engine, and Interlingua Machine Translation System |
CN106325866A (en) * | 2016-08-22 | 2017-01-11 | 网易(杭州)网络有限公司 | Cross-engine calling method and cross-engine calling device |
CN111858092A (en) * | 2020-07-06 | 2020-10-30 | 北京乐学帮网络技术有限公司 | Method, device and system for communication between scripts |
Non-Patent Citations (1)
Title |
---|
张筱毅: ""COCOS2D-X强交互网络游戏架构设计与实践"", 《中国优秀硕士学位论文全文数据库信息科技辑》 * |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113656417A (en) * | 2021-07-23 | 2021-11-16 | 厦门雅基软件有限公司 | Data processing method, device, equipment and computer readable storage medium |
CN113656417B (en) * | 2021-07-23 | 2022-07-22 | 厦门雅基软件有限公司 | Data processing method, device, equipment and computer readable storage medium |
CN114679493A (en) * | 2022-03-23 | 2022-06-28 | 北京睿芯高通量科技有限公司 | Safe method for transmitting data in serialization and deserialization mode |
CN114679493B (en) * | 2022-03-23 | 2023-07-28 | 北京睿芯高通量科技有限公司 | Safe method for transmitting data in serialization and deserialization mode |
Also Published As
Publication number | Publication date |
---|---|
CN112579062B (en) | 2022-04-29 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109885488B (en) | Automatic test method and system for satellite orbit calculation software driven by case table | |
CN112579062B (en) | Data interaction method between Lua language and Unity | |
CN107918666B (en) | Data synchronization method and system on block chain | |
CN111241454B (en) | Method, system and device for generating webpage codes | |
CN109697979B (en) | Voice assistant skill adding method, device, storage medium and server | |
CN110244941B (en) | Task development method and device, electronic equipment and computer readable storage medium | |
CN1783004A (en) | Persistent memory manipulation using EFI | |
CN109614329B (en) | Software test case aided design method based on interface control file | |
CN111857801B (en) | Construction method of mobile application | |
CN111338618B (en) | Application scene driven Android application micro-service automatic generation method | |
CN111506314B (en) | Project development method, device, server and medium | |
CN100507871C (en) | Method and system for testing embedded file system | |
CN107526679A (en) | Automated test frame, the automated testing method based on thereon, storage medium and computer equipment | |
CN107748715B (en) | Unity-based texture map configuration information detection method and system | |
Reimann et al. | Role-based generic model refactoring | |
CN117762285A (en) | Terminal service processing method and device | |
CN116028022A (en) | Java technology-based zero code Excel data importing method, device and medium | |
CN109857462A (en) | The backstage Docker duty mapping method of remote sensing images visual editor | |
CN103246605A (en) | Method and system for collocating remote controller key values based on xml (extensive markup language) | |
CN117931623A (en) | Semiconductor parameter testing method and system based on interpreted high-level language | |
CN1521994A (en) | Method for implementing automatic test of intelligent service | |
CN110058855B (en) | Method, device and equipment for updating interface and workflow of software | |
CN112099793A (en) | Interface generation method and device, electronic equipment and storage medium | |
CN118502745B (en) | Visual arrangement method, system, medium and device based on back-end code generation | |
CN116400927B (en) | Code block translation method and device, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |