简体   繁体   中英

How to passing c# function as a param to UnityScript in unity?

I have a class using UnityScript like this:

public class Responder{
    private var completeHandler:Function;

    public function addHandlers(completeHandler:Function):void {
        completeHandler();
    }
}

Now, i want to use this class in c# code,

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. You will be able to call the methods written in JS from C# scripts.

The type Function in JS appears to me as Boo.Lang.ICallable in C#. 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; at the top of my C# script.

You can now create and pass a new ICallable type as an argument from C# to JS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM