I’m writing a WIndows Facebook Universal App Plugin. I’m almost done, but I’ve got a problem. I need to invoke certain stuff on the Unity Thread (because callbacks made in Unity usually needs to be ran on the Unity Thread, since they usually involve manipulating GameObjects).
I managed to do this by referencing the UnityPlayer.winmd file and calling “UnityPlayer.AppCallbacks.Instance.InvokeOnAppThread(…)”. But by referencing that library (UnityPlayer.winmd) my plugin is no longer “portable”, it complains about the .winmd file only being built for x86 while i target ARM and x86. I changed it to only compile for x86 and it works, but naturally it won’t work for both desktop and phones.
Is there any way to access the Unity Thread without the UnityPlayer.dll? For example, maybe get current thread (in a normal call), cache the thread and then execute on it? Or any other, more natural way?
Thank you!
Thank you Tomas. I was thinking of a solution on the “native” side. For the same reason as I mentioned I can’t reference UnityEngine.dll since there is no “portable” version of it. If I understand you correctly you would want be to do something like this:
FB.Login(()=>{
Application.InvokeOnAppThread(()=>{
//Do some Unity specific stuff
}, false);
});
I ended up creating an Interface called UnityThread in the Facebook Plugin (FacebookPlugin.dll):
public interface UnityThread
{
void InvokeOnAppThread(Action callback);
void InvokeOnUIThread(Action callback);
}
Then in the Unity Project I create a class named UnityThread:
public class UnityThread : FB.UnityThread
{
public void InvokeOnAppThread(Action callback)
{
UnityPlayer.AppCallbacks.Instance.InvokeOnAppThread(new UnityPlayer.AppCallbackItem(() =>
{
if (callback != null)
callback();
}), false);
}
//impl. of InvokeOnUIThread
}
Then in App.xaml.cs:
public App()
{
//Some code
//...
//...
ACE.WinRT.Facebook.FB.Init(new UnityThread());
}
I’m open for other suggestions if there are any better solutions.
Did you try referencing the one in PlaybackEngines\metrosupport\Managed\ ?
Thank you Tomas, that seems to have worked!