How to inject dependancies written in C# into Unityscript?

Hi Guys,

I’ve been chasing my tail on this all day without finding a good solution.

I have a runtime script engine written in Unityscript to get around the fact that C# in Unity has no evail.

It works fine. I can use it as an object in my C# code and call it from my main code no problem.

The issue is that I want to expose an API to the game to the user written Unityscript that the .js engine compiles. The problem is that the ScriptEngine is compiled before the C# and apparently sets its visibility for other classes then so I cannot see my C# API static class from runtime evaluated code.

I can’t move the static API class to plugins because IT references the main game engine.

In pure jvascript we can create names spaces in objects and pass them in to the functional scope. Ive been trying to figure out how to do that but I can’t figure out how to get from the methods of a static C# type to a set of js Functions that can be called as properties of an API object.

Help?

I figured it out. I was basically trying too hard.

All I had to do was declare a var API in my Javascript ScriptEngine class and pass it a singleton of my API object in its constructor when making an instance from my C# code. Then in the engine, I passed the API object in as the first parameter to the script and invoke it as API.Methodname(params…) dynamically from Javascript.

Problem all solved :slight_smile: