I’m trying to port my app to WP8, but my project uses the Facebook SDK and Game Analytics (for iOS and Android). With Game Analytics, I simply unchecked the GA_SystemTracker, but I don’t have an object in the scene view with any Facebook components added. The FB.Init code is not called on a WP8 build, but the compiler complains about FB,cs. The only work around I’ve found so far is to #IF UNITY_IPHONE || UNITY ANDROID
in each function. I can’t do the entire class, as other scripts reference it. My concern with this method is also that the plugin is still updated fairly regularly. Is there a better way to do this?
We use a “FacebookService” interface here. All our scripts use this interface to interact with Facebook. They do not use the Facebook SDK directly.
We have two classes that implements FacebookService. A RealFacebookService and a FakeFacebookService.
This code isn’t as robust as our ServiceManager, but it’s an example on how to abstract out the real Facebook SDK.
public class ServiceManager {
public FacebookService facebook {
get {
if (m_facebookService == null) {
#if UNITY_METRO || UNITY_WP8
m_facebookService = new FakeFacebookService();
#else
// I'm sure this isn't how the actual Facebook SDK is initialized.
m_facebookService = new RealFacebookService();
#endif
}
}
}
private FacebookService m_facebook;
}
We will usually write a wrapper interface for anything that needs different versions for different platforms. This way only our ServiceManager needs to know the platform, everything else can just rely on the interface.