From what I read so far, it is impossible. But hey, impossible is nothing! hum…
Well, here’s the issue:
I have a Javascript Class static that let me access its Methods from C#. Let’s call this static class MyClass ( so innovative ).
Here’s what I have in it:
function MyCallbackWrapper( callback: function() : void )
{
callback();
}
function MyCallbackWrapper( callback: function() : IEnumerator )
{
StartCoroutine( callback() );
}
And let’s say I have a C# Script that does this:
void Start ()
{
MyClass.Get().MyCallbackWrapper( TestVoid );
//MyClass.Get().MyCallbackWrapper( TestIEnumerator );
}
public void TestVoid( )
{
print ("MyVoid");
}
public IEnumerator TestIEnumerator( )
{
print ("MyIEnum");
yield return 0;
}
But the compilator throws: The call is ambiguous between the following methods or properties.
The two ambiguous methods are MyCallbackWrapper from the JS Class.
So now, why does it happens?
Long story short, in fact I first tried to do MyClass in C# but hitted a wall. In C# it looked like this:
void MyCallbackWrapper( System.Action callback )
{
callback();
}
void MyCallbackWrapper( System.Func<IEnumerator> callback )
{
StartCoroutine( callback() );
}
Which was throwing the same error : The call is ambiguous and stuff.
So, this error occurs in fact because the compilator cannot distingish the 2 methods, because the return type is not included in the process to get a unique method signature.
(c# - Compiler Ambiguous invocation error - anonymous method and method group with Func<> or Action - Stack Overflow)
Sooo! I thought that maybe UnityScript would handle things diferently. But not. I tried to use Function type instead, but the compilator wasn’t able to translate it for the C#.
Well, that was a lot to say, but here is what I’m searching now.
Option1: Despite the fact that I’ve searched for lots of “hacks” to make these 2 function non ambiguous, I didn’t find anything, but maybe I missed something. So if someone knows a trick, my eyes are wide open.
Option2: Dirtier but if this is the only thing possible I don’t mind : Use Reflection. But I’m at level extra noob on this one so I’ll need some help.
Option3 : It is possible to do it in Boo Edit: NOT WORKING
That was a dang long post, I you arrived at this line, I have to thank you for reading me. And if you have a solution, I’d probably make special wish for you next time I’ll see a shooting star.