I have a small javascript class called Item (inherits from System.Object). I was wondering if there’s a way to create instances of Item in a C# class (so that they can be passed to other Javascript class instances).
I currently have a solution that works: I pair the C# instance with the following Javascript class (as components of the same GameObject):
class ObjectItem extends MonoBehaviour
{
// Create the new instance of Item, passing the
// GameObject to its constructor.
function GetNewItem() : Item
{
return new Item(gameObject);
}
}
I use reflection in C# to call GetNewItem() in the Javascript component, and pass the returned value (abstracted as System.Object) to other Javascript instances.
It works fine, but it would be simpler if I could create instances of Javascript class Item directly in C#.
Somewhat related, can static member functions in Javascript be called in C#, or vice versa?