Object access method, code generation method, device, equipment and storage medium
By parsing the target Lua code file in the Lua runtime environment and displaying an object identifier selection page, users can directly select the Unity object identifier, which solves the problem of incorrect query paths in Unity projects and improves development efficiency.
Patent Information
- Application Number
- CN202210365488.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-07
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2042-04-07
AI Technical Summary
In Unity game projects, when searching for and caching Unity objects in the Lua runtime environment, excessively long query paths can easily lead to errors and low development efficiency.
This provides an object access method that parses the target Lua code file in the Lua runtime environment, displays an object identifier selection page, allows the user to select an identifier for a specific Unity object, and accesses the object based on the identifier lookup data, thus avoiding the need for manually typing the query path.
It improves the development efficiency of Unity projects and avoids errors caused by manually spelling Unity object query paths in the Lua runtime environment.
Smart Images

Figure CN114741068B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to an object access method, a code generation method, an apparatus, a device, and a storage medium. Background Technology
[0002] In Unity game projects, there are often numerous instances of searching for and caching Unity objects within the Lua runtime environment. When searching for Unity objects in the Lua runtime environment using Xlua (used to enable interaction between the Lua language and the C# language in Unity), the query path of the Unity object needs to be passed to the Lua runtime environment as a string via Xlua. Developers need to manually type the query path of the Unity object in the Lua runtime environment to implement the logic code for querying and caching Unity objects. However, if the query path of the Unity object is too long, manual typing is prone to errors and difficult to debug, leading to low development efficiency in Unity projects. Summary of the Invention
[0003] This application provides an object access method, a code generation method, an apparatus, a device, and a storage medium, which can improve the development efficiency of Unity projects.
[0004] This application provides an object access method, including:
[0005] In response to a parsing trigger operation for a target Lua code file in a Lua runtime environment, the target Lua code file is obtained. The target Lua code file includes object access code in Lua language. The object access code is generated based on Unity preset code and includes an object identifier and a data lookup identifier for a specific Unity object that needs to be accessed in the Lua runtime environment. The data lookup identifier is used to obtain the object data of the specific Unity object.
[0006] Parse the object access code in the target Lua code file, and display an object identifier selection page on the user interface based on the parsing results. The object identifier selection page includes the object identifier of the specific Unity object.
[0007] In response to the selection operation of the object identifier in the object identifier selection page, the specific Unity object corresponding to the selected object identifier is accessed based on the data lookup identifier.
[0008] Accordingly, embodiments of this application provide a code generation method, including:
[0009] Identify the specific Unity objects that need to be accessed in the Lua runtime environment from among the Unity objects included in the target Unity preset;
[0010] Based on the target Unity preset, obtain the data lookup identifier of the specific Unity object, record the data lookup identifier in a preset data structure to obtain object record information, and the position information of the data lookup identifier recorded in the preset data structure is integer data;
[0011] Import the target Unity preset and the object record information into the Lua runtime environment;
[0012] Obtain a Lua language object access code template in the Lua runtime environment. The object access code template is used to access Unity objects in the Lua runtime environment and includes several code segments to be replaced associated with the specific Unity object.
[0013] Based on the object identifier of the specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, code replacement is performed in the code segment to be replaced in the object access code template to obtain object access code, wherein the object access code includes the object identifier and data lookup identifier of the specific Unity object;
[0014] The target Lua code file is obtained based on the object access code. The target Lua code file is used to display the object identifier of the specific Unity object after being parsed for the user to select, and after selection, to access the specific Unity object corresponding to the selected object identifier based on the data lookup identifier.
[0015] Accordingly, embodiments of this application also provide an object access device, including:
[0016] The code file acquisition unit is used to acquire the target Lua code file in response to a parsing trigger operation for the target Lua code file in the Lua runtime environment. The target Lua code file includes object access code in Lua language. The object access code is generated based on Unity preset code and includes an object identifier and a data lookup identifier for a specific Unity object that needs to be accessed in the Lua runtime environment. The data lookup identifier is used to acquire the object data of the specific Unity object.
[0017] An identifier display unit is used to parse the object access code in the target Lua code file and display an object identifier selection page on the user interface based on the parsing result. The object identifier selection page includes the object identifier of the specific Unity object.
[0018] The access unit is used to respond to the selection operation of the object identifier in the object identifier selection page, and access the specific Unity object corresponding to the selected object identifier based on the data lookup identifier.
[0019] Optionally, the object access code includes object body access code and component access code of the mounted component of each specific Unity object. The component access code includes the object identifier of the specific Unity object and the component identifier of the mounted component. The object data includes the component identifier and component data of the mounted component.
[0020] The access unit is also used for:
[0021] In response to the selection operation of the object identifier in the object identifier selection page, the specific Unity object corresponding to the selected object identifier is determined as the target Unity object to be accessed;
[0022] Based on the parsing results, a component identifier selection page is displayed on the user interface. The component identifier selection page includes the target component identifier of the target mounted component of the target Unity object.
[0023] In response to the selection operation of the target component identifier in the component identifier selection page, the target mounted component corresponding to the selected target component identifier is accessed based on the data lookup identifier of the target Unity object.
[0024] Accordingly, embodiments of this application also provide a code generation apparatus, including:
[0025] The object determination unit is used to determine the specific Unity object that needs to be accessed in the Lua runtime environment from among the Unity objects included in the target Unity preset.
[0026] The recording unit is used to obtain the data lookup identifier of the specific Unity object based on the target Unity preset body, and record the data lookup identifier in a preset data structure to obtain object record information. The position information of the data lookup identifier recorded in the preset data structure is integer data.
[0027] The import unit is used to import the target Unity preset and the object record information into the Lua runtime environment.
[0028] The code template acquisition unit is used to acquire object access code templates in the Lua language under the Lua runtime environment. The object access code templates are used to access Unity objects under the Lua runtime environment and include several code segments to be replaced associated with the specific Unity object.
[0029] The replacement unit is used to replace the code in the code segment to be replaced in the object access code template based on the object identifier of the specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, to obtain object access code, wherein the object access code includes the object identifier and the data lookup identifier of the specific Unity object;
[0030] The code file obtaining unit is used to obtain a target Lua code file based on the object access code. The target Lua code file is used to display the object identifier of the specific Unity object after being parsed for the user to select, and after selection, to access the specific Unity object corresponding to the selected object identifier based on the data lookup identifier.
[0031] Optionally, the object determination unit is further configured to:
[0032] Based on the code of the target Unity preset, the settings subpage of the target Unity preset is displayed in the Unity runtime environment. The settings subpage includes the object identifier of the Unity object contained in the target Unity preset, and the object settings area.
[0033] When the target object identifier of the Unity object contained in the target Unity preset is selected, in response to the access flag operation in the object setting area corresponding to the target object identifier, the Unity object corresponding to the target object identifier is determined to be the specific Unity object that needs to be accessed in the Lua runtime environment.
[0034] Optionally, the object determination unit is further configured to:
[0035] When the target object identifier of the Unity object contained in the target Unity preset is selected, the target object setting area of the selected Unity object corresponding to the target object identifier is displayed in the Unity runtime environment. The target object setting area includes the object properties of the selected Unity object.
[0036] In response to the operation of adding a label to the object property of the selected Unity object in the target object settings area, the selected Unity object is determined to be the specific Unity object that needs to be accessed in the Lua runtime environment.
[0037] Optionally, the preset data structure is an array structure, and the recording unit is further used for:
[0038] Based on the target Unity preset, obtain the data lookup identifier of the specific Unity object;
[0039] If there are multiple specific Unity objects, the data lookup identifiers of each specific Unity object are recorded sequentially into the array structure according to a preset order to obtain the object record information.
[0040] Optionally, the recording unit is further configured to:
[0041] Mount the access log component to the target Unity preset;
[0042] The object record information is stored in the access record component;
[0043] The import unit is also used for:
[0044] In response to the import operation of the object data of the target Unity preset and the access record component from the Unity runtime environment to the Lua runtime environment, the target Unity preset and the object record information are imported into the Lua runtime environment.
[0045] Optionally, the replacement unit is further configured to:
[0046] Based on the object identifier of the specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, generate the target replacement code segment corresponding to each of the code segments to be replaced;
[0047] The object access code is obtained by replacing the corresponding code segment to be replaced in the object access code template with each of the target replacement code segments.
[0048] Optionally, the code segment to be replaced includes a code segment for identifying the object to be replaced, a code segment for accessing the object itself to be replaced, and a code segment for accessing the component to be replaced. The replacement unit is further used for:
[0049] Obtain the preset identifier of the target Unity preset from the object data of the target Unity preset, and use it as the target replacement code segment corresponding to the identifier code segment to be replaced;
[0050] Based on the data lookup identifier in the object record information and the object data of the target Unity preset, a code segment is generated to query and cache the specific Unity object, which serves as the target replacement code segment corresponding to the object body access code segment to be replaced;
[0051] Based on the target replacement code segment corresponding to the access code segment of the object to be replaced and the object identifier of the specific Unity object, the target replacement code segment corresponding to the access code segment of the component to be replaced is generated.
[0052] Optionally, the preset data structure in the object record information is an array structure, and the replacement unit is further used for:
[0053] Determine the index of the data lookup identifier record for each specific Unity object in the array structure;
[0054] Generate a first code segment that determines the data lookup identifier of the specific Unity object in the array structure based on the index;
[0055] Based on the determined data lookup identifier, a second code segment is generated to query and cache the object data of the specific Unity object in the object data of the target Unity preset;
[0056] The first code segment and the second code segment are merged into the target replacement code segment corresponding to the object body access code segment to be replaced.
[0057] Optionally, the replacement unit is further configured to:
[0058] The data lookup identifier of the specific Unity object is obtained based on the first code segment;
[0059] Based on the object data of the specific Unity object cached in the second code segment, obtain the component identifier of the mounted component of the specific Unity object;
[0060] The target replacement code segment corresponding to the access code segment of the component to be replaced is generated based on the object identifier of the specific Unity object, the data lookup identifier, and the component identifier.
[0061] Optionally, the replacement unit is further configured to:
[0062] If a specific Unity object has multiple mounted components, a code segment for accessing each mounted component is generated based on the object identifier of the specific Unity object, the data lookup identifier, and the component identifier of each mounted component.
[0063] The code segments that access each of the mounted components are concatenated to generate the target replacement code segment corresponding to the code segment accessing the component to be replaced.
[0064] Optionally, the replacement unit is further configured to:
[0065] Replace the corresponding identifier code segment, object body access code segment, and component access code segment in the object access code template with the target replacement code segments to obtain object access code including identifier code segment, object body access code segment, and component access code segment.
[0066] Similarly, embodiments of this application also provide a computer device, including:
[0067] Memory, used to store computer programs;
[0068] A processor for performing a step in either the object access method or the code generation method.
[0069] Furthermore, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of either the object access method or the code generation method.
[0070] This application provides an object access method, code generation method, apparatus, device, and storage medium. When a user wants to access a specific Unity object in the Lua runtime environment, a parsing trigger operation can be performed to cause the computer device to parse the object access code in the target Lua code file. An object identifier selection page, including the object identifier of the specific Unity object, is displayed on the user interface. The user can directly select the object identifier of the specific Unity object to be accessed on the object identifier selection page. After the computer device determines the data lookup identifier of the specific Unity object corresponding to the object identifier, the computer device can access the specific Unity object to be accessed according to the object identifier selected by the user and the determined data lookup identifier. This avoids the user manually typing the query path of the desired Unity object in the Lua runtime environment, thereby avoiding errors caused by manually typing the query path of the Unity object in the Lua runtime environment and improving the development efficiency of Unity projects. Attached Figure Description
[0071] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings required in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0072] Figure 1 This is a system schematic diagram of the object access device provided in the embodiments of this application;
[0073] Figure 2 This is a flowchart illustrating the object access method provided in an embodiment of this application;
[0074] Figure 3 This is a schematic diagram of the object identifier selection page provided in an embodiment of this application;
[0075] Figure 4 This is a schematic diagram of the component identifier selection page provided in an embodiment of this application;
[0076] Figure 5 This is a flowchart illustrating the code generation method provided in an embodiment of this application;
[0077] Figure 6 This is a schematic diagram of the settings subpage provided in an embodiment of this application;
[0078] Figure 7 This is a schematic diagram of array addition provided in an embodiment of this application;
[0079] Figure 8 This is a schematic diagram of the replacement process provided in an embodiment of this application;
[0080] Figure 9 This is a template code diagram of the access code segment of the component to be replaced provided in the embodiments of this application;
[0081] Figure 10 This is a schematic diagram of the structure of the object access device provided in the embodiments of this application;
[0082] Figure 11 This is a schematic diagram of the structure of the code generation apparatus provided in the embodiments of this application;
[0083] Figure 12 This is a schematic diagram of the structure of the computer device provided in the embodiments of this application. Detailed Implementation
[0084] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of the present invention, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0085] This application provides an object access method, a code generation method, an apparatus, a device, and a storage medium. Specifically, the object access method and code generation method of this application can be executed by a computer device, which can be a terminal or a server. The terminal can be a smartphone, tablet, laptop, touch screen, game console, personal computer (PC), personal digital assistant (PDA), or other terminal device. The terminal can also include a client, which can be a game application client, a front-end browser client carrying a game program, or an instant messaging client. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery network services, and big data and artificial intelligence platforms.
[0086] For example, when an object access method runs on a terminal, the terminal device stores a Lua code writing application that generates the Lua runtime environment and is used to present the scene in the user interface. The terminal device interacts with the user through the user interface, allowing the user to write code within it, for example, by downloading and installing a Lua code writing application (e.g., AndroLua, Qlua, Lua editor, etc.) and running it. The terminal device can provide the user interface to the user in various ways; for example, it can render the interface on the terminal device's screen or present it through holographic projection. For instance, the terminal device may include a touchscreen display and a processor. The touchscreen display is used to present the user interface and receive user commands generated by the user interacting with the user interface, which includes a code writing interface. The processor is used to run the Lua code writing application, generate the user interface, respond to command requests, and control the display of the user interface on the touchscreen display.
[0087] For example, when the code generation method runs on a terminal, the terminal device stores Lua code writing applications that generate the Lua runtime environment (e.g., AndroLua, Qlua, Lua editor, etc.) and code writing applications that generate the Unity runtime environment (e.g., Unity, Microsoft Visual Studio, etc.), and uses them to present scenes in the user interface. The terminal device interacts with the user through the user interface, allowing the user to write code within the user interface, for example, by downloading, installing, and running a Lua code writing application on the terminal device. The terminal device can provide the user interface to the user in various ways, such as rendering it on the terminal device's display screen or presenting the user interface through holographic projection. For example, the terminal device can include a touch screen and a processor. The touch screen is used to present the user interface and receive operation commands generated by the user on the user interface, which includes a code writing interface. The processor is used to run the Lua code writing application, generate the user interface, respond to operation commands, and control the display of the user interface on the touch screen.
[0088] Please see Figure 1 , Figure 1 This is a system schematic diagram of an object access device provided in an embodiment of this application. The system may include at least one terminal. The terminal is used to obtain the target Lua code file in response to a parsing trigger operation for a target Lua code file in a Lua runtime environment. The target Lua code file includes object access code in Lua language. The object access code is generated based on Unity preset body code and includes an object identifier and a data lookup identifier for a specific Unity object that needs to be accessed in the Lua runtime environment. The data lookup identifier is used to obtain object data of the specific Unity object. The terminal parses the object access code in the target Lua code file and displays an object identifier selection page on the user interface based on the parsing result. The object identifier selection page includes the object identifier of the specific Unity object. In response to a selection operation for an object identifier on the object identifier selection page, the terminal accesses the specific Unity object corresponding to the selected object identifier based on the data lookup identifier.
[0089] The following sections provide detailed descriptions of each example. It should be noted that the order in which the embodiments are described is not intended to limit the preferred order of the embodiments.
[0090] This embodiment will be described from the perspective of an object access device, which can be integrated into a terminal device, such as a smartphone, laptop, tablet, or personal computer.
[0091] This application provides an object access method, which can be executed by a terminal's processor, such as... Figure 2 As shown, the specific flow of this object access method mainly includes steps 201 to 203, which are explained in detail below:
[0092] Step 201: In response to the parsing trigger operation of the target Lua code file in the Lua runtime environment, obtain the target Lua code file. The target Lua code file includes object access code in Lua language. The object access code is generated based on the Unity preset code and includes the object identifier and data lookup identifier of the specific Unity object that needs to be accessed in the Lua runtime environment. The data lookup identifier is used to obtain the object data of the specific Unity object.
[0093] In this embodiment of the application, a specific Unity object is a Unity object created in the Unity runtime environment that needs to be accessed by the user in the Lua runtime environment. The Unity object is the basic object in the Unity runtime environment, representing anything that can exist in the game scene, such as characters, props, and scenery in the game scene.
[0094] In this embodiment, a Unity preset is a Unity object that can be reused in a game scene. A Unity preset can be a single Unity object, such as a wall model or a tree model. It can also be formed by combining multiple related Unity objects, such as a building model composed of multiple wall models, roof models, window models, door models, etc. When a Unity preset is composed of multiple related Unity objects, these objects can be combined in a tree structure, with the Unity preset as the root node and the related Unity objects as the child nodes corresponding to the root node. For example, the building model is the root node, and the wall models, roof models, window models, door models, etc., are the child nodes included in the root node. Furthermore, Unity presets and Unity objects can be obtained by writing code within the Unity runtime environment.
[0095] In this embodiment of the application, the object access code is code used to access Unity objects in the Lua runtime environment. Since the object access code is used in the Lua runtime environment, the object access code can be in the Lua language.
[0096] In this embodiment, when a user wants to access a specific Unity object in the Lua runtime environment, a parsing trigger operation can be performed on the target Lua code file storing the object access code, thereby triggering the terminal to parse the object access code in the target Lua code file. Furthermore, the parsing trigger operation is not limited and can be flexibly set according to actual conditions. For example, the user can input the characters that trigger the terminal to parse the target Lua code file in the user interface of the Lua runtime environment. That is, if the target Lua code file is an ExampleWrap file, the user's parsing trigger operation can be to input `local uiwrap = require('UI.ExampleWrap').nue(rootGo)` in the Lua runtime environment, where `rootGo` is the game object instantiated from the preset body to which the specific Unity object belongs, and `uiwrap` represents the table constructed based on the property access functions of the specific Unity object.
[0097] Step 202: Parse the object access code in the target Lua code file, and display the object identifier selection page on the user interface based on the parsing results. The object identifier selection page includes the object identifier of a specific Unity object.
[0098] In this embodiment, since object access code is code that can access specific Unity objects, parsing the object access code displays an object identifier selection page on the user interface, thereby providing the user with code completion and prompts when accessing Unity objects. For example, such as Figure 3 The diagram shown illustrates the object identifier selection page. When the user enters `localuiwrap = require('UI.ExampleWrap').nue(rootGo)`, the terminal parses the object access code in the `ExampleWrap` file and generates an object identifier selection page 301 in the form of a list. The object identifier selection page 301 displays the object identifiers of different specific Unity objects.
[0099] Step 203: In response to the selection operation of the object identifier on the object identifier selection page, access the specific Unity object corresponding to the selected object identifier based on the data lookup identifier.
[0100] In this embodiment, the user can select the object identifier of the Unity object they wish to access on the object selection page. Specifically, the selection operation can be clicking the desired object identifier. After selecting the object identifier, the corresponding data lookup identifier can be determined, thereby retrieving the object data of the specific Unity object to be accessed based on the determined data lookup identifier, thus realizing access to the selected specific Unity object.
[0101] In this embodiment of the application, a specific Unity object includes mounted components. The mounted components define the behavior of the corresponding specific Unity object. The mounted components include Unity's built-in components such as light sources, models, and animations, as well as custom components added by developers through C# code.
[0102] In this embodiment, accessing a specific Unity object can be accessing the mounted components of that specific Unity object. That is, the object access code can include object body access code and component access code for each mounted component of a specific Unity object. The component access code includes the object identifier of the specific Unity object and the component identifier of the mounted component. The object data includes the component identifier and component data of the mounted component. The object body access code can be code for querying and caching the object data of a specific Unity object. The component access code is used to access the mounted components of a specific Unity object. Since there can be multiple mounted components for a Unity object, each mounted component has a component identifier to distinguish each component.
[0103] Specifically, when accessing the mounted component of a specific Unity object, step 203 above, "in response to the selection operation of the object identifier on the object identifier selection page, access the specific Unity object corresponding to the selected object identifier based on data lookup identifier," can be:
[0104] In response to the selection operation of an object identifier on the object identifier selection page, determine the specific Unity object corresponding to the selected object identifier, which is the target Unity object to be accessed;
[0105] Based on the parsing results, a component identifier selection page is displayed on the user interface. The component identifier selection page includes the target component identifier of the target Unity object's target mounted component.
[0106] In response to the selection operation of the target component identifier on the component identifier selection page, the target mounted component corresponding to the selected target component identifier is accessed based on the data lookup identifier of the target Unity object.
[0107] For example, such as Figure 4In the schematic diagram of the component identifier selection page shown, after the user selects the object identifier of the target Unity object to be accessed on the object identifier selection page, a component identifier selection page 401 is generated in the form of a list. The component identifier selection page 401 displays the target component identifiers of the mounted components corresponding to the target Unity object, so that the user can select the specific target mounted component to be accessed. The user can find the object data of the target Unity object by searching for the identifier based on the data of the target Unity object, and then retrieve the component data corresponding to the selected target component identifier from the object data of the target Unity object.
[0108] All of the above technical solutions can be combined in any way to form optional embodiments of this application, and will not be described in detail here.
[0109] The object access method provided in this application allows a user to access a specific Unity object within a Lua runtime environment. This involves executing a parsing trigger operation to cause the computer device to parse the object access code in the target Lua code file. An object identifier selection page, including the object identifier of the specific Unity object, is then displayed on the user interface. The user can directly select the object identifier of the desired Unity object from this page. Once the computer device determines the data lookup identifier corresponding to that object identifier, it can access the desired Unity object based on the user-selected object identifier and the determined data lookup identifier. This avoids the user manually typing the query path for the desired Unity object within the Lua runtime environment, thus preventing errors and improving the development efficiency of Unity projects.
[0110] This embodiment will be described from the perspective of a code generation device, which can be integrated into a terminal device, such as a smartphone, laptop, tablet, or personal computer.
[0111] This application provides a code generation method for generating object access code used in the aforementioned object access method. This method can be executed by the processor of a terminal, such as... Figure 5 As shown, the specific process of this code generation method mainly includes steps 501 to 506, which are explained in detail below:
[0112] Step 501: Identify the specific Unity object that needs to be accessed in the Lua runtime environment from the Unity objects included in the target Unity preset.
[0113] In this embodiment, to generate object access code that can access specific Unity objects, it is necessary to pre-determine which Unity objects belong to the specific Unity objects that need to be accessed within the target Unity preset body generated in the Unity runtime environment. Specifically, the specific Unity objects can be determined based on the user's visual operations in the Unity runtime environment. The above step 501, "determining the specific Unity objects that need to be accessed in the Lua runtime environment among the Unity objects included in the target Unity preset body," can be:
[0114] Based on the code of the target Unity preset, the settings subpage of the target Unity preset is displayed in the Unity runtime environment. The settings subpage includes the object identifier of the Unity object contained in the target Unity preset, as well as the object settings area;
[0115] When the target object identifier of the Unity object contained in the target Unity preset is selected, in response to the access flag operation in the object setting area corresponding to the target object identifier, the Unity object corresponding to the target object identifier is determined to be a specific Unity object that needs to be accessed in the Lua runtime environment.
[0116] In this embodiment of the application, after the code for the target Unity preset is completed, a settings subpage of the target Unity preset can be displayed in the Unity runtime environment, for example, as shown below. Figure 6 In the schematic diagram of the settings subpage shown, the settings subpage 60 may include an object identifier display area 601 and an object settings area 602. The object identifier display area 601 displays the preset identifier ExampleWrap of the target Unity preset and the object identifiers (close_btn, detail, etc.) of the Unity objects included therein. When a Unity object with the object identifier close_btn is selected in the object identifier display area 601, the object settings area 602 of the Unity object with the object identifier close_btn is displayed, so that access mark operations can be performed in the object settings area 602.
[0117] In this embodiment, the access marker operation can be an operation of adding a tag in the object settings area. Specifically, the above step "when the target object identifier of the Unity object contained in the target Unity preset is selected, in response to the access marker operation in the object settings area corresponding to the target object identifier, determine that the Unity object corresponding to the target object identifier is a specific Unity object that needs to be accessed in the Lua runtime environment" can be:
[0118] When the target object identifier of a Unity object contained in the target Unity preset is selected, the target object setting area of the selected Unity object corresponding to the target object identifier is displayed in the Unity runtime environment. The target object setting area includes the object properties of the selected Unity object.
[0119] In response to the operation of adding a label to the object property of the selected Unity object in the target object settings area, the selected Unity object is determined to be a specific Unity object that needs to be accessed in the Lua runtime environment.
[0120] For example, such as Figure 6 In the schematic diagram of the settings subpage shown, the object settings area 602 of the Unity object with the object identifier close_btn includes the object property Layer. By adding the LuaWrap tag to the object property Layer, it is determined that the Unity object with the object identifier close_btn is a specific Unity object that needs to be accessed in the Lua runtime environment.
[0121] Step 502: Obtain the data lookup identifier of a specific Unity object based on the target Unity preset, record the data lookup identifier in the preset data structure to obtain the object record information, and the position information of the data lookup identifier recorded in the preset data structure is integer data.
[0122] In this embodiment, after a specific Unity object is determined, its data lookup identifier can be obtained from the object data of the target Unity preset body to which it belongs. The data lookup identifiers of each specific Unity object can be recorded. To avoid obtaining the Unity object's data lookup identifier as a string in the Lua runtime environment, thus preventing frequent memory reclamation caused by transferring strings from the Unity runtime environment to the Lua runtime environment, the location information of the data lookup identifier recorded in the preset data structure can be set to integer data, thereby enabling the data lookup identifier to be obtained as an integer in the Lua runtime environment.
[0123] Specifically, since array indices are integers, the preset data structure can be an array structure, with the indices used to identify the position of the data lookup identifier within the array structure. In this case, step 502 above, "obtaining the data lookup identifier of a specific Unity object based on the target Unity preset body, and recording the data lookup identifier in the preset data structure to obtain object record information," can be:
[0124] Retrieve data lookup identifiers for specific Unity objects based on the target Unity preset;
[0125] If there are multiple specific Unity objects, the data lookup identifiers of each specific Unity object are recorded into an array structure in a preset order to obtain the object record information.
[0126] In this embodiment, the preset order can be the order in which each Unity object is determined to be a specific Unity object, that is, the data lookup information corresponding to the Unity object that is determined to be a specific Unity object is added to the array structure first.
[0127] Step 503: Import the target Unity preset and object record information into the Lua runtime environment.
[0128] In this embodiment of the application, after the above step "obtaining the data lookup identifier of a specific Unity object based on the target Unity preset and recording the data lookup identifier in a preset data structure to obtain object record information", it further includes: attaching an access record component to the target Unity preset; storing the object record information in the access record component; at this time, step 503 "importing the target Unity preset and object record information into the Lua runtime environment" can be: in response to the import operation of the object data and access record component of the target Unity preset from the Unity runtime environment to the Lua runtime environment, importing the target Unity preset and object record information into the Lua runtime environment.
[0129] In one embodiment of this application, attaching an access record component to the target Unity preset can be achieved by the terminal automatically attaching the access record component to the target Unity preset in response to a code generation trigger operation in the Unity runtime environment. That is, the terminal iterates through each Unity object of the target Unity preset, recording the data lookup identifier of the Unity object with the Layer attribute set to LuaWrap in a preset data structure to form object record information, for example, such as... Figure 7 As shown. Object record information is stored in the access record component. Furthermore, the access record component can be persistently saved along with the target Unity preset.
[0130] In this embodiment of the application, the import operation is unrestricted and can be a user manually importing a file containing the object data of the target Unity preset and a file containing the access record component into the Lua runtime environment.
[0131] Step 504: Obtain the object access code template in the Lua runtime environment. The object access code template is used to access Unity objects in the Lua runtime environment and includes several code segments to be replaced associated with a specific Unity object.
[0132] In this embodiment, an object access code template is pre-generated in the Lua runtime environment. When the user wants to generate object access code, they can perform a code template retrieval operation in the Lua runtime environment, thereby enabling the terminal to obtain the object access code template. For example, the object access code template can be:
[0133]
[0134] in, <luaobj> , <upvaluegodefine>and <nodedefine>It can be the code segment to be replaced.
[0135] Step 505: Based on the object identifier of a specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, replace the code in the code segment to be replaced in the object access code template to obtain the object access code. The object access code includes the object identifier and data lookup identifier of the specific Unity object.
[0136] In this embodiment of the application, step 505 above, "based on the object identifier of a specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, performing code replacement in the code segment to be replaced in the object access code template to obtain the object access code," can be:
[0137] Based on the object identifier of a specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, generate the target replacement code segment corresponding to each code segment to be replaced;
[0138] Replace the corresponding code segment to be replaced in the object access code template with the code segment to be replaced for each target to obtain the object access code.
[0139] In this embodiment of the application, the code segment to be replaced includes a code segment to be replaced identifier, a code segment to be replaced object body access, and a code segment to be replaced component access. In this case, the above step "generating the target replacement code segment corresponding to each code segment to be replaced based on the object identifier of a specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset body" can be:
[0140] Obtain the preset identifier of the target Unity preset from the object data of the target Unity preset, and use it as the target replacement code segment corresponding to the code segment to be replaced;
[0141] Based on the data lookup identifier in the object record information and the object data of the target Unity preset, a code segment is generated to query and cache a specific Unity object, which serves as the target replacement code segment corresponding to the object body access code segment to be replaced;
[0142] Based on the target replacement code segment corresponding to the access code segment of the object to be replaced and the object identifier of the specific Unity object, the target replacement code segment corresponding to the access code segment of the component to be replaced is generated.
[0143] For example, such as Figure 8 In the schematic diagram of the replacement process shown, <luaobj>The content will be replaced with the root node name of the preset body, that is, the name of the preset body in the preset body data, which is mainly used to identify the generated Lua code. <upvaluegodefine>The content is replaced by Lua code that queries and caches Unity objects based on the access record component (cmpcache). <nodedefine>The content is replaced with the component access code based on the component's Lua template table.
[0144] In this embodiment of the application, when the preset data structure in the object record information is an array structure, the above step "generating a code segment for querying and caching a specific Unity object based on the data lookup identifier in the object record information and the object data of the target Unity preset body, as the target replacement code segment corresponding to the object body access code segment to be replaced" can be:
[0145] Determine the index of the data lookup identifier record for each specific Unity object in the array structure;
[0146] Generate the first code segment that identifies a specific Unity object in an array structure based on its index;
[0147] Based on the determined data lookup identifier, generate a second code segment that queries and caches the object data of a specific Unity object in the object data of the target Unity preset;
[0148] The first and second code segments are merged into the target replacement code segment corresponding to the object body access code segment to be replaced.
[0149] For example, the first code segment could be:
[0150] local cmpcache=rootGo:GetComponent(typeof(CS.CmpCache))
[0151] local closeBtnGo=cmpcache.GetCache(0)
[0152] Specifically, the Unity object in the CmpCache array is retrieved by array index, which replaces the use of a lookup path to find the Unity object. Integer variables are passed between Lua and C# instead of string variables, avoiding memory reclamation in the Lua runtime environment.
[0153] In this embodiment of the application, the above step "generating the target replacement code segment corresponding to the access code segment of the component to be replaced based on the target replacement code segment corresponding to the access code segment of the object to be replaced and the object identifier of the specific Unity object" can be:
[0154] The first code segment is used to retrieve the data lookup identifier for a specific Unity object.
[0155] Based on the object data of a specific Unity object cached in the second code segment, obtain the component identifier of the mounted component of the specific Unity object;
[0156] Generate the target replacement code segment corresponding to the access code segment of the component to be replaced based on the object identifier, data lookup identifier, and component identifier of a specific Unity object.
[0157] For example, such as Figure 9 The diagram shows a template code representation of the component access code segment to be replaced. Based on the object identifier, data lookup identifier, and component identifier of a specific Unity object, the template code is replaced to generate the target replacement code segment corresponding to the component access code segment. Specifically, <name>The identifier is replaced by the Unity object name (the object identifier of the Unity object). <upvaluegodefine>The generated Lua code contains data lookup identifiers needed for querying and caching Unity objects. These Unity object variable names (i.e., data lookup identifiers) will eventually be replaced. <gameobject>Logo, <cmptype>The identifier will be replaced by the component type name (i.e., the component identifier) of the Unity object.
[0158] In this embodiment of the application, if a specific Unity object has multiple mounted components, the above step "generating the target replacement code segment corresponding to the access code segment of the component to be replaced based on the object identifier, data lookup identifier, and component identifier of the specific Unity object" can be:
[0159] If a specific Unity object has multiple mounted components, a code segment for accessing each mounted component is generated based on the object identifier of the specific Unity object, the data lookup identifier, and the component identifier of each mounted component.
[0160] The code segments that access each mounted component are concatenated to generate the target replacement code segment corresponding to the code segment accessing the component to be replaced.
[0161] In this embodiment of the application, the above step "replacing the corresponding code segment to be replaced in the object access code template with each target replacement code segment to obtain the object access code" can be:
[0162] Replace the corresponding identifier code segment, object body access code segment, and component access code segment in the object access code template with the target replacement code segments to obtain object access code including identifier code segment, object body access code segment, and component access code segment.
[0163] Step 506: Obtain the target Lua code file based on the object access code. The target Lua code file is used to display the object identifier of a specific Unity object after being parsed for the user to select, and to access the specific Unity object corresponding to the selected object identifier based on the data lookup identifier after selection.
[0164] The code generation method provided in this application allows a computer device to parse the object access code in a target Lua code file when a user wants to access a specific Unity object in the Lua runtime environment. The parsing trigger operation displays an object identifier selection page on the user interface, including the object identifier of the specific Unity object. The user can directly select the object identifier of the desired Unity object on this page. Once the computer device determines the data lookup identifier of the specific Unity object corresponding to that object identifier, it can access the desired Unity object based on the user-selected object identifier and the determined data lookup identifier. This avoids the user manually typing the query path for the desired Unity object in the Lua runtime environment, thus preventing errors caused by manually typing the query path and improving the development efficiency of Unity projects.
[0165] To facilitate better implementation of the object access method of this application, this application also provides an object access apparatus. Please refer to... Figure 10 , Figure 10 This is a schematic diagram of the structure of an object access device provided in an embodiment of this application. The object access device may include a code file acquisition unit 1001, an identification display unit 1002, and an access unit 1003.
[0166] The code file acquisition unit 1001 is used to respond to the parsing trigger operation of the target Lua code file in the Lua runtime environment and acquire the target Lua code file. The target Lua code file includes object access code in Lua language. The object access code is generated based on the Unity preset body code and includes the object identifier and data lookup identifier of a specific Unity object that needs to be accessed in the Lua runtime environment. The data lookup identifier is used to obtain the object data of the specific Unity object.
[0167] The identifier display unit 1002 is used to parse the object access code in the target Lua code file and display the object identifier selection page on the user interface based on the parsing result. The object identifier selection page includes the object identifier of a specific Unity object.
[0168] Access unit 1003 is used to respond to the selection operation of object identifier in the object identifier selection page, and access the specific Unity object corresponding to the selected object identifier based on data lookup identifier.
[0169] Optionally, the object access code includes the object body access code and the component access code of the mounted component for each specific Unity object. The component access code includes the object identifier of the specific Unity object and the component identifier of the mounted component. The object data includes the component identifier and component data of the mounted component.
[0170] Access unit 1003 is also used for:
[0171] In response to the selection operation of an object identifier on the object identifier selection page, determine the specific Unity object corresponding to the selected object identifier, which is the target Unity object to be accessed;
[0172] Based on the parsing results, a component identifier selection page is displayed on the user interface. The component identifier selection page includes the target component identifier of the target Unity object's target mounted component.
[0173] In response to the selection operation of the target component identifier on the component identifier selection page, the target mounted component corresponding to the selected target component identifier is accessed based on the data lookup identifier of the target Unity object.
[0174] All of the above technical solutions can be combined in any way to form optional embodiments of this application, and will not be described in detail here.
[0175] To facilitate better implementation of the code generation method of this application, this application also provides a code generation apparatus. Please refer to... Figure 11 , Figure 11 This is a schematic diagram of the structure of a code generation apparatus provided in an embodiment of this application. The code generation apparatus may include an object determination unit 1101, a recording unit 1102, an import unit 1103, a code template acquisition unit 1104, a replacement unit 1105, and a code file acquisition unit 1106.
[0176] Among them, the object determination unit 1101 is used to determine the specific Unity object that needs to be accessed in the Lua runtime environment from the Unity objects included in the target Unity preset body;
[0177] Recording unit 1102 is used to obtain the data lookup identifier of a specific Unity object based on the target Unity preset body, record the data lookup identifier in a preset data structure to obtain object record information, and the position information of the data lookup identifier recorded in the preset data structure is integer data;
[0178] Import unit 1103 is used to import the target Unity preset and object record information into the Lua runtime environment;
[0179] The code template acquisition unit 1104 is used to acquire object access code templates in the Lua runtime environment. The object access code templates are used to access Unity objects in the Lua runtime environment and include several code segments to be replaced associated with a specific Unity object.
[0180] The replacement unit 1105 is used to replace the code in the code segment to be replaced in the object access code template based on the object identifier of a specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset body, to obtain the object access code. The object access code includes the object identifier and data lookup identifier of the specific Unity object.
[0181] The code file obtains unit 1106, which is used to obtain the target Lua code file based on object access code. The target Lua code file is used to display the object identifier of a specific Unity object for the user to select after being parsed, and to access the specific Unity object corresponding to the selected object identifier based on data lookup identifier after selection.
[0182] Optionally, the object determination unit 1101 is also used for:
[0183] Based on the code of the target Unity preset, the settings subpage of the target Unity preset is displayed in the Unity runtime environment. The settings subpage includes the object identifier of the Unity object contained in the target Unity preset, as well as the object settings area;
[0184] When the target object identifier of the Unity object contained in the target Unity preset is selected, in response to the access flag operation in the object setting area corresponding to the target object identifier, the Unity object corresponding to the target object identifier is determined to be a specific Unity object that needs to be accessed in the Lua runtime environment.
[0185] Optionally, the object determination unit 1101 is also used for:
[0186] When the target object identifier of the Unity object contained in the target Unity preset is selected, the target object setting area of the selected Unity object corresponding to the target object identifier is displayed in the Unity runtime environment. The target object setting area includes the object properties of the selected Unity object.
[0187] In response to the operation of adding a label to the object property of the selected Unity object in the target object settings area, the selected Unity object is determined to be a specific Unity object that needs to be accessed in the Lua runtime environment.
[0188] Optionally, the default data structure is an array structure, and record unit 1102 is also used for:
[0189] Retrieve data lookup identifiers for specific Unity objects based on the target Unity preset;
[0190] If there are multiple specific Unity objects, the data lookup identifiers of each specific Unity object are recorded into an array structure in a preset order to obtain the object record information.
[0191] Optionally, the recording unit 1102 is also used for:
[0192] Attach the access log component to the target Unity preset;
[0193] Store object record information in the access record component;
[0194] The import unit 1103 is also used for:
[0195] In response to an import operation of object data and access history components for a target Unity preset from the Unity runtime environment to the Lua runtime environment, the target Unity preset and object record information are imported into the Lua runtime environment.
[0196] Optionally, replacement unit 1105 is also used for:
[0197] Based on the object identifier of a specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, generate the target replacement code segment corresponding to each code segment to be replaced;
[0198] Replace the corresponding code segment to be replaced in the object access code template with the code segment to be replaced for each target to obtain the object access code.
[0199] Optionally, the code segment to be replaced includes a code segment for identifying the identifier to be replaced, a code segment for accessing the object itself to be replaced, and a code segment for accessing the component to be replaced. The replacement unit 1105 is also used for:
[0200] Obtain the preset identifier of the target Unity preset from the object data of the target Unity preset, and use it as the target replacement code segment corresponding to the code segment to be replaced;
[0201] Based on the data lookup identifier in the object record information and the object data of the target Unity preset, a code segment is generated to query and cache a specific Unity object, which serves as the target replacement code segment corresponding to the object body access code segment to be replaced;
[0202] Based on the target replacement code segment corresponding to the access code segment of the object to be replaced and the object identifier of the specific Unity object, the target replacement code segment corresponding to the access code segment of the component to be replaced is generated.
[0203] Optionally, the preset data structure in the object record information is an array structure, and the replacement unit 1105 is also used for:
[0204] Determine the index of the data lookup identifier record for each specific Unity object in the array structure;
[0205] Generate the first code segment that identifies a specific Unity object in an array structure based on its index;
[0206] Based on the determined data lookup identifier, generate a second code segment that queries and caches the object data of a specific Unity object in the object data of the target Unity preset;
[0207] The first and second code segments are merged into the target replacement code segment corresponding to the object body access code segment to be replaced.
[0208] Optionally, replacement unit 1105 is also used for:
[0209] The first code segment is used to retrieve the data lookup identifier for a specific Unity object.
[0210] Based on the object data of a specific Unity object cached in the second code segment, obtain the component identifier of the mounted component of the specific Unity object;
[0211] Generate the target replacement code segment corresponding to the access code segment of the component to be replaced based on the object identifier, data lookup identifier, and component identifier of a specific Unity object.
[0212] Optionally, replacement unit 1105 is also used for:
[0213] If a specific Unity object has multiple mounted components, a code segment for accessing each mounted component is generated based on the object identifier of the specific Unity object, the data lookup identifier, and the component identifier of each mounted component.
[0214] The code segments that access each mounted component are concatenated to generate the target replacement code segment corresponding to the code segment accessing the component to be replaced.
[0215] Optionally, replacement unit 1105 is also used for:
[0216] Replace the corresponding identifier code segment, object body access code segment, and component access code segment in the object access code template with the target replacement code segments to obtain object access code including identifier code segment, object body access code segment, and component access code segment.
[0217] The object access method, code generation method, apparatus, device, and storage medium provided in this application embodiment can, when a user wants to access a specific Unity object in the Lua runtime environment, execute a parsing trigger operation to cause the computer device to parse the object access code in the target Lua code file. An object identifier selection page, including the object identifier of the specific Unity object, is displayed on the user interface. The user can directly select the object identifier of the specific Unity object to be accessed on the object identifier selection page. After the computer device determines the data lookup identifier of the specific Unity object corresponding to the object identifier, the computer device can access the specific Unity object to be accessed based on the object identifier selected by the user and the determined data lookup identifier. This avoids the user manually typing the query path of the desired Unity object in the Lua runtime environment, thereby preventing errors caused by manually typing the query path of the Unity object in the Lua runtime environment and improving the development efficiency of Unity projects.
[0218] Accordingly, this application also provides a computer device, which can be a terminal, such as a smartphone, tablet computer, laptop computer, touch screen, game console, personal computer, personal digital assistant, etc. Figure 12 As shown, Figure 12 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. The computer device 1200 includes a processor 1201 with one or more processing cores, a memory 1202 with one or more computer-readable storage media, and a computer program stored on the memory 1202 and executable on the processor. The processor 1201 and the memory 1202 are electrically connected. Those skilled in the art will understand that the computer device structure shown in the figure does not constitute a limitation on the computer device, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0219] The processor 1201 is the control center of the computer device 1200. It connects various parts of the computer device 1200 through various interfaces and lines. By running or loading software programs and / or modules stored in the memory 1202, and calling data stored in the memory 1202, it performs various functions of the computer device 1200 and processes data, thereby monitoring the computer device 1200 as a whole.
[0220] In this embodiment, the processor 1201 in the computer device 1200 loads the instructions corresponding to the processes of one or more applications into the memory 1202 according to the following steps, and the processor 1201 runs the applications stored in the memory 1202 to realize various functions:
[0221] In response to the parsing trigger operation of the target Lua code file in the Lua runtime environment, the target Lua code file is obtained. The target Lua code file includes object access code in Lua language. The object access code is generated based on the Unity preset code and includes the object identifier and data lookup identifier of the specific Unity object that needs to be accessed in the Lua runtime environment. The data lookup identifier is used to obtain the object data of the specific Unity object.
[0222] Parse the object access code in the target Lua code file, and display the object identifier selection page in the user interface based on the parsing results. The object identifier selection page includes the object identifier of a specific Unity object.
[0223] In response to the selection of an object identifier on the object identifier selection page, access the specific Unity object corresponding to the selected object identifier based on data lookup identifier.
[0224] Identify the specific Unity objects that need to be accessed in the Lua runtime environment from among the Unity objects included in the target Unity preset;
[0225] Based on the target Unity preset, obtain the data lookup identifier of a specific Unity object, record the data lookup identifier in the preset data structure to obtain the object record information, and the position information of the data lookup identifier recorded in the preset data structure is integer data;
[0226] Import the target Unity preset and object record information into the Lua runtime environment;
[0227] Obtain object access code templates in the Lua runtime environment. These templates are used to access Unity objects in the Lua runtime environment and include several code segments to be replaced that are associated with a specific Unity object.
[0228] Based on the object identifier of a specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, the code is replaced in the code segment to be replaced in the object access code template to obtain the object access code. The object access code includes the object identifier and data lookup identifier of the specific Unity object.
[0229] The target Lua code file is obtained based on the object access code. After being parsed, the target Lua code file is used to display the object identifier of a specific Unity object for the user to select. After selection, the specific Unity object corresponding to the selected object identifier is accessed based on the data lookup identifier.
[0230] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0231] Optional, such as Figure 12 As shown, the computer device 1200 also includes: a touch screen display 1203, a radio frequency circuit 1204, an audio circuit 1205, an input unit 1206, and a power supply 1207. The processor 1201 is electrically connected to the touch screen display 1203, the radio frequency circuit 1204, the audio circuit 1205, the input unit 1206, and the power supply 1207. Those skilled in the art will understand that... Figure 12 The computer device structure shown does not constitute a limitation on the computer device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0232] The touch display screen 1203 can be used to display a graphical user interface (GUI) and receive operation commands generated by the user interacting with the GUI. The touch display screen 1203 may include a display panel and a touch panel. The display panel can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces of the computer device. These graphical user interfaces can be composed of graphics, text, icons, video, and any combination thereof. Optionally, the display panel can be configured using a liquid crystal display (LCD), organic light-emitting diode (OLED), or other similar technologies. The touch panel can be used to collect touch operations performed by the user on or near it (such as the user's finger, stylus, or any suitable object or accessory on or near the touch panel), generate corresponding operation commands, and execute the corresponding program according to the operation commands. Optionally, the touch panel may include a touch detection device and a touch controller. The touch detection device detects the user's touch location and the signal generated by the touch operation, transmitting the signal to the touch controller. The touch controller receives touch information from the touch detection device, converts it into touch point coordinates, and sends it to the processor 1201. It can also receive and execute commands from the processor 1201. The touch panel can cover the display panel. When the touch panel detects a touch operation on or near it, it transmits the information to the processor 1201 to determine the type of touch event. Subsequently, the processor 1201 provides corresponding visual output on the display panel based on the type of touch event. In this embodiment, the touch panel and the display panel can be integrated into the touch display screen 1203 to achieve input and output functions. However, in some embodiments, the touch panel and the touch display screen 1203 can be implemented as two independent components to achieve input and output functions. That is, the touch display screen 1203 can also be used as part of the input unit 1206 to achieve input functions.
[0233] The radio frequency circuit 1204 can be used to transmit and receive radio frequency signals to establish wireless communication with network devices or other computer devices, and to transmit and receive signals with network devices or other computer devices.
[0234] Audio circuit 1205 can be used to provide an audio interface between a user and a computer device via a speaker and a microphone. Audio circuit 1205 can convert received audio data into electrical signals and transmit them to the speaker, where the speaker converts them into sound signals for output. Conversely, the microphone converts collected sound signals into electrical signals, which are then received by audio circuit 1205, converted back into audio data, and then processed by processor 1201 before being transmitted via radio frequency circuit 1204 to, for example, another computer device, or output to memory 1202 for further processing. Audio circuit 1205 may also include an earphone jack to provide communication between peripheral headphones and the computer device.
[0235] The input unit 1206 can be used to receive input numbers, characters, or user characteristic information (such as fingerprints, iris, facial information, etc.), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control.
[0236] Power supply 1207 is used to supply power to various components of computer device 1200. Optionally, power supply 1207 can be logically connected to processor 1201 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Power supply 1207 may also include one or more DC or AC power supplies, recharging systems, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components.
[0237] although Figure 12 As not shown in the diagram, the computer device 1200 may also include a camera, sensor, wireless fidelity module, Bluetooth module, etc., which will not be described in detail here.
[0238] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0239] As can be seen from the above, the computer device provided in this embodiment can execute a parsing trigger operation when a user wants to access a specific Unity object in the Lua runtime environment. This causes the computer device to parse the object access code in the target Lua code file and display an object identifier selection page on the user interface, which includes the object identifier of the specific Unity object. The user can directly select the object identifier of the specific Unity object they want to access on the object identifier selection page. After the computer device determines the data lookup identifier of the specific Unity object corresponding to the object identifier, the computer device can access the specific Unity object they want to access based on the object identifier selected by the user and the determined data lookup identifier. This avoids the user manually typing the query path of the Unity object they want to access in the Lua runtime environment, thereby avoiding errors caused by manually typing the query path of the Unity object in the Lua runtime environment and improving the development efficiency of Unity projects.
[0240] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be performed by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0241] Therefore, embodiments of this application provide a computer-readable storage medium storing multiple computer programs that can be loaded by a processor to execute steps in any of the object access methods and code generation methods provided in embodiments of this application. For example, the computer program can execute the following steps:
[0242] In response to the parsing trigger operation of the target Lua code file in the Lua runtime environment, the target Lua code file is obtained. The target Lua code file includes object access code in Lua language. The object access code is generated based on the Unity preset code and includes the object identifier and data lookup identifier of the specific Unity object that needs to be accessed in the Lua runtime environment. The data lookup identifier is used to obtain the object data of the specific Unity object.
[0243] Parse the object access code in the target Lua code file, and display the object identifier selection page in the user interface based on the parsing results. The object identifier selection page includes the object identifier of a specific Unity object.
[0244] In response to the selection of an object identifier on the object identifier selection page, access the specific Unity object corresponding to the selected object identifier based on data lookup identifier.
[0245] Identify the specific Unity objects that need to be accessed in the Lua runtime environment from among the Unity objects included in the target Unity preset;
[0246] Based on the target Unity preset, obtain the data lookup identifier of a specific Unity object, record the data lookup identifier in the preset data structure to obtain the object record information, and the position information of the data lookup identifier recorded in the preset data structure is integer data;
[0247] Import the target Unity preset and object record information into the Lua runtime environment;
[0248] Obtain object access code templates in the Lua runtime environment. These templates are used to access Unity objects in the Lua runtime environment and include several code segments to be replaced that are associated with a specific Unity object.
[0249] Based on the object identifier of a specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, the code is replaced in the code segment to be replaced in the object access code template to obtain the object access code. The object access code includes the object identifier and data lookup identifier of the specific Unity object.
[0250] The target Lua code file is obtained based on the object access code. After being parsed, the target Lua code file is used to display the object identifier of a specific Unity object for the user to select. After selection, the specific Unity object corresponding to the selected object identifier is accessed based on the data lookup identifier.
[0251] For details on the implementation of each of the above operations, please refer to the previous examples, which will not be repeated here.
[0252] The storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0253] Since the computer program stored in the storage medium can execute the steps of any of the object access methods and code generation methods provided in the embodiments of this application, it can achieve the beneficial effects that any of the object access methods and code generation methods provided in the embodiments of this application can achieve. For details, please refer to the previous embodiments, which will not be repeated here.
[0254] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0255] The foregoing has provided a detailed description of an object access method, code generation method, apparatus, device, and storage medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the technical solutions and core ideas of the present invention. Those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. These modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.< / cmptype> < / gameobject> < / upvaluegodefine> < / name> < / nodedefine> < / upvaluegodefine> < / luaobj> < / nodedefine> < / upvaluegodefine> < / luaobj>
Claims
1. An object access method, characterized in that, include: In response to a parsing trigger operation for a target Lua code file in a Lua runtime environment, the target Lua code file is obtained. The target Lua code file includes object access code in Lua language. The object access code is generated based on Unity preset code and includes an object identifier and a data lookup identifier for a specific Unity object that needs to be accessed in the Lua runtime environment. The data lookup identifier is used to obtain the object data of the specific Unity object. Parse the object access code in the target Lua code file, and display an object identifier selection page on the user interface based on the parsing results. The object identifier selection page includes the object identifier of the specific Unity object. In response to the selection operation of the object identifier in the object identifier selection page, the specific Unity object corresponding to the selected object identifier is accessed based on the data lookup identifier.
2. The method according to claim 1, characterized in that, The object access code includes object body access code and component access code for each specific Unity object's mounted component. The component access code includes the object identifier of the specific Unity object and the component identifier of the mounted component. The object data includes the component identifier and component data of the mounted component. The step of responding to a selection operation of an object identifier on the object identifier selection page, and accessing the specific Unity object corresponding to the selected object identifier based on the data lookup identifier, includes: In response to the selection operation of the object identifier in the object identifier selection page, the specific Unity object corresponding to the selected object identifier is determined as the target Unity object to be accessed; Based on the parsing results, a component identifier selection page is displayed on the user interface. The component identifier selection page includes the target component identifier of the target mounted component of the target Unity object. In response to the selection operation of the target component identifier in the component identifier selection page, the target mounted component corresponding to the selected target component identifier is accessed based on the data lookup identifier of the target Unity object.
3. A code generation method, characterized in that, include: Identify the specific Unity objects that need to be accessed in the Lua runtime environment from among the Unity objects included in the target Unity preset; Based on the target Unity preset, obtain the data lookup identifier of the specific Unity object, record the data lookup identifier in a preset data structure to obtain object record information, and the position information of the data lookup identifier recorded in the preset data structure is integer data; Import the target Unity preset and the object record information into the Lua runtime environment; Obtain a Lua language object access code template in the Lua runtime environment. The object access code template is used to access Unity objects in the Lua runtime environment, and the object access code template includes several code segments to be replaced associated with the specific Unity object. Based on the object identifier of the specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, code replacement is performed in the code segment to be replaced in the object access code template to obtain object access code, wherein the object access code includes the object identifier and data lookup identifier of the specific Unity object; The target Lua code file is obtained based on the object access code. The target Lua code file is used to display the object identifier of the specific Unity object after being parsed for the user to select, and after selection, to access the specific Unity object corresponding to the selected object identifier based on the data lookup identifier.
4. The method according to claim 3, characterized in that, The specific Unity objects that need to be accessed in the Lua runtime environment, among the Unity objects included in the determined target Unity preset, include: Based on the code of the target Unity preset, the settings subpage of the target Unity preset is displayed in the Unity runtime environment. The settings subpage includes the object identifier of the Unity object contained in the target Unity preset, and the object settings area. When the target object identifier of the Unity object contained in the target Unity preset is selected, in response to the access flag operation in the object setting area corresponding to the target object identifier, the Unity object corresponding to the target object identifier is determined to be the specific Unity object that needs to be accessed in the Lua runtime environment.
5. The method according to claim 4, characterized in that, When the target object identifier of the Unity object contained in the target Unity preset is selected, in response to the access flag operation in the object setting area corresponding to the target object identifier, the Unity object corresponding to the target object identifier is determined to be the specific Unity object that needs to be accessed in the Lua runtime environment, including: When the target object identifier of the Unity object contained in the target Unity preset is selected, the target object setting area of the selected Unity object corresponding to the target object identifier is displayed in the Unity runtime environment. The target object setting area includes the object properties of the selected Unity object. In response to the operation of adding a label to the object property of the selected Unity object in the target object settings area, the selected Unity object is determined to be the specific Unity object that needs to be accessed in the Lua runtime environment.
6. The method according to claim 3, characterized in that, The preset data structure is an array structure. The step of obtaining the data lookup identifier of the specific Unity object based on the target Unity preset, and recording the data lookup identifier in the preset data structure to obtain object record information includes: Based on the target Unity preset, obtain the data lookup identifier of the specific Unity object; If there are multiple specific Unity objects, the data lookup identifiers of each specific Unity object are recorded sequentially into the array structure according to a preset order to obtain the object record information.
7. The method according to claim 3, characterized in that, After obtaining the data lookup identifier of the specific Unity object based on the target Unity preset and recording the data lookup identifier in a preset data structure to obtain the object record information, the method further includes: Mount the access log component to the target Unity preset; The object record information is stored in the access record component; The step of importing the target Unity preset and the object record information into the Lua runtime environment includes: In response to the import operation of the object data of the target Unity preset and the access record component from the Unity runtime environment to the Lua runtime environment, the target Unity preset and the object record information are imported into the Lua runtime environment.
8. The method according to claim 3, characterized in that, The object access code is obtained by replacing the object identifier of the specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset in the code segment to be replaced in the object access code template, including: Based on the object identifier of the specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, generate the target replacement code segment corresponding to each of the code segments to be replaced; The object access code is obtained by replacing the corresponding code segment to be replaced in the object access code template with each of the target replacement code segments.
9. The method according to claim 8, characterized in that, The code segment to be replaced includes a code segment for identifying the object to be replaced, a code segment for accessing the object itself to be replaced, and a code segment for accessing the component to be replaced. The step of generating the target replacement code segment corresponding to each of the code segments to be replaced based on the object identifier of the specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset includes: Obtain the preset identifier of the target Unity preset from the object data of the target Unity preset, and use it as the target replacement code segment corresponding to the identifier code segment to be replaced; Based on the data lookup identifier in the object record information and the object data of the target Unity preset, a code segment is generated to query and cache the specific Unity object, which serves as the target replacement code segment corresponding to the object body access code segment to be replaced; Based on the target replacement code segment corresponding to the access code segment of the object to be replaced and the object identifier of the specific Unity object, the target replacement code segment corresponding to the access code segment of the component to be replaced is generated.
10. The method according to claim 9, characterized in that, The preset data structure in the object record information is an array structure. The code segment that generates, queries, and caches the specific Unity object based on the data lookup identifier in the object record information and the object data of the target Unity preset body, serves as the target replacement code segment corresponding to the object body access code segment to be replaced, including: Determine the index of the data lookup identifier record for each specific Unity object in the array structure; Generate a first code segment that determines the data lookup identifier of the specific Unity object in the array structure based on the index; Based on the determined data lookup identifier, a second code segment is generated to query and cache the object data of the specific Unity object in the object data of the target Unity preset; The first code segment and the second code segment are merged into the target replacement code segment corresponding to the object body access code segment to be replaced.
11. The method according to claim 10, characterized in that, The step of generating the target replacement code segment corresponding to the access code segment of the component to be replaced based on the target replacement code segment corresponding to the access code segment of the object to be replaced and the object identifier of the specific Unity object includes: The data lookup identifier of the specific Unity object is obtained based on the first code segment; Based on the object data of the specific Unity object cached in the second code segment, obtain the component identifier of the mounted component of the specific Unity object; The target replacement code segment corresponding to the access code segment of the component to be replaced is generated based on the object identifier of the specific Unity object, the data lookup identifier, and the component identifier.
12. The method according to claim 11, characterized in that, The process of generating the target replacement code segment corresponding to the access code segment of the component to be replaced based on the object identifier of the specific Unity object, the data lookup identifier, and the component identifier includes: If a specific Unity object has multiple mounted components, a code segment for accessing each mounted component is generated based on the object identifier of the specific Unity object, the data lookup identifier, and the component identifier of each mounted component. The code segments that access each of the mounted components are concatenated to generate the target replacement code segment corresponding to the code segment accessing the component to be replaced.
13. The method according to claim 9, characterized in that, The step of replacing the corresponding code segment to be replaced in the object access code template with each of the target replacement code segments to obtain the object access code includes: Replace the corresponding identifier code segment, object body access code segment, and component access code segment in the object access code template with the target replacement code segments to obtain object access code including identifier code segment, object body access code segment, and component access code segment.
14. An object access device, characterized in that, include: The code file acquisition unit is used to acquire the target Lua code file in response to a parsing trigger operation for the target Lua code file in the Lua runtime environment. The target Lua code file includes object access code in Lua language. The object access code is generated based on Unity preset code and includes an object identifier and a data lookup identifier for a specific Unity object that needs to be accessed in the Lua runtime environment. The data lookup identifier is used to acquire the object data of the specific Unity object. An identifier display unit is used to parse the object access code in the target Lua code file and display an object identifier selection page on the user interface based on the parsing result. The object identifier selection page includes the object identifier of the specific Unity object. The access unit is used to respond to the selection operation of the object identifier in the object identifier selection page, and access the specific Unity object corresponding to the selected object identifier based on the data lookup identifier.
15. A code generation apparatus, characterized in that, include: The object determination unit is used to determine the specific Unity object that needs to be accessed in the Lua runtime environment from among the Unity objects included in the target Unity preset. The recording unit is used to obtain the data lookup identifier of the specific Unity object based on the target Unity preset body, and record the data lookup identifier in a preset data structure to obtain object record information. The position information of the data lookup identifier recorded in the preset data structure is integer data. The import unit is used to import the target Unity preset and the object record information into the Lua runtime environment. The code template acquisition unit is used to acquire object access code templates in the Lua language under the Lua runtime environment. The object access code templates are used to access Unity objects under the Lua runtime environment, and the object access code templates include several code segments to be replaced associated with the specific Unity object. The replacement unit is used to replace the code in the code segment to be replaced in the object access code template based on the object identifier of the specific Unity object, the data lookup identifier in the object record information, and the object data of the target Unity preset, to obtain object access code, wherein the object access code includes the object identifier and the data lookup identifier of the specific Unity object; The code file obtaining unit is used to obtain a target Lua code file based on the object access code. The target Lua code file is used to display the object identifier of the specific Unity object after being parsed for the user to select, and after selection, to access the specific Unity object corresponding to the selected object identifier based on the data lookup identifier.
16. A computer device, characterized in that, include: Memory, used to store computer programs; A processor for implementing the steps of the object access method and the code generation method as described in any one of claims 1 to 13 when executing the computer program.
17. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the object access method and the code generation method as described in any one of claims 1 to 13.
Citation Information
Patent Citations
Method and device for updating UI controls in game
CN111708563A
Method for generating a binding between a c / c++ library and an interpreted language, and carrying out said method to transform a three-dimensional (3D) model
US20210342135A1