A Web client JavaScript method to call Unity scene

Through JSBridgeSDK and JSBridgeObject, JavaScript code execution and callbacks are implemented in Unity WebGL, solving the problem of poor function call flexibility when JavaScript calls C# methods, and realizing the flexible access and operation of Unity scenarios by browser-side JavaScript.

CN119025092BActive Publication Date: 2025-03-21ASPIRE TECH (SHENZHEN) LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411515558.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-03-21
Estimated Expiration
2044-10-29

AI Technical Summary

Technical Problem

In the prior art, when JavaScript calls C# methods in Unity WebGL, there is a problem of poor flexibility in function calling, making it difficult to achieve flexible calling of Unity functions.

Method used

The JavaScript code module running on the browser side of the JSBridgeSDK transmits the JavaScript code information required to be executed to the Unity scenario, uses JSBridgeObject to execute JavaScript code in the Unity scenario, and passes the results back from the C# callback function to the browser side through the agreed JavaScript method.

Benefits of technology

It realizes the function of flexibly accessing and manipulating objects and object components in Unity scenarios, which is equivalent to the UnityInstance.SendMessage(objectName, methodName, value) function provided by Unity WebGL.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119025092B_ABST
    Figure CN119025092B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for calling a Unity scene from a Web client JavaScript, comprising: a JavaScript code module running on a browser transmits JavaScript code information required to be executed to a Unity scene through JSBridgeSDK; the Unity scene executes the JavaScript code required to be executed using JSBridgeObject; if there is a return result, the result is transmitted back to the browser from a C# callback function in the Unity scene through an agreed JavaScript method. The present invention enables JavaScript running on a browser to flexibly call Unity SDK functions, and implements scene functions through JavaScript code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of software technology, and in particular relates to a method for a Web client JavaScript to call a Unity scene. Background Art

[0002] Unity WebGL is developed in combination with front-end technology, and the front-end technology is used to cover the UI interface developed by the front-end on the Unity scene. Under such a technical framework, there are application scenarios where Unity C# code calls functions implemented by JavaScript on the front-end, such as feedback to the front-end page after clicking on the GameObject in the Unity scene. In this case, the mechanism provided by Unity WebGL can be used in the C# function code to call the pre-defined JavaScript method to implement this function. Conversely, there are also application scenarios where JavaScript can call functions implemented by Unity C#. In this case, Unity WebGL can be used to provide UnityInstance.SendMessage(objectName, methodName, value), where UnityInstance is the JavaScript instance created by Unity WebGL, objectName is the object name in the Unity scene, methodName is the method name of the script associated with the object named objectName, and value is the parameter passed to the method named methodName, which can only be a basic data type, such as a string, a number, or null.

[0003] In the mechanism provided by Unity WebGL for JavaScript to call Unity C# methods, there is a close binding relationship between the objects in the scene and the methods of the object's script. Basically, every time a specific function is called, it is necessary to add a corresponding function to the script of the corresponding C# object, which makes it difficult to call Unity functions flexibly.

[0004] The existing JavaScript calling C# code technologies are:

[0005] (1) Use a browser control, such as WebBrowser or WebView

[0006] This technology mainly uses the built-in WebBrowser control or WebView control to build native Windows applications, which provide basic JavaScript and C# interaction capabilities. This technology is applied to desktop applications and cannot be applied to front-end development.

[0007] (2) Using the NanUI development framework

[0008] NanUI is a .NET interface development framework based on ChromiumFX, which allows developers to build native Windows applications using HTML5, CSS3 and JavaScript. Such technologies are used in desktop applications and cannot be used in front-end development.

[0009] (3) Using the Blazor development framework

[0010] Blazor is a technology that uses .NET to build interactive client-side web applications. It supports two modes: (Mode 1) Blazor Server mode, which requires running .NET on the server side, maintaining a real-time connection with the browser through SignalR, and implementing the interaction between C# and JavaScript through the IJSRuntime service. (Mode 2) Blazor WebAssembly mode, which runs .NET code directly in the browser, requires the API provided by Blazor to implement the interaction between JavaScript and C# code. This type of technology requires Blazor to be deployed on the server and cannot be applied to front-end development.

[0011] (4) Using Electron.NET

[0012] Combining Electron (Node.js + Chromium) with .NET Core, cross-process communication can be achieved in the Electron environment, and C# and JavaScript interact through the IPC mechanism of the Electron environment. This type of technology uses cross-process communication and cannot be applied to front-end development.

[0013] In view of this, it is necessary to propose a new method and device to solve the problem of calling Unity scenes in front-end development. Summary of the invention

[0014] Based on this, it is necessary to provide a method for a Web client JavaScript to call a Unity scene in order to solve at least one problem existing in the above-mentioned prior art.

[0015] The present invention provides a method for calling a Unity scene using JavaScript on a Web client, comprising:

[0016] The JavaScript code module running on the browser transmits the JavaScript code information required to be executed to the Unity scene through JSBridgeSDK;

[0017] The Unity scene uses JSBridgeObject to execute the JavaScript code required to be executed;

[0018] If there is a result returned, it is transmitted from the C# callback function in the Unity scene to the browser through the agreed JavaScript method.

[0019] Optionally, the JavaScript code module running on the browser transmits JavaScript code information required to be executed to the Unity scene through JSBridgeSDK, specifically:

[0020] Construct a UnityInstance object and initialize it;

[0021] Call SendMessage of the UnityInstance object to send a message to Unity, passing the JavaScript code content required to be executed.

[0022] Optionally, the Unity scene uses JSBridgeObject to execute the JavaScript code required to be executed, specifically including:

[0023] Name the object in the Unity scene JSBridge and add the JSBridgeBehaviour component;

[0024] Configure the bridge interface between JavaScript and Unity C# into the jslib file;

[0025] The JSBridgeBehaviour component imports the JavaScript method defined in the jslib file;

[0026] The JSBridgeBehaviour component calls the ExecJSContent method to directly execute JavaScript code.

[0027] Optionally, the parameters of the ExecJSContent method include a Config parameter, a JavaScriptContent parameter and a Callback parameter, wherein the Config parameter is a JSON object, and the first-layer JSON variables therein will be configured by the JSBridgeBehaviour component as JavaScript variables that can be directly used in the JavaScriptContent parameter; the JavaScriptContent parameter is the JavaScript code to be executed; and the Callback parameter is the callback method triggered in the JavaScript code to be executed in the JavaScriptContent parameter;

[0028] The JSBridgeBehaviour component calls the ExecJSContent method to directly execute JavaScript code, specifically including:

[0029] Create a JintEngine instance, configure it to allow all access controls, and set the locale;

[0030] Initialize the JavaScript runtime environment;

[0031] The Execute method of the JintEngine class is called to execute the JavaScript code to be executed in the JavaScriptContent parameter.

[0032] Optionally, the initialization of the JavaScript runtime environment is specifically as follows:

[0033] Use the SetValue method of the JintEngine class to configure the convenience method in the JSBridgeBehaviour component to the environment;

[0034] Set JavaScript callback browser-side JavaScript callback method.

[0035] Optionally, the initialization of the JavaScript runtime environment uses the SetValue method of the JintEngine class to configure the convenience method in the JSBridgeBehaviour component into the environment, specifically including:

[0036] Expand the first layer of data of the Config parameter;

[0037] If the value is a simple data type, use the SetValue method of the JintEngine class to set it as a global variable. The variable name is the corresponding field name in Config.

[0038] If the value is a JSON object or array, a JavaScript script code is generated first, and then the Execute method of the JintEngine class is used to execute the script code to generate a global variable.

[0039] Optionally, the JavaScript code module running on the browser transmits JavaScript code information required to be executed to the Unity scene through JSBridgeSDK, specifically including:

[0040] Construct a UnityInstance object and initialize it;

[0041] Call SendMessage of the UnityInstance object to send a message to Unity, passing the address where the JavaScript code content required to be executed is stored.

[0042] Optionally, the Unity scene uses JSBridgeObject to execute the JavaScript code required to be executed, specifically including:

[0043] Name the object in the Unity scene JSBridge and add the JSBridgeBehaviour component;

[0044] Configure the bridge interface between JavaScript and Unity C# into the jslib file;

[0045] The JSBridgeBehaviour component imports the JavaScript method defined in the jslib file;

[0046] The JSBridgeBehaviour component calls the ExecJSUrl method to execute JavaScript code by specifying a URL address.

[0047] Optionally, the parameters of the ExecJSUrl method include a Config parameter, a JavaScriptUrl parameter and a Callback parameter. The Config parameter is a JSON object, and the first-level JSON variables therein will be configured by the JSBridgeBehaviour component as JavaScript variables that can be directly used in JavaScriptContent; the JavaScriptUrl parameter is the URL address of the JavaScript code to be executed; the Callback parameter is the callback method triggered in the JavaScript code to be executed in the JavaScriptContent parameter;

[0048] The JSBridgeBehaviour component calls the ExecJSUrl method to execute JavaScript code by specifying the URL address, specifically including:

[0049] Download the JavaScript code content to be executed under the URL address in the JavaScriptUrl parameter;

[0050] Call the ExecJSContent method to directly execute the downloaded JavaScript code.

[0051] The present invention also provides a computer device, comprising a memory, a processor, and computer-readable instructions stored in the memory and running on the processor, wherein the processor implements the above-mentioned Web client JavaScript calling Unity scene method when executing the computer-readable instructions.

[0052] The above-mentioned Web client JavaScript calls the Unity scene method, including: the JavaScript code module running on the browser side transmits a JavaScript code to the JSBridgeObject in the Unity scene for execution, and if there is a return result, the result is returned from the C# callback through the agreed JavaScript method; the JavaScript code module running on the browser side transmits a URL address of a JavaScript code to the JSBridgeObject in the Unity scene, and the JavaScript code is downloaded and executed by JSBridgeObject. If there is a return result, the result is returned from the C# callback through the agreed JavaScript method; the JavaScript code module running on the browser side can provide the JavaScript runtime environment of the JSBridgeObject in the Unity scene with initialization JavaScript code to realize some value transmission functions. Through the present invention, the front end (such as the browser) can flexibly access and operate the objects (such as GameObject) in the Unity scene and call the functions of the object components through JavaScript code. For example, using the Unity SDK to find objects (such as GameObject) in the scene, control the display and hiding of objects, manipulate the movement, rotation, animation, etc. of objects, and can also directly call the methods of the associated components of the objects, which is equivalent to the UnityInstance.SendMessage(objectName, methodName, value) function provided by Unity WebGL. The present invention enables JavaScript running on the browser to flexibly call Unity SDK functions and implement scene functions through JavaScript codes. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 It is a schematic diagram of the process of calling the Unity scene method by the Web client JavaScript in one embodiment of the present invention;

[0054] Figure 2 It is a schematic diagram of the technical framework of the present invention;

[0055] Figure 3 is a schematic diagram of a computer device in one embodiment of the present invention. DETAILED DESCRIPTION

[0056] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0057] The terms used in one or more embodiments of the present invention are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present invention. The singular forms of "a", "said" and "the" used in one or more embodiments of the present invention are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of the present invention refers to and includes any or all possible combinations of one or more associated listed items.

[0058] Unity WebGL is developed in combination with front-end technology, and the front-end technology is used to cover the UI interface developed by the front-end on the Unity scene. Under such a technical framework, there are application scenarios where Unity C# code calls functions implemented by JavaScript on the front-end, such as feedback to the front-end page after clicking on the GameObject in the Unity scene. In this case, the mechanism provided by Unity WebGL can be used in the C# function code to call the pre-defined JavaScript method to implement this function. Conversely, there are also application scenarios where JavaScript can call functions implemented by Unity C#. In this case, Unity WebGL can be used to provide UnityInstance.SendMessage(objectName, methodName, value), where UnityInstance is the JavaScript instance created by Unity WebGL, objectName is the object name in the Unity scene, methodName is the method name of the script associated with the object named objectName, and value is the parameter passed to the method named methodName, which can only be a basic data type, such as a string, a number, or null.

[0059] In the mechanism provided by Unity WebGL for JavaScript to call Unity C# methods, there is a close binding relationship between the objects in the scene and the methods of the object's script. Basically, every time a specific function is called, it is necessary to add a corresponding function to the script of the corresponding C# object, which makes it difficult to call Unity functions flexibly.

[0060] Explanation of terms used in this application:

[0061] JavaScript: A just-in-time compiled programming language that can be used to develop web pages and non-browser applications.

[0062] WebGL: A Web Graphics Library that allows JavaScript and OpenGL ES to be combined to provide hardware 3D accelerated rendering for HTM5 Canvas, allowing Web applications to display 3D scenes more smoothly in the browser with the help of the system display, and to create complex navigation and data visualization.

[0063] Jint: A JavaScript interpreter designed for the .NET platform that can run on .NET platforms such as NET Standard 2.0 and .NET 4.6.2.

[0064] Unity WebGL: A publishing platform for the Unity engine that can publish games or applications developed by Unity to web browsers. Unity WebGL can display scenes, animations, and effects on the Web, and can interact with other web page elements through JavaScript.

[0065] In view of the above problems, the present invention provides the following embodiments. Specifically, in one embodiment, Figure 1 As shown, Figure 1 The figure is a flow chart of a method for calling a Unity scene using JavaScript from a Web client in one embodiment of the present invention. The embodiment of the present invention provides a method for calling a Unity scene using JavaScript from a Web client, including steps S100 to S300:

[0066] Step S100: The JavaScript code module running on the browser transmits the JavaScript code information required to be executed to the Unity scene through JSBridgeSDK.

[0067] It should be noted that JSBridgeSDK encapsulates the ability to execute specified JavaScript code through the script of the JSBridgeObject object. Unity SDK classes, scene objects, component functions, etc. can be directly used in the specified JavaScript code module.

[0068] Step S200: The Unity scene uses JSBridgeObject to execute the JavaScript code that is required to be executed.

[0069] It should be noted that JSBridgeObject is a GameObject object used to bridge JavaScript and C# in the Unity scene. There is only one JSBridgeObject object in the running scene.

[0070] Step S300: If there is a result returned, the result is transmitted back to the browser from the C# callback function in the Unity scene through the agreed JavaScript method.

[0071] It should be noted that, in the specific implementation, the components in JSBridgeObject agree with JSBridgeSDK on the method for the JavaScript running in Unity to call back the browser JavaScript.

[0072] Through the embodiments of the present invention, the front end (e.g., browser end) can flexibly access and operate objects (e.g., GameObject) in the Unity scene and call the functions of object components through JavaScript code. For example, UnitySDK can be used to find objects in the scene, control the display and hiding of objects, manipulate the movement, rotation, and animation of objects, etc., and methods of components associated with objects can also be directly called, which is equivalent to the UnityInstance.SendMessage(objectName, methodName, value) function provided by Unity WebGL. The present invention enables JavaScript running on the browser end to flexibly call Unity SDK functions and implement scene functions through JavaScript code.

[0073] In one embodiment, step S100, the JavaScript code module running on the browser transmits JavaScript code information required to be executed to the Unity scene through JSBridgeSDK, specifically including:

[0074] Step S110, constructing a UnityInstance object and initializing it;

[0075] Step S120, calling SendMessage of the UnityInstance object to send a message to Unity, passing the JavaScript code content required to be executed.

[0076] It should be noted that the UnityInstance object sends messages to Unity through the SendMessage function, which can realize the transmission of JavaScript code content.

[0077] In one embodiment, step S200, the Unity scene uses JSBridgeObject to execute the JavaScript code required to be executed, which specifically includes steps S210-S240.

[0078] Step S210, name the object in the Unity scene as JSBridge, and add the JSBridgeBehaviour component.

[0079] It should be noted that JSBridgeBehaviour is the script component of JSBridgeObject, which implements some commonly used Unity scene and object operation methods internally. It can be used directly in JavaScript code to reduce the amount of JavaScript code and realize the mechanism of JavaScript code event transmission back to JSBridgeSDK.

[0080] Step S220, configuring the bridge interface between JavaScript and Unity C# into the jslib file.

[0081] It should be noted that the jslib file is a text file with the extension .jslib. In order to realize the bridge between JavaScript and Unity C#, the bridge interface needs to be configured in a text file with the extension .jslib. As an example, the text file format of .jslib is:

[0082] mergeInto(LibraryManager.library, {

[0083] callJsBackcall: function(callbackname, packageData){ ...

[0084] }

[0085] });

[0086] Step S230, the JSBridgeBehaviour component imports the JavaScript method defined in the jslib file.

[0087] As an example, the way is:

[0088] [DllImport("__Internal")]

[0089] private static extern void callJsBackcall(string callbackname, stringpackageData);

[0090] Step S240, the JSBridgeBehaviour component calls the ExecJSContent method to directly execute the JavaScript code.

[0091] As an example, the method for JSBridgeBehaviour to implement the JSBridgeSDK call is:

[0092] void ExecJsContent(string, string, string).

[0093] In one embodiment, the parameters of the ExecJSContent method include a Config parameter, a JavaScriptContent parameter, and a Callback parameter, namely:

[0094] ExecJSContent(Config, JavaScriptContent, Callback).

[0095] The Config parameter is a JSON object. The first-level JSON variables in it will be configured by the JSBridgeBehaviour component as JavaScript variables that can be directly used in the JavaScriptContent parameter, thereby achieving the effect of passing values ​​from the browser's JavaScript to the JavaScript code executed in Unity.

[0096] The JavaScriptContent parameter is the JavaScript code to be executed. It should be noted that the code cannot be too long and must be within the limit of the UnityInstance.SendMessage parameter.

[0097] The Callback parameter is the callback method triggered by the JavaScript code to be executed in the JavaScriptContent parameter, which can be used to update the browser page content.

[0098] Step S240, the JSBridgeBehaviour component calls the ExecJSContent method to directly execute the JavaScript code, specifically including steps S241~S243.

[0099] Step S241, create a JintEngine instance, configure it to allow all access controls, and set the language environment.

[0100] As an example, specifically:

[0101] var CN = CultureInfo.GetCultureInfo("zh-CN");

[0102] engine = new Engine(options =>{

[0103] options .AllowClr();

[0104] options.Culture(CN);

[0105] });

[0106] Step S242, initialize the JavaScript operating environment.

[0107] Step S243, calling the Execute method of the JintEngine class to execute the JavaScript code to be executed in the JavaScriptContent parameter.

[0108] It should be noted that JintEngine is a JavaScript interpreter for .NET that supports the Unity WebGL platform. Unit WebGL Library is a JavaScript library embedded in the build package after the Unity application is published as Unty WebGL. The JintEngine engine is built in ExecJsContent so that each call to ExecJsContent is an independent JavaScript runtime environment, and JavaScript code is executed inside this ExecJsContent.

[0109] In one embodiment, step S242, initializing the JavaScript operating environment, specifically includes steps S2421-S2422.

[0110] Step S2421, use the SetValue method of the JintEngine class to configure the convenience method in the JSBridgeBehaviour component into the environment.

[0111] Step S2422, setting the JavaScript callback browser-side JavaScript callback method.

[0112] As an example, specifically:

[0113] JintEngine.SetValue("CallJsBackcall", new Action <string>(data =>this.CallJsBackcall(jscallid, data)).

[0114] CallJsBackcall is a method in JsBridgeBehaviour, and jscallid is the call ID when the browser calls this JavaScript. JSBridgeSDK can use it to retrieve the corresponding callback method.

[0115] In one embodiment, step S2421 initializes the JavaScript runtime environment, and uses the SetValue method of the JintEngine class to configure the convenience method in the JSBridgeBehaviour component into the environment, specifically including steps S24211 to S24213.

[0116] Step S24211, expand the first layer data of the Config parameter.

[0117] Step S24212, if the value is a simple data type, directly use the SetValue method of the JintEngine class to set it as a global variable, and the variable name is the corresponding field name in Config.

[0118] Step S24213, if the value is a JSON object or array, generate a JavaScript script code first, and then use the Execute method of the JintEngine class to execute the script code to generate a global variable.

[0119] As an example, the JavaScript script code is:

[0120] var jsonstr= <jsonstring>

[0121] window. <varname>=JSON.parse(jsonstr)

[0122] in, <jsonstring>It is a JSON object or array string in Config. <varname>It is the field name in Config.

[0123] In one embodiment, step S100, the JavaScript code module running on the browser transmits JavaScript code information required to be executed to the Unity scene through JSBridgeSDK, which specifically includes another set of steps:

[0124] Step S110', construct a UnityInstance object and initialize it;

[0125] Step S120', calling SendMessage of the UnityInstance object to send a message to Unity, passing the address where the JavaScript code content required to be executed is stored.

[0126] It should be noted that the UnityInstance object sends messages to Unity through the SendMessage function, which can realize the transfer of JavaScript code addresses.

[0127] In one embodiment, step S200, the Unity scene uses JSBridgeObject to execute the JavaScript code required to be executed, which specifically includes another set of steps S210'-S240'.

[0128] Step S210', name the object in the Unity scene as JSBridge, and add a JSBridgeBehaviour component. This is the same as the above step S210.

[0129] Step S220', configure the bridge interface between JavaScript and Unity C# into the jslib file. This is the same as the above step S220.

[0130] Step S230', the JSBridgeBehaviour component imports the JavaScript method defined in .jslib. This is the same as the above step S230.

[0131] Step S240', the JSBridgeBehaviour component calls the ExecJSUrl method to execute the JavaScript code by specifying the URL address.

[0132] As an example, the method for JSBridgeBehaviour to implement the JSBridgeSDK call is:

[0133] Void ExecJsUrl(string, string, string).

[0134] In one embodiment, the parameters of the ExecJSUrl method include a Config parameter, a JavaScriptUrl parameter, and a Callback parameter, namely:

[0135] ExecJSUrl(Config, JavaScriptUrl, Callback).

[0136] The Config parameter is a JSON object. The first-level JSON variables in it will be configured by the JSBridgeBehaviour component as JavaScript variables that can be directly used in JavaScriptContent, achieving the effect of passing values ​​from the browser's JavaScript to the JavaScript code executed in Unity.

[0137] The JavaScriptUrl parameter is the URL address of the JavaScript code to be executed. The JSBridgeBehaviour component downloads the JavaScript code from this address for execution.

[0138] The Callback parameter is the callback method triggered by the JavaScript code to be executed in the JavaScriptContent parameter, which can be used to update the browser page content.

[0139] Step S240', the JSBridgeBehaviour component calls the ExecJSUrl method to execute the JavaScript code by specifying the URL address, which specifically includes steps S241' to S242':

[0140] Step S241', download the JavaScript code content to be executed under the URL address in the JavaScriptUrl parameter.

[0141] It should be noted that UnityWebRequest can be used to download JavaScriptUrl content so that it can be downloaded normally when the C# code is compiled into WebGL platform code.

[0142] Step S242', calling the ExecJSContent method to directly execute the downloaded JavaScript code. The specific implementation method is the same as the above steps S210-S240.

[0143] Figure 2 It is a schematic diagram of the technical framework of the present invention, wherein:

[0144] JSBridgeSDK encapsulates the ability to execute specified JavaScript code through the script of the JSBridgeObject object. In the specified JavaScript code module, you can directly use Unity SDK classes, scene objects, component functions, etc.;

[0145] JSBridgeObject is a GameObject object used to bridge JavaScript and C# in the Unity scene. There is only one JSBridgeObject object in the running scene.

[0146] JSBridgeBehaviour is a script component of JSBridgeObject. It implements some commonly used Unity scenes and object operation methods, which can be used directly in JavaScript code to reduce the amount of JavaScript code. It implements the mechanism of JavaScript code events passing back to JSBridgeSDK;

[0147] JintEngine is a Javascript interpreter for .NET engine that supports the Unity WebGL platform;

[0148] Unit WebGL Library is a JavaScript library that is embedded into the build package after the Unity application is published as Unity WebGL.

[0149] The above-mentioned Web client JavaScript calls the Unity scene method, including: the JavaScript code module running on the browser side transmits a JavaScript code to the JSBridgeObject in the Unity scene for execution, and if there is a return result, the result is returned from the C# callback through the agreed JavaScript method; the JavaScript code module running on the browser side transmits a URL address of a JavaScript code to the JSBridgeObject in the Unity scene, and the JavaScript code is downloaded and executed by JSBridgeObject. If there is a return result, the result is returned from the C# callback through the agreed JavaScript method; the JavaScript code module running on the browser side can provide the JavaScript runtime environment of the JSBridgeObject in the Unity scene with initialization JavaScript code to realize some value transmission functions. Through the present invention, the front end (such as the browser) can flexibly access and operate the objects (such as GameObject) in the Unity scene and call the functions of the object components through JavaScript code. For example, using the Unity SDK to find objects (such as GameObject) in the scene, control the display and hiding of objects, manipulate the movement, rotation, animation, etc. of objects, and can also directly call the methods of the associated components of the objects, which is equivalent to the UnityInstance.SendMessage(objectName, methodName, value) function provided by Unity WebGL. The present invention enables JavaScript running on the browser to flexibly call Unity SDK functions and implement scene functions through JavaScript codes.

[0150] In one embodiment, a computer device is provided. The computer device may be a server or a personal terminal. The internal structure diagram thereof may be as follows: Figure 3 As shown, Figure 3 : is a schematic diagram of a computer device in one embodiment of the present invention. The computer device includes a processor, a memory, a network interface and a database connected by a device bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a readable storage medium and an internal memory. The readable storage medium stores an operating device, a computer-readable instruction and a database. The internal memory provides an environment for the operation of the operating device and the computer-readable instructions in the readable storage medium. The database of the computer device is used to store data involved in the device intelligent scheduling upgrade method. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer-readable instruction is executed by the processor, a vehicle entry control method is implemented. The readable storage medium provided in this embodiment includes a non-volatile readable storage medium and a volatile readable storage medium.

[0151] In one embodiment, a computer device is provided, including a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, and when the processor executes the computer-readable instructions, the steps of calling the Unity scene method by the Web client JavaScript are implemented as described above. The method includes: the JavaScript code module running on the browser transmits the JavaScript code information required to be executed to the Unity scene through JSBridgeSDK; the Unity scene executes the JavaScript code required to be executed using JSBridgeObject; if there is a return result, the result is transmitted back to the browser from the C# callback function in the Unity scene through the agreed JavaScript method.

[0152] In one embodiment, a readable storage medium is provided, and the readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the method of calling the Unity scene by the Web client JavaScript as described above are implemented. A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a non-volatile readable storage medium or a volatile readable storage medium. When the computer-readable instructions are executed, they may include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0153] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0154] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.< / varname> < / jsonstring> < / varname> < / jsonstring> < / string>

Claims

1. A Web client JavaScript calls a Unity scene method, including: The JavaScript code module running on the browser transmits the JavaScript code information required to be executed to the Unity scene through JSBridgeSDK; The Unity scene uses JSBridgeObject to execute the JavaScript code that is required to be executed. JSBridgeObject is a GameObject object used to bridge JavaScript and C# in the Unity scene. The components in JSBridgeObject agree with JSBridgeSDK on the method for the JavaScript running in Unity to call back the browser JavaScript. If there is a result returned, it is transmitted from the C# callback function in the Unity scene to the browser through the agreed JavaScript method; The JavaScript code module running on the browser transmits the JavaScript code information required to be executed to the Unity scene through JSBridgeSDK, specifically: Construct a UnityInstance object and initialize it; Calling SendMessage of the UnityInstance object to send a message to Unity, passing the JavaScript code content required to be executed; The Unity scene uses JSBridgeObject to execute the JavaScript code required to be executed, specifically including: Name the object in the Unity scene JSBridge and add the JSBridgeBehaviour component. JSBridgeBehaviour is the script component of JSBridgeObject, which implements common Unity scene and object operation methods. Configure the bridge interface between JavaScript and Unity C# into the jslib file; The JSBridgeBehaviour component imports the JavaScript method defined in the jslib file; The JSBridgeBehaviour component calls the ExecJSContent method to directly execute JavaScript code; The parameters of the ExecJSContent method include a Config parameter, a JavaScriptContent parameter, and a Callback parameter. The Config parameter is a JSON object, and the first-level JSON variables therein will be configured by the JSBridgeBehaviour component as JavaScript variables directly used in the JavaScriptContent parameter; the JavaScriptContent parameter is the JavaScript code to be executed; the Callback parameter is the callback method triggered in the JavaScript code to be executed in the JavaScriptContent parameter; The JSBridgeBehaviour component calls the ExecJSContent method to directly execute JavaScript code, specifically including: Create a JintEngine instance, configure it to allow all access controls, and set the locale; Initialize the JavaScript runtime environment; The Execute method of the JintEngine class is called to execute the JavaScript code to be executed in the JavaScriptContent parameter.

2. A Web client JavaScript calling Unity scene method according to claim 1, characterized in that: The initialization of the JavaScript operating environment is specifically as follows: Use the SetValue method of the JintEngine class to configure the convenience method in the JSBridgeBehaviour component to the environment; Set JavaScript callback browser-side JavaScript callback method.

3. A Web client JavaScript calling Unity scene method according to claim 2, characterized in that: The initialization of the JavaScript runtime environment uses the SetValue method of the JintEngine class to configure the convenient method in the JSBridgeBehaviour component into the environment, specifically including: Expand the first layer of data of the Config parameter; If the value is a simple data type, use the SetValue method of the JintEngine class to set it as a global variable. The variable name is the corresponding field name in Config. If the value is a JSON object or array, a JavaScript script code is generated first, and then the Execute method of the JintEngine class is used to execute the script code to generate a global variable.

4. A Web client JavaScript calls a Unity scene method, including: The JavaScript code module running on the browser transmits the JavaScript code information required to be executed to the Unity scene through JSBridgeSDK; The Unity scene uses JSBridgeObject to execute the JavaScript code that is required to be executed. JSBridgeObject is a GameObject object used to bridge JavaScript and C# in the Unity scene. The components in JSBridgeObject agree with JSBridgeSDK on the method for the JavaScript running in Unity to call back the browser JavaScript. If there is a result returned, it is transmitted from the C# callback function in the Unity scene to the browser through the agreed JavaScript method; The JavaScript code module running on the browser transmits the JavaScript code information required to be executed to the Unity scene through JSBridgeSDK, specifically including: Construct a UnityInstance object and initialize it; Calling SendMessage of the UnityInstance object to send a message to Unity, passing the address of the JavaScript code content required to be executed; the Unity scene uses JSBridgeObject to execute the JavaScript code required to be executed, specifically including: Name the object in the Unity scene JSBridge and add the JSBridgeBehaviour component. JSBridgeBehaviour is the script component of JSBridgeObject, which implements common Unity scene and object operation methods. Configure the bridge interface between JavaScript and Unity C# into the jslib file; The JSBridgeBehaviour component imports the JavaScript method defined in the jslib file; The JSBridgeBehaviour component calls the ExecJSUrl method to execute JavaScript code by specifying the URL address; The parameters of the ExecJSUrl method include a Config parameter, a JavaScriptUrl parameter, and a Callback parameter. The Config parameter is a JSON object, and the first-level JSON variables therein will be configured by the JSBridgeBehaviour component as JavaScript variables directly used in JavaScriptContent; the JavaScriptUrl parameter is the URL address of the JavaScript code to be executed; the Callback parameter is the callback method triggered in the JavaScript code to be executed in the JavaScriptContent parameter; The JSBridgeBehaviour component calls the ExecJSUrl method to execute JavaScript code by specifying the URL address, specifically including: Download the JavaScript code content to be executed under the URL address in the JavaScriptUrl parameter; Call the ExecJSContent method to directly execute the downloaded JavaScript code; The parameters of the ExecJSContent method include a Config parameter, a JavaScriptContent parameter, and a Callback parameter. The Config parameter is a JSON object, and the first-level JSON variables therein will be configured by the JSBridgeBehaviour component as JavaScript variables directly used in the JavaScriptContent parameter; the JavaScriptContent parameter is the JavaScript code to be executed; the Callback parameter is the callback method triggered in the JavaScript code to be executed in the JavaScriptContent parameter; The calling of the ExecJSContent method directly executes the downloaded JavaScript code, specifically including: Create a JintEngine instance, configure it to allow all access controls, and set the locale; Initialize the JavaScript runtime environment; The Execute method of the JintEngine class is called to execute the JavaScript code to be executed in the JavaScriptContent parameter.

5. A computer device comprising a memory, a processor, and computer-readable instructions stored in the memory and executed on the processor, characterized in that: When the processor executes the computer-readable instructions, the method of calling a Unity scene by a Web client JavaScript as described in any one of claims 1 to 4 is implemented.