Search code examples
c#unity-game-enginesystem.reflectionfacebook-unity-sdk

How to find out if Unity Facebook SDK is in the project?


I have this code:

m_FacebookVersion =  Facebook.Unity.FacebookSdkVersion.Build;

To get the version of Facebook, but I run into problems when Facebook doesn't exist. I can't find a Define to check against i.e. #if UNITY_EDITOR.

I also tried

Type myType = Type.GetType("Facebook.Unity.FacebookSdkVersion");

But myType returns null.

Any suggestions?

Thanks


Solution

  • After some digging, I came up with this:

            m_FacebookVersion = "N/A";
    
            Type myType = Type.GetType("Facebook.Unity.FacebookSdkVersion, Assembly-CSharp");
            if(myType != null)
            {
                PropertyInfo myProp = myType.GetProperty("Build");
                if(myProp != null)
                {
                    m_FacebookVersion = (string)myProp.GetValue(null, null);
                }
            }
    

    Seems I needed to look in a different Assembly.