functionName | 要调用的函数的名称。 |
args | 调用中传递的参数数组。 |
在包含 WebGL 播放器的网页中调用函数。
ExternalCall
在包含 WebGL 播放器的网页中调用 ToString
,将给定的参数传递给它。支持的参数类型包括
原始类型(ToString
、ToString
、ToString
、ToString
)和这些类型的数组。任何其他对象
将使用 ToString
转换为 /string/,并以 string
形式传递。
The function is non-blocking; ExternalCall
immediately returns without waiting for the function that was called to complete.
The number of passed arguments can be varying:
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
void Example()
{
// Calls MyFunction1 in the web page with no arguments
Application.ExternalCall("MyFunction1");
// Calls MyFunction2 in the web page with a string
Application.ExternalCall("MyFunction2", "Hello from Unity!");
// Calls MyFunction3 in the web page with several arguments of different types
Application.ExternalCall("MyFunction3", "one", 2, 3.0F);
}
}
The functions to be called are declared in the HTML page using standard syntax, for example:
// This should be contained in the host page in the appropriate <script> element.
// Using the above call from Unity, this will receive
// "Hello from Unity!" as the argument.
function MyFunction2( arg )
{
alert( arg );
}
另请参阅:Application.ExternalEval。