A script-based automated binding method, system and medium for prefabricated objects
Through the prefabricated script automation binding method, the script is automatically generated and bound to nodes in the Cocos prefabricated body, the cumbersome problem of script binding in the existing technology is solved and the development efficiency is improved.
Patent Information
- Application Number
- CN202111607592.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2041-12-27
AI Technical Summary
The existing script binding methods are relatively cumbersome, especially for array variables and node insertion operations, which require a large number of repeated binding operations, which consumes a long time and is very labor-intensive, affecting the development efficiency of games and scripts.
A prefabricated script automation binding method is adopted to automatically generate scripts and bind to nodes in Cocos prefabricated by creating data pairing tables, configuring script templates, and obtaining prefabricated loading. This method includes initial configuration, script generation and script binding steps, and uses the Creator engine's attribute binding and event binding interface to achieve automated script binding.
It realizes automated generation of scripts and binding with prefabricated nodes, reducing script binding and generation time, improving the efficiency of game and script development, avoiding repeated binding operations, and making up for the shortcomings of the existing technology.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of game development, and in particular to a prefabricated body-based script automatic binding method, system and medium. Background Art
[0002] In game development, after the game interface is built, you need to write a script and declare variables in the script, and bind the variables to the nodes in the prefab, so as to control the relevant properties and actions in the game interface through the script code. The existing script binding method has the following problems:
[0003] First, the existing script binding method is relatively cumbersome, and it needs to adopt different binding methods according to the relevant properties of the script variable. For example, when the script variable is an array variable, it is necessary to specify the array length and perform a binding operation on each item in the array, which is time-consuming and labor-intensive.
[0004] Secondly, when modifying the game interface, some nodes need to be re-bound; and when inserting a node into an array, all nodes after the insertion position need to be reinserted, which is also time-consuming and labor-intensive.
[0005] In summary, the existing script binding method is relatively cumbersome, and special binding operations consume a lot of time resources, affecting the development efficiency of games and scripts. Summary of the invention
[0006] The present invention mainly solves the problem that the existing script binding method is relatively complicated, wherein special binding operations consume a lot of time resources, affecting the efficiency of game development and script development.
[0007] In order to solve the above technical problems, a technical solution adopted by the present invention is to provide a script-based automatic binding method for prefabricated bodies, comprising the following steps:
[0008] Initial configuration steps:
[0009] Create a data pairing table, configure a script template, obtain the prefabricated body loading status, and set the first node to be traversed based on the prefabricated body loading status;
[0010] Script generation steps:
[0011] Configure a node processing function, and generate a first script to be bound based on the data pairing table, the script template, the first node to be traversed, and the node processing function;
[0012] Script binding steps:
[0013] The Creator engine is configured to perform a script binding operation based on the first node to be traversed, the first script to be bound, and the Creator engine.
[0014] As an improved solution, the data pairing table includes: a first attribute table and a first click event table; a plurality of placeholders are set in the script template; the prefabricated body loading situation includes: a first situation and a second situation; the first situation is that there is a loaded first prefabricated body; the second situation is that there is no loaded first prefabricated body; the first to-be-traversed node includes a plurality of first child nodes;
[0015] The node processing function includes: a node structure identification function and a node data filling function; the Creator engine is configured with an attribute binding interface and an event binding interface;
[0016] The step of setting the first node to be traversed based on the preform loading situation further includes: when the preform loading situation is the first situation, obtaining a node selection requirement; selecting a first node in the first preform according to the node selection requirement, and setting the first node as the first node to be traversed.
[0017] As an improved solution, the step of generating the first script to be bound based on the data pairing table, the script template, the first node to be traversed and the node processing function further includes:
[0018] Setting a first character position, a second character position, a first character structure, and a second character structure; performing node binding steps on a plurality of first child nodes based on the first attribute table, the first click event table, the node structure identification function, the node data filling function, the first character position, the second character position, the first character structure, and the second character structure to obtain a plurality of first key-value pairs and a plurality of second key-value pairs;
[0019] Calling the node data filling function to add a number of the first key-value pairs to the first attribute table to obtain a second attribute table; calling the node data filling function to add a number of the second key-value pairs to the first click event table to obtain a second click event table;
[0020] A first string format is set; based on the script template, the second attribute table, the second click event table and the first string format, a data replacement step is performed to obtain the first script to be bound.
[0021] As an improved solution, the node binding step includes:
[0022] Calling the node structure identification function to identify first structure information corresponding to the first character position in the first child node; comparing the first structure information with the first character structure; if the first structure information matches the first character structure, executing a first key-value pair generation step;
[0023] After executing the first key-value pair generation step, call the node structure identification function to identify the second structure information corresponding to the second character position in the first child node; compare the second structure information with the second character structure; if the second structure information matches the second character structure, execute the second key-value pair generation step.
[0024] As an improved solution, the first key-value pair generating step includes: calling the node structure identification function to identify the first name information and the first identification code information of the first child node; integrating the first name information and the first identification code information into the first key-value pair;
[0025] The second key-value pair generation step includes: adding a first component to the first child node; setting a first click event name based on the first name information; identifying the second identification code information of the first component; and integrating the second identification code information and the first click event name into the second key-value pair.
[0026] As an improved solution, the data replacement step includes:
[0027] Reading a plurality of the first key-value pairs in the second attribute table and a plurality of the second key-value pairs in the second click event table; generating a plurality of first script character strings that respectively match the plurality of the first key-value pairs according to the first character string format; generating a plurality of second script character strings that respectively match the plurality of the second key-value pairs according to the first character string format;
[0028] Counting a first number of the first script character strings and a second number of the second script character strings; confirming a number of first placeholders in the script template according to the first number; and confirming a number of second placeholders in the script template according to the second number;
[0029] First, several of the first script character strings are used to replace several of the first placeholders in the script template respectively, and then several of the second script character strings are used to replace several of the second placeholders in the script template respectively, so as to obtain the first script to be bound.
[0030] As an improved solution, the script binding operation includes:
[0031] Bind the first script to be bound to the first node to be traversed; identify a number of the first sub-nodes in the first node to be traversed; set the nodes having the first component among the number of the first sub-nodes as second sub-nodes;
[0032] Identify the first name information respectively corresponding to the first key-value pairs in the first script to be bound; identify the first click event names and second identification code information respectively corresponding to the second key-value pairs in the first script to be bound;
[0033] The attribute binding interface is called to bind the first sub-nodes to the first name information in the first script to be bound according to the first identification code information in the first key-value pair; the event binding interface is called to add the first click event names to the first attributes of the first components of the second sub-nodes according to the second identification code information in the second key-value pair.
[0034] As an improved solution, the first character structure is an underline structure; the second character structure is a combination structure of an underline and a data string; the data string is btn; the first component is a button component; the first attribute is a clickEvents attribute;
[0035] The step of generating the first script to be bound based on the data pairing table, the script template, the first node to be traversed and the node processing function further includes:
[0036] When the node data filling function is called to add the first key-value pairs to the first attribute table, performing verification operations on the first key-value pairs respectively;
[0037] The verification operation includes: traversing the first attribute table to see whether there is a third key-value pair matching the first key-value pair; if not, adding the first key-value pair to the first attribute table; if so, identifying the third identification code information of the third key-value pair in the first attribute table; changing the third identification code information to an empty array, and adding the first identification code information corresponding to the first key-value pair to the empty array.
[0038] The present invention also provides a prefabricated body-based script automatic binding system, comprising:
[0039] Initial configuration module, script generation module and script binding module;
[0040] The initial configuration module is used to create a data pairing table, configure a script template, and obtain a prefabricated body loading status, and the initial configuration module sets a first node to be traversed based on the prefabricated body loading status;
[0041] The script generation module is used to configure the node processing function, and the script generation module generates a first script to be bound based on the data pairing table, the script template, the first node to be traversed and the node processing function;
[0042] The script binding module is used to configure the Creator engine, and the script binding module performs a script binding operation based on the first node to be traversed, the first script to be bound, and the Creator engine.
[0043] The present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the prefabricated body-based script automated binding method are implemented.
[0044] The beneficial effects of the present invention are:
[0045] 1. The prefab-based script automatic binding method of the present invention can realize automatic script generation and automatically bind to the nodes in the corresponding Cocos prefab. At the same time, the script generated and bound by this method does not need to be repeated in the face of script variable changes, which greatly saves script binding time and generation time, improves the efficiency of game development and script development, makes up for the shortcomings of the prior art, and has certain market value and application value.
[0046] 2. The prefab-based script automatic binding system described in the present invention can realize automatic script generation and automatic binding with the nodes in the corresponding Cocos prefab through the mutual cooperation of the initial configuration module, the script generation module and the script binding module. At the same time, the script generated and bound by this system does not need to be repeated in the face of script variable changes, which saves a lot of script binding time and generation time, improves the efficiency of game development and script development, makes up for the shortcomings of the existing technology, and has certain market value and application value.
[0047] 3. The computer-readable storage medium described in the present invention can guide the initial configuration module, the script generation module and the script binding module to cooperate, thereby realizing automatic script generation and automatically binding with the nodes in the corresponding Cocos prefab. At the same time, when the script variables change, there is no need to perform repeated binding operations, which greatly saves the script binding time and generation time, improves the efficiency of game development and script development, and effectively improves the operability of the prefab-based script automatic binding method. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0049] Figure 1 is a flowchart of the script automated binding method based on prefabricated bodies described in Example 1 of the present invention;
[0050] Figure 2 It is a specific flow chart of the script automatic binding method based on prefabricated body described in Example 1 of the present invention;
[0051] Figure 3 It is an architecture diagram of the prefabricated body-based script automated binding system described in Example 2 of the present invention. DETAILED DESCRIPTION
[0052] The preferred embodiments of the present invention are described in detail below in conjunction with the accompanying drawings so that the advantages and features of the present invention can be more easily understood by those skilled in the art, thereby making a clearer and more definite definition of the protection scope of the present invention.
[0053] In the description of the present invention, it should be noted that the embodiments described in the present invention are only part of the embodiments of the present invention, rather than all of the embodiments; based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present invention.
[0054] In the description of the present invention, it should be noted that the terms “first”, “second” and “third” are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0055] In the description of the present invention, it should be noted that the prefabricated script automatic binding method provided in this embodiment 1 is applied in the game development process; specifically, it is applied to the relevant processes of Cocos prefabricated node and script binding operation after the game interface is built.
[0056] In the description of the present invention, it should be noted that: Cocos is a systematic game development platform; Creator is a game development engine.
[0057] Example 1
[0058] This embodiment provides a script-based automatic binding method for prefabricated objects. Figure 1 and Figure 2 As shown, the following steps are included:
[0059] S100, initial configuration steps, specifically including:
[0060] S110, creating a data pairing table, configuring a script template, obtaining a preform loading status, and setting a first node to be traversed based on the preform loading status; in this embodiment, the data pairing table is an empty table, that is, a list to be filled; the preform loading status is the opening status of the first preform to be node bound; the first node to be traversed is a node in the first preform to which a script needs to be bound by this method;
[0061] Specifically, the data pairing table includes: a first attribute table and a first click event table; the first attribute table is used to store relevant data representing node attributes; the first click event table is used to store relevant data representing node-associated function events; a number of placeholders are provided in the script template; the placeholders are respectively fixed positions to be filled in the script template, and are used to cooperate with subsequent script generation steps; the preform loading conditions include: a first condition and a second condition; the first condition is that there is a loaded first preform, that is, there is an opened first preform; the second condition is that there is no loaded first preform, that is, there is no opened first preform; the first node to be traversed contains a number of first child nodes;
[0062] Specifically, when the preform loading situation is the first situation, the node selection requirement is obtained, and the node selection requirement is the relevant identification information of a node that the operator wants to bind; according to the node selection requirement, the first node matching the above identification information is selected in the first preform, and the first node is set as the first node to be traversed.
[0063] Correspondingly, part of the core JavaScript code of step S100 is as follows:
[0064] / / Script template
[0065] let classTemplete = `cc.Class({
[0066] extends: cc.Component,
[0067] properties:
[0068] {properties}
[0069] },
[0070] / / LIFE-CYCLE CALLBACKS:
[0071] / / onLoad () {},
[0072] start () {
[0073] },
[0074] / / update (dt) {},
[0075] {clicks}
[0076] });
[0077] / / Node selection
[0078] let scriptProperties = {};
[0079] let scriptClicks = {};
[0080] let scriptFileUuid;
[0081] const generateScript = () => {
[0082] let root = Editor.Selection.curSelection('node')[0];
[0083] if (!root) return Editor.error('Please select the node where you need to generate the script');
[0084] let rootNode = cc.engine.getInstanceById(root);
[0085] / / Initialize table
[0086] scriptProperties = {};
[0087] scriptClicks = {};
[0088] scriptFileUuid = '';
[0089] S200, script generation step, specifically including:
[0090] S210, configuring a node processing function, generating a first script to be bound based on the data pairing table, the script template, the first node to be traversed and the node processing function; in this embodiment, the node processing function is a function compiled in a programming language to implement related functions; the first script to be bound is a script to be bound to the first node to be traversed in step S100;
[0091] Specifically, the node processing function includes: a node structure identification function and a node data filling function;
[0092] Specifically, the first character position, the second character position, the first character structure and the second character structure are set; in the present embodiment, the first character position is the beginning of the character of the node; the second character position is the related character position of the second position of the beginning of the character of the node; correspondingly, the first character structure is an underline structure, which is an underline in the present embodiment, that is, "_"; the second character structure is a combination structure of an underline and a data string, and in the present embodiment, the data string is btn, that is, the second character structure is "_btn"; correspondingly, based on the first attribute table, the first click event table, the node structure identification function, the node data filling function, the first character position, the second character position, the first character structure and the second character structure, the node binding steps are respectively performed on the first child nodes to obtain a plurality of first key-value pairs and a plurality of second key-value pairs; the node data filling function is called to convert the plurality of first key-value pairs Add to the first attribute table to obtain the second attribute table; call the node data filling function to add several of the second key-value pairs to the first click event table to obtain the second click event table; correspondingly, the node binding step is executed synchronously for each first child node; the second attribute table and the second click event table are respectively the first attribute table and the first click event table after the node binding step; set the first string format; in this embodiment, the first string format is a specific string format, and the first string format matches the data format specifically supported and adapted by the script template, so the first string format is specifically set according to the specifications of the script template; the first string format is used as the data structure basis for auxiliary script generation; therefore, based on the script template, the second attribute table, the second click event table and the first string format, the data replacement step is performed to obtain the first script to be bound.
[0093] Specifically, the specific logical process of the node binding step executed for each first child node includes: calling the node structure identification function to identify the first structural information corresponding to the first character position in the first child node; in this embodiment, the first structural information is the relevant character data at the beginning of the character of the first child node; comparing the first structural information with the first character structure; if the first structural information matches the first character structure, that is, the relevant character data at the beginning of the character of the first child node is "_", then executing the first key-value pair generation step; after executing the first key-value pair generation step, it is also necessary to determine whether there is a related click event for the current first child node, so calling the node structure identification function to identify the second structural information corresponding to the second character position in the first child node, the second structural information is the relevant character data at the relevant character position of the first child node; comparing the second structural information with the second character structure; if the second structural information matches the second character structure, that is, the relevant character data at the relevant character position of the first child node is "_btn", then executing the second key-value pair generation step;
[0094] Specifically, the first key-value pair generation step includes: calling the node structure identification function to identify the first name information and the first identification code information of the first child node. In this embodiment, the first name information is the name of the current first child node; the first identification code information is the uuid of the current first child node; integrating the first name information and the first identification code information into the first key-value pair, that is, binding the name of the current first child node and the uuid of the current first child node in the form of key=value;
[0095] Specifically, the second key-value pair generation step includes: adding a first component to the first child node, in this embodiment, the first component is a button component; setting a first click event name based on the first name information, in this embodiment, the first click event name is associated with the name of the first child node for setting, and the specific name setting rules are not limited, and are mainly used to distinguish indexes and identify click events; identifying the second identification code information of the first component, the second identification code information is the uuid of the button component just added; integrating the second identification code information and the first click event name into the second key-value pair, and the integration principle of the second key-value pair is the same as that of the first key-value pair;
[0096] Specifically, after the above steps, the placeholders in the script template can be replaced according to the key-value pairs, thereby generating the corresponding script;
[0097] Specifically, the data replacement step includes: first, reading several first key-value pairs in the second attribute table and several second key-value pairs in the second click event table; then generating several first script strings that match several first key-value pairs respectively according to the first string format; generating several second script strings that match several second key-value pairs respectively according to the first string format; a script string is a related string that can be used in a script template for script generation; counting a first number of several first script strings and a second number of several second script strings; confirming several first placeholders according to the first number in several placeholders in the script template; confirming several second placeholders according to the second number in several placeholders in the script template; several first placeholders are respectively the positions to be filled in several first script strings; several second placeholders are respectively the positions to be filled in several second script strings; therefore, firstly, several first script strings are used to replace several first placeholders in the template to be filled respectively, and then several second script strings are used to replace several second placeholders in the template to be filled respectively, to obtain the first script to be bound;
[0098] Correspondingly, in this step, when the node data filling function is called to add a plurality of the first key-value pairs to the first attribute table, it is necessary to perform a verification operation on the plurality of the first key-value pairs respectively; that is, it is necessary to traverse the first attribute table to see whether the plurality of the first key-value pairs exist;
[0099] Specifically, the verification operation includes: traversing the first attribute table to see whether there is a third key-value pair matching the first key-value pair; if not, adding the first key-value pair to the first attribute table; if so, identifying the specific value of the third identification code information of the third key-value pair in the first attribute table; changing the specific value of the third identification code information to an empty array, and adding the first identification code information corresponding to the first key-value pair to the empty array, thereby completing the adjustment of the existing first key-value pair.
[0100] Correspondingly, part of the core JavaScript code of step S200 is as follows, through which the script is automatically generated, thereby improving the script generation efficiency;
[0101] let addItem = (map, name, uuid) => {
[0102] if (!map[name]) { / / The key does not exist, save it directly
[0103] map[name] = uuid;
[0104] } else if (Array.isArray(map[name])) {
[0105] / / The key exists and is an array, add it to the array
[0106] map[name].push(uuid);
[0107] } else {
[0108] / / The key exists and is not an array, change it to an array
[0109] map[name] = [map[name], uuid];
[0110] }
[0111] }
[0112] / / Traverse the nodes
[0113] travelCocosNode(rootNode, (node) => {
[0114] / / Process nodes starting with an underscore
[0115] if (node.name.startsWith('_')) {
[0116] / / Nodes starting with _btn are considered buttons
[0117] if (node.name.startsWith(PREFIX_BUTTON)) {
[0118] / / Make sure the node has a Button component
[0119] let btnComp = node.getComponent(cc.Button);
[0120] if (!btnComp) btnComp = node.addComponent(cc.Button);
[0121] / / Construct event name and add it to the click event table
[0122] addItem(scriptClicks, `on${node.name.substr(4)}Click`, btnComp);
[0123] / / Add to the property table
[0124] addItem(scriptProperties, node.name, node.uuid);
[0125] } else {
[0126] / / Non-button, just add to the property sheet
[0127] addItem(scriptProperties, node.name, node.uuid);
[0128] }
[0129] }
[0130] });
[0131] / / Traverse the attribute table and construct the attribute string
[0132] let propKeys = Object.keys(scriptProperties);
[0133] let propertiesStr = propKeys.map(p =>
[0134] ${p.substr(1)}: ${getClassByName(p, Array.isArray(scriptProperties[p]))}`
[0135] ).join(',\n');
[0136] / / Traverse the click event table and construct a click event string
[0137] let clickKeys = Object.keys(scriptClicks);
[0138] let clickStr = clickKeys.map(c =>
[0139] ${c} () {\n\n}`
[0140] ).join(',\n\n');
[0141] / / Replace the placeholders in the template and save the script
[0142] let classStr = classTemplete.replace('{properties}',propertiesStr).replace('{clicks}', clickStr);
[0143] let jsTargetUrl = `db: / / assets / ${rootNode.name}.js`;
[0144] if (gTargetUrl) jsTargetUrl = `${gTargetUrl} / ${rootNode.name}.js`
[0145] Editor.assetdb.create(jsTargetUrl, classStr, (e, r) => {
[0146] if (e) return console.error(e);
[0147] if (r.length > 0) scriptFileUuid = r[0].uuid;
[0148] })
[0149] }
[0150] S300, script binding step, specifically including:
[0151] S310, configuring the Creator engine, and performing a script binding operation based on the first node to be traversed, the first script to be bound, and the Creator engine; in this embodiment, the Creator engine is a game development engine for developing games and exporting the first prefab;
[0152] Specifically, the Creator engine is configured with an attribute binding interface and an event binding interface; both the attribute binding interface and the event binding interface are functional APIs provided by the Creator engine, which can be pre-configured or reset; correspondingly, based on the above two interfaces and the first node to be traversed and the first script to be bound obtained in the above steps, an automated script binding operation is performed;
[0153] Specifically, the script binding operation includes:
[0154] First, the first script to be bound generated in step S200 is bound to the first node to be traversed; after completion, a specific subnode in the first node to be traversed needs to be bound to a variable on the script, thereby completing the entire binding operation; therefore, several first subnodes in the first node to be traversed are identified; at the same time, several nodes having the first component (i.e., button component) in the first subnodes are set as second subnodes; several first name information corresponding to several first key-value pairs in the first script to be bound are identified; several first click event names and several second identification code information corresponding to several second key-value pairs in the first script to be bound are identified;
[0155] First, the attribute binding interface is called to bind the first sub-nodes to the first name information in the first script to be bound according to the first identification code information in the first key-value pair, that is, the uuid of the first sub-node is used as the index and the associated item; then, the event binding interface is called to add the first click event names to the first attributes of the first components (i.e., button components) of the second sub-nodes according to the second identification code information in the second key-value pair, that is, the uuid of the button component is used as the index and the associated item; specifically, in the present embodiment, the first attribute is the clickEvents attribute; through the above steps, the script automatic binding operation based on the Cocos prefab is completed;
[0156] Correspondingly, part of the core JavaScript code of step S300 is as follows, through which the automatic binding of the script is realized, thereby improving the script binding efficiency;
[0157] / / Bind script
[0158] const bindScript = () => {
[0159] let root = Editor.Selection.curSelection('node')[0];
[0160] if (!root) return Editor.error('Please select the node to which you need to bind the script');
[0161] let rootNode = cc.engine.getInstanceById(root);
[0162] let comp = rootNode.addComponent(rootNode.name);
[0163] let compId = comp.uuid;
[0164] / / Traverse the property table
[0165] let propKeys = Object.keys(scriptProperties);
[0166] propKeys.forEach((p) => {
[0167] let prop = scriptProperties[p];
[0168] if (Array.isArray(prop)) {
[0169] / / Bind the array
[0170] Editor.Ipc.sendToPanel('scene','scene:set-property', {
[0171] id: compId,
[0172] isSubProp: false,
[0173] path: `${p.substr(1)}.length`,
[0174] type: undefined,
[0175] value: prop.length
[0176] });
[0177] for (let i = 0, n = prop.length; i < n; i++) {
[0178] Editor.Ipc.sendToPanel('scene','scene:set-property',{
[0179] id: compId,
[0180] isSubProp: false,
[0181] path: `${p.substr(1)}.${i}`,
[0182] type: getClassByName(p),
[0183] value: { uuid: prop[i]}
[0184] });
[0185] }
[0186] } else {
[0187] / / Bind normal nodes
[0188] Editor.Ipc.sendToPanel('scene', 'scene:set-property', {
[0189] id: compId,
[0190] isSubProp: false,
[0191] path: p.substr(1),
[0192] type: getClassByName(p),
[0193] value: { uuid: prop}
[0194] });
[0195] }
[0196] });
[0197] / / Traverse the click event table and set the click event corresponding to the button
[0198] let clickKeys = Object.keys(scriptClicks);
[0199] clickKeys.forEach(c => {
[0200] let btnComp = scriptClicks[c];
[0201] if (!Array.isArray(btnComp)) btnComp = [btnComp];
[0202] for (let i = 0, n = btnComp.length; i < n; i++) {
[0203] let comp = btnComp[i];
[0204] let len = comp.clickEvents.length;
[0205] Editor.Ipc.sendToPanel('scene', 'scene:set-property', {
[0206] id: comp.uuid,
[0207] isSubProp: false,
[0208] path: 'clickEvents.length',
[0209] type: undefined,
[0210] value: len + 1
[0211] })
[0212] Through the prefab-based script automatic binding method described in Example 1, scripts can be automatically generated according to the nodes of the Cocos prefab and automatically bound to the corresponding nodes. This script generation and binding method does not require repeated binding operations when the script variables change, which greatly saves script binding time and generation time, improves the efficiency of game development and script development, and makes up for the shortcomings of the existing technology.
[0213] Example 2
[0214] This embodiment is based on the same inventive concept as the prefabricated body-based script automatic binding method described in Embodiment 1, and provides a prefabricated body-based script automatic binding system, such as Figure 3 As shown, it includes: an initial configuration module, a script generation module and a script binding module;
[0215] In the prefab-based script automatic binding system, the initial configuration module is used to create a data pairing table, configure a script template, and obtain the prefab loading status, and the initial configuration module sets the first node to be traversed based on the prefab loading status;
[0216] Specifically, the data pairing table includes: a first attribute table and a first click event table; a plurality of placeholders are set in the script template; the prefabricated body loading situation includes: a first situation and a second situation; the first situation is that there is a loaded first prefabricated body; the second situation is that there is no loaded first prefabricated body; the first to-be-traversed node includes a plurality of first child nodes;
[0217] Specifically, when the preform loading situation is the first situation, the initial configuration module obtains the node selection requirement; the initial configuration module selects the first node in the first preform according to the node selection requirement, and sets the first node as the first node to be traversed.
[0218] In the prefabricated body-based script automatic binding system, the script generation module is used to configure the node processing function, and the script generation module generates a first script to be bound based on the data pairing table, the script template, the first node to be traversed and the node processing function;
[0219] Specifically, the node processing function includes: a node structure identification function and a node data filling function;
[0220] Specifically, the script generation module sets the first character position, the second character position, the first character structure and the second character structure; the script generation module performs node binding steps on several first child nodes based on the first attribute table, the first click event table, the node structure identification function, the node data filling function, the first character position, the second character position, the first character structure and the second character structure, and obtains several first key-value pairs and several second key-value pairs; the script generation module calls the node data filling function to add several first key-value pairs to the first attribute table to obtain the second attribute table; the script generation module calls the node data filling function to add several second key-value pairs to the first click event table to obtain the second click event table; the script generation module sets the first string format; the script generation module performs data replacement steps based on the script template, the second attribute table, the second click event table and the first string format to obtain the first script to be bound.
[0221] Specifically, the node binding step includes: the script generation module calls the node structure identification function to identify the first structural information corresponding to the first character position in the first child node; the script generation module compares the first structural information with the first character structure; if the first structural information matches the first character structure, the script generation module executes the first key-value pair generation step; after executing the first key-value pair generation step, the script generation module calls the node structure identification function to identify the second structural information corresponding to the second character position in the first child node; the script generation module compares the second structural information with the second character structure; if the second structural information matches the second character structure, the script generation module executes the second key-value pair generation step.
[0222] Specifically, the first key-value pair generation step includes: the script generation module calls the node structure identification function to identify the first name information and the first identification code information of the first child node; the script generation module integrates the first name information and the first identification code information into the first key-value pair;
[0223] Specifically, the second key-value pair generation step includes: the script generation module adds a first component to the first child node; the script generation module sets the first click event name based on the first name information; the script generation module identifies the second identification code information of the first component; the script generation module integrates the second identification code information and the first click event name into the second key-value pair.
[0224] Specifically, it also includes: when the script generation module calls the node data filling function to add the first key-value pairs to the first attribute table, the script generation module performs verification operations on the first key-value pairs respectively;
[0225] Specifically, the verification operation includes: the script generation module traverses the first attribute table to see whether there is a third key-value pair matching the first key-value pair; if not, the script generation module adds the first key-value pair to the first attribute table; if so, the script generation module identifies the third identification code information of the third key-value pair in the first attribute table; the script generation module changes the third identification code information to an empty array, and adds the first identification code information corresponding to the first key-value pair to the empty array;
[0226] Specifically, the data replacement step includes: the script generation module reads several first key-value pairs in the second attribute table and several second key-value pairs in the second click event table; the script generation module generates several first script strings that match several first key-value pairs respectively according to the first string format; the script generation module generates several second script strings that match several second key-value pairs respectively according to the first string format; the script generation module counts the first number of several first script strings and the second number of several second script strings; the script generation module confirms several first placeholders according to the first number among several placeholders in the script template; the script generation module confirms several second placeholders according to the second number among several placeholders in the script template; first, the script generation module uses several first script strings to replace several first placeholders in the script template respectively, and then the script generation module uses several second script strings to replace several second placeholders in the script template respectively, to obtain the first script to be bound.
[0227] In the prefab-based script automatic binding system, the script binding module is used to configure the Creator engine, and the script binding module performs a script binding operation based on the first node to be traversed, the first script to be bound, and the Creator engine;
[0228] Specifically, the Creator engine is configured with an attribute binding interface and an event binding interface;
[0229] Specifically, the script binding operation includes: the script binding module binds the first script to be bound to the first node to be traversed; the script binding module identifies several first child nodes in the first node to be traversed; the script binding module sets the nodes with the first component in several first child nodes as second child nodes; the script binding module identifies several first name information corresponding to several first key-value pairs in the first script to be bound; the script binding module identifies several first click event names and several second identification code information corresponding to several second key-value pairs in the first script to be bound; the script binding module calls the attribute binding interface to bind several first child nodes to several first name information in the first script to be bound according to the first identification code information in the first key-value pairs; the script binding module calls the event binding interface to add several first click event names to several first attributes of several first components of several second child nodes according to the second identification code information in the second key-value pairs.
[0230] Example 3
[0231] This embodiment provides a computer-readable storage medium, including:
[0232] The storage medium is used to store computer software instructions used to implement the preform-based script automation binding method described in the above-mentioned Example 1, which includes a program for executing the above-mentioned program set for the preform-based script automation binding method; specifically, the executable program can be built into the preform-based script automation binding system described in Example 2, so that the preform-based script automation binding system can implement the preform-based script automation binding method described in Example 1 by executing the built-in executable program.
[0233] In addition, the computer-readable storage medium of this embodiment may adopt any combination of one or more computer-readable storage media, wherein the computer-readable storage medium includes electrical, optical, electromagnetic, infrared or semiconductor systems, devices or components, or any combination thereof.
[0234] Different from the prior art, the present application adopts a prefabricated script automatic binding method, system and medium, which can automatically generate scripts through this method and automatically bind them to the nodes in the corresponding Cocos prefab. At the same time, the script generated and bound by this method does not need to be repeated in the face of script variable changes, which saves a lot of script binding time and generation time. The system provides effective technical support for the method, which ultimately improves the efficiency of game development and script development, makes up for the shortcomings of the prior art, and has certain market value and application value.
[0235] The serial numbers of the embodiments disclosed in the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0236] A person skilled in the art will appreciate that all or part of the steps for implementing the above embodiments may be accomplished by hardware, or may be accomplished by a program to instruct the relevant hardware. The program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk, or an optical disk, etc.
[0237] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A script-based automated binding method for prefabricated objects, characterized in that: The following steps are involved: Initial configuration steps: Create a data pairing table, configure a script template, obtain the prefabricated body loading status, and set the first node to be traversed based on the prefabricated body loading status; The data pairing table includes: a first attribute table and a first click event table; a plurality of placeholders are provided in the script template; the prefabricated loading conditions include: a first condition and a second condition; the first condition is that there is a loaded first prefabricated body; the second condition is that there is no loaded first prefabricated body; the first node to be traversed includes a plurality of first child nodes; the node processing function includes: a node structure identification function and a node data filling function; the Creator engine is configured with an attribute binding interface and an event binding interface; the step of setting the first node to be traversed based on the prefabricated loading condition further includes: when the prefabricated loading condition is the first condition, obtaining a node selection requirement; selecting a first node in the first prefabricated body according to the node selection requirement, and setting the first node as the first node to be traversed; Script generation steps: The node processing function is configured to generate a first script to be bound based on the data pairing table, the script template, the first node to be traversed and the node processing function; the step of generating the first script to be bound based on the data pairing table, the script template, the first node to be traversed and the node processing function further includes: setting a first character position, a second character position, a first character structure and a second character structure; performing node binding steps on a plurality of the first child nodes respectively based on the first attribute table, the first click event table, the node structure identification function, the node data filling function, the first character position, the second character position, the first character structure and the second character structure, and obtaining a plurality of first key-value pairs and a plurality of second key-value pairs; calling the node data filling function to add the plurality of the first key-value pairs to the first attribute table to obtain a second attribute table; calling the node data filling function to add the plurality of the second key-value pairs to the first click event table to obtain a second click event table; setting a first string format; performing a data replacement step based on the script template, the second attribute table, the second click event table and the first string format to obtain the first script to be bound; the node binding step includes: calling the node structure identification function to identify the first structure information corresponding to the first character position in the first child node; comparing the first structure information with the first character structure; if the first structure If the information matches the first character structure, the first key-value pair generating step is executed; after executing the first key-value pair generating step, the node structure identifying function is called to identify the second structure information corresponding to the second character position in the first child node; the second structure information is compared with the second character structure; if the second structure information matches the second character structure, the second key-value pair generating step is executed; the first key-value pair generating step includes: calling the node structure identifying function to identify the first name information and the first identification code information of the first child node; integrating the first name information and the first identification code information into the first key-value pair; the second key-value pair generating step includes: Adding a first component; setting a first click event name based on the first name information; identifying the second identification code information of the first component; integrating the second identification code information and the first click event name into the second key-value pair; the data replacement step includes: reading a number of the first key-value pairs in the second attribute table and a number of the second key-value pairs in the second click event table; generating a number of first script strings that match the number of the first key-value pairs respectively according to the first string format; generating a number of second script strings that match the number of the second key-value pairs respectively according to the first string format; counting a first number of the number of the first script strings and a second number of the number of the second script strings;Confirming a number of first placeholders in the script template according to the first number; confirming a number of second placeholders in the script template according to the second number; firstly replacing a number of the first placeholders in the script template with a number of the first script strings, and then replacing a number of the second placeholders in the script template with a number of the second script strings, to obtain the first script to be bound; Script binding steps: Configure the Creator engine, and perform a script binding operation based on the first node to be traversed, the first script to be bound, and the Creator engine; the script binding operation includes: binding the first script to be bound to the first node to be traversed; identifying several of the first child nodes in the first node to be traversed; setting the nodes with the first component in several of the first child nodes as second child nodes; identifying several of the first name information corresponding to several of the first key-value pairs in the first script to be bound; identifying several of the first click event names and several of the second identification code information corresponding to several of the second key-value pairs in the first script to be bound; calling the attribute binding interface to bind several of the first child nodes to several of the first name information in the first script to be bound according to the first identification code information in the first key-value pairs; calling the event binding interface to add several of the first click event names to several of the first attributes of several of the first components of several of the second child nodes according to the second identification code information in the second key-value pairs.
2. A script-based automatic binding method for prefabricated bodies according to claim 1, characterized in that: The first character structure is an underline structure; the second character structure is a combination structure of an underline and a data string; the data string is btn; the first component is a button component; The first attribute is the clickEvents attribute; The step of generating the first script to be bound based on the data pairing table, the script template, the first node to be traversed and the node processing function further includes: When the node data filling function is called to add the first key-value pairs to the first attribute table, performing verification operations on the first key-value pairs respectively; The verification operation includes: traversing the first attribute table to see whether there is a third key-value pair matching the first key-value pair; if not, adding the first key-value pair to the first attribute table; if so, identifying the third identification code information of the third key-value pair in the first attribute table; changing the third identification code information to an empty array, and adding the first identification code information corresponding to the first key-value pair to the empty array.
3. A prefabricated script-based automatic binding system based on a prefabricated script-based automatic binding method according to any one of claims 1 to 2, characterized in that: include: Initial configuration module, script generation module and script binding module; The initial configuration module is used to create a data pairing table, configure a script template, and obtain a prefabricated body loading status, and the initial configuration module sets a first node to be traversed based on the prefabricated body loading status; The data pairing table includes: a first attribute table and a first click event table; a plurality of placeholders are provided in the script template; the prefabricated body loading conditions include: a first condition and a second condition; the first condition is that there is a loaded first prefabricated body; the second condition is that there is no loaded first prefabricated body; the first node to be traversed includes a plurality of first child nodes; the node processing function includes: a node structure identification function and a node data filling function; the Creator engine is configured with an attribute binding interface and an event binding interface; the initial configuration module obtains a node selection requirement when the prefabricated body loading condition is the first condition; the initial configuration module selects a first node in the first prefabricated body according to the node selection requirement, and sets the first node as the first node to be traversed; The script generation module is used to configure the node processing function. The script generation module generates a first script to be bound based on the data pairing table, the script template, the first node to be traversed and the node processing function; the script generation module sets the first character position, the second character position, the first character structure and the second character structure; the script generation module performs node binding steps on a plurality of the first child nodes based on the first attribute table, the first click event table, the node structure identification function, the node data filling function, the first character position, the second character position, the first character structure and the second character structure, respectively, to obtain a plurality of first key-value pairs and a plurality of second key-value pairs; the script generation module calls the node The point data filling function adds a number of the first key-value pairs to the first attribute table to obtain a second attribute table; the script generation module calls the node data filling function to add a number of the second key-value pairs to the first click event table to obtain a second click event table; the script generation module sets a first string format; the script generation module performs a data replacement step based on the script template, the second attribute table, the second click event table and the first string format to obtain the first script to be bound; the node binding step includes: the script generation module calls the node structure identification function to identify the first structure information corresponding to the first character position in the first child node; the script generation module replaces the first character position with the first character position; The script generation module compares a first structure information with the first character structure; if the first structure information matches the first character structure, the script generation module executes a first key-value pair generation step; after the script generation module executes the first key-value pair generation step, the node structure recognition function is called to identify the second structure information corresponding to the second character position in the first child node; the script generation module compares the second structure information with the second character structure; if the second structure information matches the second character structure, the script generation module executes a second key-value pair generation step; the first key-value pair generation step includes: the script generation module calls the node structure recognition function to identify the first name of the first child node The script generation module integrates the first name information and the first identification code information into the first key-value pair; the second key-value pair generation step includes: the script generation module adds a first component to the first child node; the script generation module sets a first click event name based on the first name information; the script generation module identifies the second identification code information of the first component; the script generation module integrates the second identification code information and the first click event name into the second key-value pair; the data replacement step includes: the script generation module reads a number of the first key-value pairs in the second attribute table and a number of the second key-value pairs in the second click event table;The script generation module generates a plurality of first script strings that match a plurality of first key-value pairs respectively according to the first string format; the script generation module generates a plurality of second script strings that match a plurality of second key-value pairs respectively according to the first string format; the script generation module counts a first number of the plurality of first script strings and a second number of the plurality of second script strings; the script generation module confirms a plurality of first placeholders according to the first number among the plurality of placeholders in the script template; the script generation module confirms a plurality of second placeholders according to the second number among the plurality of placeholders in the script template; firstly, the script generation module replaces a plurality of first placeholders in the script template respectively with a plurality of the first script strings, and then the script generation module replaces a plurality of second placeholders in the script template respectively with a plurality of the second script strings, to obtain the first script to be bound; The script binding module is used to configure the Creator engine. The script binding module performs a script binding operation based on the first node to be traversed, the first script to be bound and the Creator engine. The script binding operation includes: the script binding module binds the first script to be bound to the first node to be traversed; the script binding module identifies several first child nodes in the first node to be traversed; the script binding module sets the node with the first component in several first child nodes as the second child node; the script binding module identifies several first name information corresponding to several first key-value pairs in the first script to be bound; the script binding module identifies several first click event names and several second identification code information corresponding to several second key-value pairs in the first script to be bound; the script binding module calls the attribute binding interface to bind several first child nodes to several first name information in the first script to be bound according to the first identification code information in the first key-value pair; the script binding module calls the event binding interface to add several first click event names to several first attributes of several first components of several second child nodes according to the second identification code information in the second key-value pair.
4. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the prefabricated body-based script-automated binding method described in any one of claims 1 to 2 are implemented.
Citation Information
Patent Citations
Code completion implementation method and device, and computing device
CN105739981A
Game interface generation method and game interface generation device
CN107320956A