[英]How to passing c# function as a param to UnityScript in unity?
I have a class using UnityScript like this: 我有一个使用UnityScript的类,如下所示:
public class Responder{
private var completeHandler:Function;
public function addHandlers(completeHandler:Function):void {
completeHandler();
}
}
Now, i want to use this class in c# code, 现在,我想在C#代码中使用此类,
public class MyGame : MonoBehaviour{
void Start(){
Responder res = new Responder();
res.addHandlers(?????); //how to pass the param??
}
}
Thanks! 谢谢!
Put the Javascript class in a folder called Plugins
under assets. 将Javascript类放在资产下名为
Plugins
的文件夹中。 You will be able to call the methods written in JS from C# scripts. 您将能够从C#脚本调用用JS编写的方法。
The type Function
in JS appears to me as Boo.Lang.ICallable
in C#. 在我看来,JS中的
Function
类型在C#中为Boo.Lang.ICallable
。 As I couldn't import Boo.Lang by default, I took the Boo.Lang.dll
from the Unity3D installed folder and copied it to the same Plugins
folder in the project, then adding using Boo.Lang;
由于默认情况下我无法导入Boo.Lang,因此我从Unity3D安装文件夹中
Boo.Lang.dll
,并将其复制到项目中的同一Plugins
文件夹中,然后using Boo.Lang;
进行添加using Boo.Lang;
at the top of my C# script. 在我的C#脚本的顶部。
You can now create and pass a new ICallable
type as an argument from C# to JS. 现在,您可以创建一个新的
ICallable
类型并将其作为参数从C#传递给JS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.