コード例 #1
0
    private static void OnDllLoaded()
    {
        var versionInfo = FBBuildVersionAttribute.GetVersionAttributeOfType(FacebookImpl.GetType());

        if (versionInfo == null)
        {
            FbDebug.Warn("Finished loading Facebook dll, but could not find version info");
        }
        else
        {
            FbDebug.Log(string.Format("Finished loading Facebook dll. Version {0} Build {1}", versionInfo.SdkVersion, versionInfo.BuildVersion));
        }
        FacebookImpl.Init(
            OnInitComplete,
            appId,
            cookie,
            logging,
            status,
            xfbml,
            FBSettings.ChannelUrl,
            authResponse,
            frictionlessRequests,
            OnHideUnity
            );
    }
コード例 #2
0
 public static void Warn(string msg)
 {
     if (allowLogging)
     {
         FbDebug.Warn(msg);
     }
 }
コード例 #3
0
ファイル: FB.cs プロジェクト: issamux/Sample-App-Unity
    /**
     * onInitComplete - Delegate is called when FB.Init() finished initializing everything.
     *                  By passing in a delegate you can find out when you can safely call the other methods.
     */
    public static void Init(Facebook.InitDelegate onInitComplete, Facebook.HideUnityDelegate onHideUnity = null, string authResponse = null)
    {
        if (!isInitCalled)
        {
            FB.authResponse   = authResponse;
            FB.OnInitComplete = onInitComplete;
            FB.OnHideUnity    = onHideUnity;

            FbDebug.Info(String.Format("Using SDK {0}, Build {1}", FBBuildVersionAttribute.SDKVersion, FBBuildVersionAttribute.GetBuildVersionOfType(typeof(IFacebook))));

#if UNITY_EDITOR
            FBComponentFactory.GetComponent <EditorFacebookLoader>();
#elif UNITY_WEBPLAYER
            FBComponentFactory.GetComponent <CanvasFacebookLoader>();
#elif UNITY_IOS
            FBComponentFactory.GetComponent <IOSFacebookLoader>();
#elif UNITY_ANDROID
            FBComponentFactory.GetComponent <AndroidFacebookLoader>();
#else
            throw new NotImplementedException("Facebook API does not yet support this platform");
#endif
            FB.isInitCalled = true;
            return;
        }

        FbDebug.Warn("FB.Init() has already been called.  You only need to call this once and only once.");

        // Init again if possible just in case something bad actually happened.
        if (FacebookImpl != null)
        {
            OnDllLoaded();
        }
    }
コード例 #4
0
    /**
     * If you need a more programmatic way to set the facebook app id and other setting call this function.
     * Useful for a build pipeline that requires no human input.
     */
    public static void Init(
        InitDelegate onInitComplete,
        string appId,
        bool cookie  = true,
        bool logging = true,
        bool status  = true,
        bool xfbml   = false,
        bool frictionlessRequests     = true,
        HideUnityDelegate onHideUnity = null,
        string authResponse           = null)
    {
        FB.appId   = appId;
        FB.cookie  = cookie;
        FB.logging = logging;
        FB.status  = status;
        FB.xfbml   = xfbml;
        FB.frictionlessRequests = frictionlessRequests;
        FB.authResponse         = authResponse;
        FB.OnInitComplete       = onInitComplete;
        FB.OnHideUnity          = onHideUnity;

        if (!isInitCalled)
        {
            var versionInfo = FBBuildVersionAttribute.GetVersionAttributeOfType(typeof(IFacebook));

            if (versionInfo == null)
            {
                FbDebug.Warn("Cannot find Facebook SDK Version");
            }
            else
            {
                FbDebug.Info(String.Format("Using SDK {0}, Build {1}", versionInfo.SdkVersion, versionInfo.BuildVersion));
            }

#if UNITY_EDITOR
            FBComponentFactory.GetComponent <EditorFacebookLoader>();
#elif UNITY_WEBPLAYER
            FBComponentFactory.GetComponent <CanvasFacebookLoader>();
#elif UNITY_IOS
            FBComponentFactory.GetComponent <IOSFacebookLoader>();
#elif UNITY_ANDROID
            FBComponentFactory.GetComponent <AndroidFacebookLoader>();
#elif UNITY_WP8
            FBComponentFactory.GetComponent <WindowsPhoneFacebookLoader>();
#else
            throw new NotImplementedException("Facebook API does not yet support this platform");
#endif
            isInitCalled = true;
            return;
        }

        FbDebug.Warn("FB.Init() has already been called.  You only need to call this once and only once.");

        // Init again if possible just in case something bad actually happened.
        if (FacebookImpl != null)
        {
            OnDllLoaded();
        }
    }
コード例 #5
0
        public override void Login(string scope = "", FacebookDelegate callback = null)
        {
            if (isLoggedIn)
            {
                FbDebug.Warn("User is already logged in.  You don't need to call this again.");
            }

            userId      = "0";
            accessToken = "abcdefghijklmnopqrstuvwxyz";
            isLoggedIn  = true;
        }
コード例 #6
0
        public override void API(
            string query,
            HttpMethod method,
            Dictionary <string, string> formData = null,
            FacebookDelegate callback            = null)
        {
            if (query.StartsWith("me"))
            {
                FbDebug.Warn("graph.facebook.com/me does not work within the Unity Editor");
            }

            if (!query.Contains("access_token=") && (formData == null || !formData.ContainsKey("access_token")))
            {
                FbDebug.Warn("Without an access_token param explicitly passed in formData, some API graph calls will 404 error in the Unity Editor.");
            }
            fb.API(query, method, formData, callback);
        }
コード例 #7
0
        public static void UpdateManifest(string fullPath)
        {
            string appId = FBSettings.AppId;

            if (!FBSettings.IsValidAppId)
            {
                Debug.LogError("You didn't specify a Facebook app ID.  Please add one using the Facebook menu in the main Unity editor.");
                return;
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(fullPath);

            if (doc == null)
            {
                Debug.LogError("Couldn't load " + fullPath);
                return;
            }

            XmlNode manNode = FindChildNode(doc, "manifest");
            XmlNode dict    = FindChildNode(manNode, "application");

            if (dict == null)
            {
                Debug.LogError("Error parsing " + fullPath);
                return;
            }

            string ns = dict.GetNamespaceOfPrefix("android");

            //change
            //<activity android:name="com.unity3d.player.UnityPlayerProxyActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
            //to
            //<activity android:name="com.facebook.unity.FBUnityPlayerActivity" android:launchMode="singleTask" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" android:screenOrientation="portrait">
            XmlElement mainActivity     = FindMainActivityNode(dict);
            var        mainActivityName = mainActivity.GetAttribute("name", ns);

            if (mainActivityName != "com.unity3d.player.UnityPlayerProxyActivity" &&
                mainActivityName != "com.unity3d.player.UnityPlayerNativeActivity" &&
                mainActivityName != ActivityName)
            {
                FbDebug.Warn("FBUnityPlayerActivity was not detected as the main activity in the AndroidManifest.xml!  Be sure to have your activity extend " + ActivityName + " for the Facebook SDK to work");
            }
            else
            {
                mainActivity.SetAttribute("name", ns, ActivityName);
            }

            //add the login activity
            //<activity android:name="com.facebook.LoginActivity" android:screenOrientation="portrait" android:configChanges="keyboardHidden|orientation">
            //</activity>
            XmlElement loginElement = FindElementWithAndroidName("activity", "name", ns, "com.facebook.LoginActivity", dict);

            if (loginElement == null)
            {
                loginElement = doc.CreateElement("activity");
                loginElement.SetAttribute("name", ns, "com.facebook.LoginActivity");
                loginElement.SetAttribute("screenOrientation", ns, "portrait");
                loginElement.SetAttribute("configChanges", ns, "keyboardHidden|orientation");
                loginElement.InnerText = "\n    ";  //be extremely anal to make diff tools happy
                dict.AppendChild(loginElement);
            }

            //add the app id
            //<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="\ 409682555812308" />
            XmlElement appIdElement = FindElementWithAndroidName("meta-data", "name", ns, "com.facebook.sdk.ApplicationId", dict);

            if (appIdElement == null)
            {
                appIdElement = doc.CreateElement("meta-data");
                appIdElement.SetAttribute("name", ns, "com.facebook.sdk.ApplicationId");
                dict.AppendChild(appIdElement);
            }
            appIdElement.SetAttribute("value", ns, "\\ " + appId); //stupid hack so that the id comes out as a string

            doc.Save(fullPath);
        }