Exemplo n.º 1
0
    void ScoresCallback(FBResult result)
    {
        FbDebug.Log("ScoresCallback");
        if (result.Error != null)
        {
            FbDebug.Error(result.Error);
            return;
        }

        scores = new List <object>();
        List <object> scoresList = Util.DeserializeScores(result.Text);

        foreach (object score in scoresList)
        {
            var entry = (Dictionary <string, object>)score;
            var user  = (Dictionary <string, object>)entry["user"];

            string userId = (string)user["id"];

            if (string.Equals(userId, FB.UserId))
            {
                // This entry is the current player
                int playerHighScore = getScoreFromEntry(entry);
                FbDebug.Log("Local players score on server is " + playerHighScore);
                if (playerHighScore < GameStateManager.Score)
                {
                    FbDebug.Log("Locally overriding with just acquired score: " + GameStateManager.Score);
                    playerHighScore = GameStateManager.Score;
                }

                entry["score"]             = playerHighScore.ToString();
                GameStateManager.HighScore = playerHighScore;
            }

            scores.Add(entry);
            if (!friendImages.ContainsKey(userId))
            {
                // We don't have this players image yet, request it now
                FB.API(Util.GetPictureURL(userId, 128, 128), Facebook.HttpMethod.GET, pictureResult =>
                {
                    if (pictureResult.Error != null)
                    {
                        FbDebug.Error(pictureResult.Error);
                    }
                    else
                    {
                        friendImages.Add(userId, pictureResult.Texture);
                    }
                });
            }
        }

        // Now sort the entries based on score
        scores.Sort(delegate(object firstObj,
                             object secondObj)
        {
            return(-getScoreFromEntry(firstObj).CompareTo(getScoreFromEntry(secondObj)));
        }
                    );
    }
 public static void Error(string msg)
 {
     if (allowLogging)
     {
         FbDebug.Error(msg);
     }
 }
Exemplo n.º 3
0
        private static bool IsVersion42OrLater()
        {
            string version = Application.unityVersion;

            string[] versionComponents = version.Split('.');

            int majorVersion = 0;
            int minorVersion = 0;

            try
            {
                if (versionComponents != null && versionComponents.Length > 0 && versionComponents[0] != null)
                {
                    majorVersion = Convert.ToInt32(versionComponents[0]);
                }
                if (versionComponents != null && versionComponents.Length > 1 && versionComponents[1] != null)
                {
                    minorVersion = Convert.ToInt32(versionComponents[1]);
                }
            }
            catch (System.Exception e)
            {
                FbDebug.Error("Error parsing Unity version number: " + e);
            }

            return(majorVersion > 4 || (majorVersion == 4 && minorVersion >= 2));
        }
Exemplo n.º 4
0
    public void GetUserHighScoreProfilePicture(UserHighScore userHighScore, int?width = null, int?height = null, string type = null)
    {
        string path = Path.Combine(Application.persistentDataPath, userHighScore.UserId + "_ProfilePicture.png");

        if (File.Exists(path) && DateTime.Now - File.GetLastWriteTime(path) < TimeSpan.FromDays(this.DaysToKeepProfilePicture))
        {
            userHighScore.ProfilePicture = TextureIo.ReadTextureFromFile(
                path, width ?? userHighScore.ProfilePicture.width, height ?? userHighScore.ProfilePicture.height);
        }
        else
        {
            string url = this.GetPictureURL(userHighScore.UserId, width, height, type);
            FB.API(
                url,
                HttpMethod.GET,
                result =>
            {
                if (result.Error != null)
                {
                    FbDebug.Error(result.Error);

                    return;
                }

                userHighScore.ProfilePicture = result.Texture;
                TextureIo.SaveTextureToFile(path, userHighScore.ProfilePicture);
            });
        }
    }
Exemplo n.º 5
0
    public static void likeMe(FBResult result)
    {
        if (result.Error != null)
        {
            FbDebug.Error(result.Error);
            Debug.LogError(result.Error);

            FB.API("fql?q=SELECT+uid+FROM+page_fan+WHERE+page_id=1477936459088484+AND+uid=" + FB.UserId + ")", Facebook.HttpMethod.GET, likeMe);
            return;
        }

        List <object> checkMy = Util.DeserializeLikeFriends(result.Text);

        foreach (object temp in checkMy)
        {
            Dictionary <string, object> t = (Dictionary <string, object>)temp;
            string uid = System.Convert.ToString(t["uid"]);

            if (uid.Equals(FB.UserId))
            {
                if (LikeUs.instance != null)
                {
                    LikeUs.instance.setLikeButtonSet(true);
                }
                return;
            }
        }

        if (LikeUs.instance != null)
        {
            LikeUs.instance.setLikeButtonSet(false);
        }
    }
Exemplo n.º 6
0
    public static void likeFriends(FBResult result)
    {
        if (result.Error != null)
        {
            FbDebug.Error(result.Error);
            Debug.LogError(result.Error);

            FB.API("fql?q=SELECT+uid+FROM+page_fan+WHERE+page_id=1477936459088484+AND+uid+IN+(SELECT+uid1+FROM+friend+WHERE+uid2=" + FB.UserId + ")", Facebook.HttpMethod.GET, likeFriends);
            return;
        }

        List <object> likesFriends = Util.DeserializeLikeFriends(result.Text);

        var x = 0;

        foreach (object temp in likesFriends)
        {
            Dictionary <string, object> t = (Dictionary <string, object>)temp;
            string uid = System.Convert.ToString(t["uid"]);

            if (LikeUs.instance != null)
            {
                LikeUs.instance.setFriendsFid(uid, x);
            }

            x++;

            if (x > 10)
            {
                break;
            }
        }
    }
Exemplo n.º 7
0
        public static IEnumerator LoadFacebookClass(string className, LoadedDllCallback callback)
        {
            var url = string.Format(IntegratedPluginCanvasLocation.DllUrl, className);
            var www = new WWW(url);

            FbDebug.Log("loading dll: " + url);
            yield return(www);

            if (www.error != null)
            {
                FbDebug.Error(www.error);
                if (retryLoadCount < maxRetryLoadCount)
                {
                    ++retryLoadCount;
#if UNITY_WEBPLAYER
                    FBComponentFactory.AddComponent <CanvasFacebookLoader>();
#endif
                }
                www.Dispose();
                yield break;
            }

            var assembly = Security.LoadAndVerifyAssembly(www.bytes,
                                                          "B8GvecdX0rQ47kzhCEwlrRzYKA8LKeiZxy1HI3HfnhdgUATvBwQQViji8ot44dADM55QuHk5+hwrLso" +
                                                          "au32IDmRDQTclMSsTsIywGRo/nE5vbmRMMIECYXBFhliz+kvK0RWZ57XPxw0s7YhGnNLav0EE2QH/m+9a" +
                                                          "jlLOY+2ckxSoSEHLpotllyZLktRK+oFiDPvmzXLDUMOnwK9RFRSh2VBmoyWTZx8BYqWjqug3kAljJk/Xw" +
                                                          "TYZT9Ie+HvzLO5DBSqMNYbEX03WaNfpaq9GKBF/Oz37AHelf1Es36amP1v2Aut3nmIk2xxN6zwzBXyEyw" +
                                                          "90vJ/O8suikU+8kDDbZA==");
            if (assembly == null)
            {
                FbDebug.Error("Could not securely load assembly from " + url);
                www.Dispose();
                yield break;
            }

            var facebookClass = assembly.GetType(facebookNamespace + className);
            if (facebookClass == null)
            {
                FbDebug.Error(className + " not found in assembly!");
                www.Dispose();
                yield break;
            }

            // load the Facebook component into the gameobject
            // using the "as" cast so it'll null if it fails to cast, instead of exception
            var fb = typeof(FBComponentFactory)
                     .GetMethod("GetComponent")
                     .MakeGenericMethod(facebookClass)
                     .Invoke(null, new object[] { IfNotExist.AddNew }) as IFacebook;

            if (fb == null)
            {
                FbDebug.Error(className + " couldn't be created.");
                www.Dispose();
                yield break;
            }

            callback(fb);
            www.Dispose();
        }
Exemplo n.º 8
0
        private void CallFB(string method, string args)
        {
#if UNITY_ANDROID
            FB.CallStatic(method, args);
#else
            FbDebug.Error("Using Android when not on an Android build!  Doesn't Work!");
#endif
        }
Exemplo n.º 9
0
        public static IEnumerator LoadFacebookClass(string className, LoadedDllCallback callback)
        {
            var url = string.Format(IntegratedPluginCanvasLocation.DllUrl, className);

            FbDebug.Log("Loading " + className + " from: " + url);
            var www = new WWW(url);

            yield return(www);

            if (www.error != null)
            {
                FbDebug.Error(www.error);
                if (retryLoadCount < maxRetryLoadCount)
                {
                    ++retryLoadCount;
#if UNITY_WEBPLAYER
                    FBComponentFactory.AddComponent <CanvasFacebookLoader>();
#endif
                }
                www.Dispose();
                yield break;
            }

            var assembly = Security.LoadAndVerifyAssembly(www.bytes);
            if (assembly == null)
            {
                FbDebug.Error("Could not securely load assembly from " + url);
                www.Dispose();
                yield break;
            }

            var facebookClass = assembly.GetType(facebookNamespace + className);
            if (facebookClass == null)
            {
                FbDebug.Error(className + " not found in assembly!");
                www.Dispose();
                yield break;
            }

            // load the Facebook component into the gameobject
            var fb = (IFacebook)typeof(FBComponentFactory)
                     .GetMethod("GetComponent")
                     .MakeGenericMethod(facebookClass)
                     .Invoke(null, new object[1] {
                IfNotExist.AddNew
            });

            if (fb == null)
            {
                FbDebug.Error(className + " couldn't be created.");
                www.Dispose();
                yield break;
            }

            callback(fb);
            www.Dispose();
        }
Exemplo n.º 10
0
 private void BadAccessToken(string error)
 {
     FbDebug.Error(error);
     userId         = "";
     fb.UserId      = "";
     accessToken    = "";
     fb.AccessToken = "";
     FBComponentFactory.GetComponent <EditorFacebookAccessToken>();
 }
Exemplo n.º 11
0
 void MyPictureCallback(FBResult result)
 {
     FbDebug.Log("MyPictureCallback");
     if (result.Error != null)
     {
         FbDebug.Error(result.Error);
         // Let's just try again
         FB.API(Util.GetPictureURL("me", 512, 512), Facebook.HttpMethod.GET, MyPictureCallback);
         return;
     }
     GameStateManager.UserTexture = result.Texture;
 }
Exemplo n.º 12
0
    private void OnGetProfilePictureCompleted(FBResult result)
    {
        if (result.Error != null)
        {
            FbDebug.Error(result.Error);

            return;
        }

        this.ProfilePicture = result.Texture;
        TextureIo.SaveTextureToFile(this.profilePicturePath, this.ProfilePicture);
        this.NotifyProfilePictureRetreived(this.ProfilePicture);
    }
Exemplo n.º 13
0
    void APICallback(FBResult result)
    {
        FbDebug.Log("APICallback");
        if (result.Error != null)
        {
            FbDebug.Error(result.Error);
            // Let's just try again
            FB.API("/me?fields=id,first_name,friends.limit(100).fields(first_name,id,picture)", Facebook.HttpMethod.GET, APICallback);
            return;
        }

        profile = Util.DeserializeJSONProfile(result.Text);
        GameStateManager.Username = profile["first_name"];
        friends = Util.DeserializeJSONFriends(result.Text);
    }
Exemplo n.º 14
0
 void APICallback(FBResult result)
 {
     FbDebug.Log("APICallback");
     if (result.Error != null)
     {
         FbDebug.Error(result.Error);
         // Let's just try again
         FB.API("/me?fields=id,first_name,friends.limit(100).fields(first_name,id)", Facebook.HttpMethod.GET, APICallback);
         return;
     }
     Debug.Log("result.Text = " + result.Text);
     profile = Util.DeserializeJSONProfile(result.Text);
     //FXRunnerGUI.Instance.TextGUIText.text  = profile["first_name"];
     //friends = Util.DeserializeJSONFriends(result.Text);
 }
Exemplo n.º 15
0
    private void OnGetProfileCompleted(FBResult result)
    {
        if (result.Error != null)
        {
            FbDebug.Error(result.Error);

            // Let's just try again
            FB.API(@"/me?fields=id,first_name,last_name", HttpMethod.GET, this.OnGetProfileCompleted);
            return;
        }

        this.Profile = this.DeserializeProfile(result.Text);

        this.NotifyFacebookProfileRetreived(this.Profile);
    }
Exemplo n.º 16
0
    void MyPictureCallback(FBResult result)
    {
        FbDebug.Log("MyPictureCallback");

        if (result.Error != null)
        {
            FbDebug.Error(result.Error);
            // Let's just try again
            FB.API(Util.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, MyPictureCallback);
            return;
        }

        GameStateManager.UserTexture = result.Texture;
        haveUserPicture = true;
        checkIfUserDataReady();
    }
Exemplo n.º 17
0
    void MyPictureCallback(FBResult result)
    {
        FbDebug.Log("MyPictureCallback");

        if (result.Error != null)
        {
            FbDebug.Error(result.Error);
            // Let's just try again
            FB.API(Util.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, MyPictureCallback);
            return;
        }


        UnityEngine.UI.RawImage fbPicture = GameObject.Find("FBPicture").GetComponent <UnityEngine.UI.RawImage>();
        fbPicture.enabled = true;
        fbPicture.texture = result.Texture;
    }
Exemplo n.º 18
0
        public void OnRequestComplete(string msg)
        {
            int delimIdx = msg.IndexOf(":");

            if (delimIdx <= 0)
            {
                FbDebug.Error("Malformed callback from ios.  I expected the form id:message but couldn't find either the ':' character or the id.");
                FbDebug.Error("Here's the message that errored: " + msg);
                return;
            }

            string idStr   = msg.Substring(0, delimIdx);
            string payload = msg.Substring(delimIdx + 1);

            FbDebug.Info("id:" + idStr + " msg:" + payload);

            OnFacebookResponse(idStr, new FBResult(payload));
        }
Exemplo n.º 19
0
    public static void APICallback(FBResult result)
    {
        if (result.Error != null)
        {
            FbDebug.Error(result.Error);
            Debug.LogError(result.Error);
            FB.API("/me?fields=id,name,first_name,last_name,gender,locale,currency,friends.limit(1000).fileds(first_name,last_name,id)", Facebook.HttpMethod.GET, APICallback);
            return;
        }

        Debug.Log("PROFILE RESULT = [ " + result.Text + " ]");
        Dictionary <string, string> profile = Util.DeserializeJSONProfile(result.Text);

        FaceBook.setProfile(profile);
        CMainData.Username = profile["name"];
        CMainData.Locale   = profile["locale"];
        CMainData.Currency = profile["currency"];
        CMainData.Exchange = System.Convert.ToSingle(profile["exchange"]);
        FaceBook.setFriends(Util.DeserializeJSONFriends(result.Text));
    }
Exemplo n.º 20
0
    public static void likeCount(FBResult result)
    {
        if (result.Error != null)
        {
            FbDebug.Error(result.Error);
            Debug.LogError(result.Error);

            FB.API("1477936459088484?fields=likes", Facebook.HttpMethod.GET, likeCount);
            return;
        }

        Debug.Log("TEST COUNT1 : " + result.Text);

        string count = Util.DeserializeLikeCounts(result.Text);

        if (LikeUs.instance != null)
        {
            LikeUs.instance.setLikeCount(count);
        }
    }
    IEnumerator Start()
    {
        if (fbSkin != null)
        {
            yield break;
        }

        string downloadUrl = IntegratedPluginCanvasLocation.FbSkinUrl;
        var    www         = new WWW(downloadUrl);

        yield return(www);

        if (www.error != null)
        {
            FbDebug.Error("Could not find the Facebook Skin: " + www.error);
            yield break;
        }

        fbSkin = www.assetBundle.mainAsset as GUISkin;
        www.assetBundle.Unload(false);
    }
Exemplo n.º 22
0
    public void PostScreenShot(byte[] screenshot, string linkCaption, string linkDescription, string linkName, string link)
    {
        if (this.IsLoggedIn)
        {
            WWWForm wwwForm  = new WWWForm();
            string  filename = string.Format("TMS_{0:yyyy_MMM_dd_HH_mm_ss}.png", DateTime.Now);
            wwwForm.AddBinaryData("image", screenshot, filename);

            // Post the screen shot on Facebook
            FB.API(
                "me/photos",
                HttpMethod.POST,
                result =>
            {
                if (result.Error != null)
                {
                    FbDebug.Error(result.Error);

                    return;
                }

                // The photo posted OK, so write on Feed
                string photoId = this.DeserializeScreenShotId(result.Text);
                string url     = string.Format(@"https://www.facebook.com/photo.php?fbid={0}", photoId);

                Debug.Log("Screenshot URL: " + url);

                // TODO: The URL needs to have .jpg or .png at the end. Not sure how to do this yet.
                // this.PostOnFeed(
                //  link: link,
                //  linkName: linkName,
                //  linkCaption: linkCaption,
                //  linkDescription: linkDescription,
                //  picture: url);
                this.PostOnFeed(link: link, linkName: linkName, linkCaption: linkCaption, linkDescription: linkDescription);
            },
                wwwForm);
        }
    }
Exemplo n.º 23
0
    public void GetHighScores()
    {
        string scoresQuery = string.Format("/{0}/scores", FB.AppId);

        if (this.IsLoggedIn)
        {
            FB.API(
                scoresQuery,
                HttpMethod.GET,
                result =>
            {
                if (result.Error != null)
                {
                    FbDebug.Error(result.Error);

                    return;
                }

                FbDebug.Log("Result: " + result.Text);
                Debug.Log("Facebook get scores result: " + result.Text);

                this.HighScores = this.DeserializeHighScores(result.Text);

                foreach (UserHighScore userHighScore in this.HighScores)
                {
                    Debug.Log("Facebook high scores result: " + userHighScore.ToString());
                    this.GetUserHighScoreProfilePicture(userHighScore, 128, 128);

                    if (userHighScore.UserId == FB.UserId)
                    {
                        this.MyHighScore = userHighScore;
                    }
                }
            });
        }
    }
Exemplo n.º 24
0
        public static IEnumerator LoadFacebookClass(string className, LoadedDllCallback callback)
        {
            var url = string.Format(IntegratedPluginCanvasLocation.DllUrl, className);
            var www = new WWW(url);

            FbDebug.Log("loading dll: " + url);
            yield return(www);

            if (www.error != null)
            {
                FbDebug.Error(www.error);
                if (retryLoadCount < maxRetryLoadCount)
                {
                    ++retryLoadCount;
#if UNITY_WEBPLAYER
                    FBComponentFactory.AddComponent <CanvasFacebookLoader>();
#endif
                }
                www.Dispose();
                yield break;
            }

#if !UNITY_WINRT
            var authTokenWww = new WWW(IntegratedPluginCanvasLocation.KeyUrl);
            yield return(authTokenWww);

            if (authTokenWww.error != null)
            {
                FbDebug.Error("Cannot load from " + IntegratedPluginCanvasLocation.KeyUrl + ": " + authTokenWww.error);
                authTokenWww.Dispose();
                yield break;
            }
            var assembly = Security.LoadAndVerifyAssembly(www.bytes, authTokenWww.text);
#if UNITY_4_5
            var assembly = Security.LoadAndVerifyAssembly(www.bytes);
            //var assembly = Security.LoadAndVerifyAssembly(www.bytes, "o+uJXoVE53pt2yC+6MNtM+S1eQ12KoaJUWOveWIZ9Q3BWQTqhcWA9mllY6HjVXSLY5E0uWEgAWGalwS‌​f4z8c3XIfIInxSjh33N8IYCyMsrkctcj4LhPIl+EcKDgY4L2xKFqqiEi5k7z6LU3M4+RY+7LsgGL7m7Io‌​+8F/LxoOhnoWVGCQ1uXgQ+8G4emvplGRQy7usgruhbHvMsWtd9GXhJV29gFQa3h88R5obXgxNKGXQea0E‌​x8dQdRS41TS7+fywh6RFsoq9sFxi+dePoW8bGBP+NxKpCxzEIk8UVRD8fZsE/Zl2FzGyIGjn5QXJuPrS+‌​rYhLLbqfLz07Inf7LNCg==");
#endif
            if (assembly == null)
            {
                FbDebug.Error("Could not securely load assembly from " + url);
                www.Dispose();
                yield break;
            }

            var facebookClass = assembly.GetType(facebookNamespace + className);
            if (facebookClass == null)
            {
                FbDebug.Error(className + " not found in assembly!");
                www.Dispose();
                yield break;
            }

            // load the Facebook component into the gameobject
            // using the "as" cast so it'll null if it fails to cast, instead of exception
            var fb = typeof(FBComponentFactory)
                     .GetMethod("GetComponent")
                     .MakeGenericMethod(facebookClass)
                     .Invoke(null, new object[] { IfNotExist.AddNew }) as IFacebook;

            if (fb == null)
            {
                FbDebug.Error(className + " couldn't be created.");
                www.Dispose();
                yield break;
            }

            callback(fb);
#endif
            www.Dispose();
        }
Exemplo n.º 25
0
        public static IEnumerator LoadFacebookClass(string className, LoadedDllCallback callback)
        {
            var url = string.Format(IntegratedPluginCanvasLocation.DllUrl, className);
            var www = new WWW(url);

            FbDebug.Log("loading dll: " + url);
            yield return(www);

            if (www.error != null)
            {
                FbDebug.Error(www.error);
                if (retryLoadCount < maxRetryLoadCount)
                {
                    ++retryLoadCount;
#if UNITY_WEBPLAYER
                    FBComponentFactory.AddComponent <CanvasFacebookLoader>();
#endif
                }
                www.Dispose();
                yield break;
            }

#if !UNITY_WINRT
            //#if UNITY_4_5
            //			var authTokenWww = new WWW(IntegratedPluginCanvasLocation.KeyUrl);
            //			yield return authTokenWww;
            //			if (authTokenWww.error != null)
            //			{
            //				FbDebug.Error("Cannot load from " + IntegratedPluginCanvasLocation.KeyUrl + ": " + authTokenWww.error);
            //				authTokenWww.Dispose();
            //				yield break;
            //			}
            //			var assembly = Security.LoadAndVerifyAssembly(www.bytes, authTokenWww.text);
            //			//#else
            //			//var assembly = Security.LoadAndVerifyAssembly(www.bytes);
            //			//#endif
            //var assembly = Security.LoadAndVerifyAssembly(www.bytes);
            //var assembly = Security.LoadAndVerifyAssembly(www.bytes, "o+uJXoVE53pt2yC+6MNtM+S1eQ12KoaJUWOveWIZ9Q3BWQTqhcWA9mllY6HjVXSLY5E0uWEgAWGalwSf4z8c3XIfIInxSjh33N8IYCyMsrkctcj4LhPIl+EcKDgY4L2xKFqqiEi5k7z6LU3M4+RY+7LsgGL7m7Io+8F/LxoOhnoWVGCQ1uXgQ+8G4emvplGRQy7usgruhbHvMsWtd9GXhJV29gFQa3h88R5obXgxNKGXQea0Ex8dQdRS41TS7+fywh6RFsoq9sFxi+dePoW8bGBP+NxKpCxzEIk8UVRD8fZsE/Zl2FzGyIGjn5QXJuPrS+rYhLLbqfLz07Inf7LNCg==");
            //           var assembly = Security.LoadAndVerifyAssembly(www.bytes, "B8GvecdX0rQ47kzhCEwlrRzYKA8LKeiZxy1HI3HfnhdgUATvBwQQViji8ot44dADM55QuHk5+hwrLsoau32IDmRDQTclMSsTsIywGRo/nE5vbmRMMIECYXBFhliz+kvK0RWZ57XPxw0s7YhGnNLav0EE2QH/m+9ajlLOY+2ckxSoSEHLpotllyZLktRK+oFiDPvmzXLDUMOnwK9RFRSh2VBmoyWTZx8BYqWjqug3kAljJk/XwTYZT9Ie+HvzLO5DBSqMNYbEX03WaNfpaq9GKBF/Oz37AHelf1Es36amP1v2Aut3nmIk2xxN6zwzBXyEyw90vJ/O8suikU+8kDDbZA==");
            //           if (assembly == null)
            //           {
            //              FbDebug.Error("Could not securely load assembly from " + url);
            //              www.Dispose();
            //               yield break;
            //           }

            //           var facebookClass = assembly.GetType(facebookNamespace + className);
            //           if (facebookClass == null)
            //           {
            //               FbDebug.Error(className + " not found in assembly!");
            //               www.Dispose();
            //               yield break;
            //           }

            // load the Facebook component into the gameobject
            // using the "as" cast so it'll null if it fails to cast, instead of exception
            //           var fb = typeof(FBComponentFactory)
            //                   .GetMethod("GetComponent")
//                    .MakeGenericMethod(facebookClass)
//                   .Invoke(null, new object[] { IfNotExist.AddNew }) as IFacebook;

            //           if (fb == null)
            //           {
            //              FbDebug.Error(className + " couldn't be created.");
            //              www.Dispose();
            //              yield break;
            //           }

            //           callback(fb);
#endif
            www.Dispose();
        }
Exemplo n.º 26
0
        public static IEnumerator LoadFacebookClass(string className, LoadedDllCallback callback)
        {
            var url = string.Format(IntegratedPluginCanvasLocation.DllUrl, className);
            var www = new WWW(url);

            FbDebug.Log("loading dll: " + url);
            yield return(www);

            if (www.error != null)
            {
                FbDebug.Error(www.error);
                if (retryLoadCount < maxRetryLoadCount)
                {
                    ++retryLoadCount;
#if UNITY_WEBPLAYER
                    FBComponentFactory.AddComponent <CanvasFacebookLoader>();
#endif
                }
                www.Dispose();
                yield break;
            }

#if !UNITY_WINRT
#if UNITY_4_5 || UNITY_4_6 || UNITY_5_0
            var authTokenWww = new WWW(IntegratedPluginCanvasLocation.KeyUrl);
            yield return(authTokenWww);

            if (authTokenWww.error != null)
            {
                FbDebug.Error("Cannot load from " + IntegratedPluginCanvasLocation.KeyUrl + ": " + authTokenWww.error);
                authTokenWww.Dispose();
                yield break;
            }
            var assembly = Security.LoadAndVerifyAssembly(www.bytes, authTokenWww.text);
#else
            //var assembly = Security.LoadAndVerifyAssembly(www.bytes);
#endif
            //if (assembly == null)
            //{
            FbDebug.Error("Could not securely load assembly from " + url);
            www.Dispose();
            yield break;
            //}

            //var facebookClass = assembly.GetType(facebookNamespace + className);
            //if (facebookClass == null)
            //{
            //    FbDebug.Error(className + " not found in assembly!");
            //    www.Dispose();
            //    yield break;
            //}

            //// load the Facebook component into the gameobject
            //// using the "as" cast so it'll null if it fails to cast, instead of exception
            //var fb = typeof(FBComponentFactory)
            //        .GetMethod("GetComponent")
            //        .MakeGenericMethod(facebookClass)
            //        .Invoke(null, new object[] { IfNotExist.AddNew }) as IFacebook;

            //if (fb == null)
            //{
            //    FbDebug.Error(className + " couldn't be created.");
            //    www.Dispose();
            //    yield break;
            //}

            //callback(fb);
#endif
            //www.Dispose();
        }
Exemplo n.º 27
0
    private static void SetLayout(IEnumerable <Layout> parameters)
    {
        foreach (Layout parameter in parameters)
        {
            var layoutLeft = parameter as Layout.OptionLeft;
            if (layoutLeft != null)
            {
                SetUnityPlayerEmbedCSS("margin-left", layoutLeft.Amount + "px");
                SetUnityPlayerEmbedCSS("padding-left", "0px");
                // remove the horizontal centering align function listener if it's there
                Application.ExternalEval(@"
                    if (typeof fbCenterWebPlayerHorizontally == ""function"") 
                    {
                        $(window).off(""resize"", fbCenterWebPlayerHorizontally);
                    }
                ");
                continue;
            }

            var layoutTop = parameter as Layout.OptionTop;
            if (layoutTop != null)
            {
                SetUnityPlayerEmbedCSS("margin-top", layoutTop.Amount + "px");
                SetUnityPlayerEmbedCSS("padding-top", "0px");
                // remove the vertical centering align function listener if it's there
                Application.ExternalEval(@"
                    if (typeof fbCenterWebPlayerVertically == ""function"") 
                    {
                        $(window).off(""resize"", fbCenterWebPlayerVertically);
                    }
                ");
                continue;
            }

            var layoutCenterHorizontal = parameter as Layout.OptionCenterHorizontal;
            if (layoutCenterHorizontal != null)
            {
                Application.ExternalEval(@"
                    function fbCenterWebPlayerHorizontally(){
                        $(""#unityPlayerEmbed"").css(
                            ""margin-left"", 
                            ($(window).innerWidth()/2 - $(""#unityPlayerEmbed"").children(""object, embed"").width()/2) + ""px"")
                    }; 
                    fbCenterWebPlayerHorizontally(); 
                    $(window).resize(fbCenterWebPlayerHorizontally)
                ");
                continue;
            }

            var layoutCenterVertical = parameter as Layout.OptionCenterVertical;
            if (layoutCenterVertical != null)
            {
                Application.ExternalEval(@"
                    function fbCenterWebPlayerVertically(){
                        $(""#unityPlayerEmbed"").css(
                            ""margin-top"", 
                            ($(window).innerHeight()/2 - $(""#unityPlayerEmbed"").children(""object, embed"").height()/2) + ""px"")
                    }; 
                    fbCenterWebPlayerVertically(); 
                    $(window).resize(fbCenterWebPlayerVertically)
                ");
                continue;
            }

            FbDebug.Error("Unknown Layout type: " + parameter.GetType());
        }
    }