//============================================================================= public void OnButtonPressed_RegisterWithFacebook() { #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR // Attempt to register bool isSessionValid = FacebookCombo.isSessionValid(); if (isSessionValid == false) { // If no internet is present go to error message if (Application.internetReachability == NetworkReachability.NotReachable) { m_txtFacebookErrorMessage.text = TextManager.GetText("ERROR_NO_INTERNET"); m_CurrentStage = eRegistrationStage.FacebookLoginFailure; } else { string[] permissions = new string[] { "email" }; FacebookCombo.loginWithReadPermissions(permissions); m_bIsLoggingIn = true; //m_CurrentStage = eRegistrationStage.FacebookRegistering; Debug.Log("FairyRegistrationManager: Register->Log Into FB"); } } else { // Already logged in, get user info and friend info m_CurrentStage = eRegistrationStage.FacebookRegisteringGetUserInfo; GetFacebookUserInfo(); Debug.Log("FairyRegistrationManager: Register->Session Valid,success"); } #else if (UnityEngine.Random.Range(0, 100) < 25) { m_CurrentStage = eRegistrationStage.FacebookRegisteringGetUserInfo; GetFacebookUserInfo(); } else { m_CurrentStage = eRegistrationStage.FacebookRegistering; } #endif }
//============================================================================= private void ShareWithFacebook() { #if UNITY_IPHONE || UNITY_ANDROID //FacebookManager.dialogCompletedWithUrlEvent += OnDialogCompletedWithUrlEvent; //FacebookManager.dialogFailedEvent += OnDialogFailedEvent; string desc = TextManager.GetText("POPUP_SHARE_FACEBOOK"); desc = desc.Replace("(population)", GameDataManager.Instance.PlayerHighestEverPopulation.ToString("#,##0")); desc = desc.Replace("(fairy)", ServerManager.instance.GetPlayerName()); Dictionary <string, object> parameters = new Dictionary <string, object> { { "link", "https://www.facebook.com/playwinxclub" }, { "name", TextManager.GetText("POPUP_SHARE_FACEBOOK_LINK_NAME") }, { "picture", "https://s3-eu-west-1.amazonaws.com/butterflix-liveupdates/FBImage.png" }, { "caption", TextManager.GetText("POPUP_SHARE_FACEBOOK_CAPTION") }, { "description", desc } }; FacebookCombo.showFacebookShareDialog(parameters); #endif }
public void OnButtonPressed_Facebook() { #if UNITY_IPHONE || UNITY_ANDROID if (m_bIsWaitingForFacebookLogin || m_bIsWaitingForTwitterLogin || m_bIsWaitingForTwitterShare) { return; } //If it's not valid you can't post - try logging in using this code and then checking session valid again. bool isLoggedIn = FacebookCombo.isSessionValid(); if (!isLoggedIn) { m_bIsWaitingForFacebookLogin = true; string[] permissions = new string[] { "email" }; FacebookCombo.loginWithReadPermissions(permissions); } else { ShareWithFacebook(); } #endif }
//===================================================== public void Update() { m_Timer += Time.deltaTime; if (m_Timer > 0.2f) { if ((AchievementsManager.m_Instance != null) && (m_bScoresDownloaded == false)) { AchievementsManager.m_Instance.GetScoreboard(AchievementsManager.eScoreTime.AllTime, 1, 100); m_bScoresDownloaded = true; } } #if UNITY_IPHONE || UNITY_ANDROID if (m_bIsWaitingForFacebookLogin) { if (FacebookCombo.isSessionValid()) { m_bIsWaitingForFacebookLogin = false; ShareWithFacebook(); } } #endif }
//============================================================================= void Start() { if (m_bVerbose) { Debug.Log("AchievementsManager: Start"); } if (m_bInitialised == false) { m_bInitialised = true; m_bIsLoggedIn = false; m_Instance = this; m_bIsUploadingAchievement = false; m_UploadingAchievementTimeout = 10.0f; m_UploadingAchievementID = -1; m_ManagerState = eManagerState.Idle; if (m_bVerbose) { Debug.Log("AchievementsManager: Init"); } } // Connect to Game Center / Google Play #if UNITY_IPHONE GameCenterManager.playerAuthenticatedEvent += GCOnPlayerAuthenticated; GameCenterManager.playerFailedToAuthenticateEvent += GCOnPlayerFailedToAuthenticate; GameCenterManager.reportAchievementFailedEvent += GCOnReportAchievementFailed; GameCenterManager.reportAchievementFinishedEvent += GCOnReportAchievementFinished; GameCenterManager.reportScoreFailedEvent += GCOnReportScoreFailed; GameCenterManager.reportScoreFinishedEvent += GCOnReportScoreFinished; // Auto login if we already logged in a previous time //if( PlayerPrefs.GetInt( "GCGPAutoLogin" , 0 ) > 0 ) { Login(); } #endif #if UNITY_ANDROID GPGManager.authenticationSucceededEvent += GPOnPlayerAuthenticated; GPGManager.authenticationFailedEvent += GPOnPlayerFailedToAuthenticate; GPGManager.unlockAchievementFailedEvent += GPOnReportAchievementFailed; GPGManager.unlockAchievementSucceededEvent += GPOnReportAchievementFinished; GPGManager.submitScoreFailedEvent += GPOnReportScoreFailed; GPGManager.submitScoreSucceededEvent += GPOnReportScoreFinished; // Auto login if we already logged in a previous time //if( PlayerPrefs.GetInt( "GCGPAutoLogin" , 0 ) > 0 ) { Login(); } #endif // Playtomic init (scoreboards) Playtomic.Initialize("4297CC23E31BC29545FC2A9577AD4", "14A8D1497B7B68DBF43D97128CB88", "http://shreditscoreboard.herokuapp.com/"); // Connect to Facebook/Twitter #if UNITY_IPHONE || UNITY_ANDROID FacebookCombo.init(); TwitterCombo.init("GPC3ImeHkYHf0Bdhr9gNC39SW", "dty3PjzDLQTnlQ9jjqMJUM2oy4apJhqtPpaFCX0oVcLvTw2kPg"); #endif #if UNITY_IPHONE && !UNITY_EDITOR FacebookBinding.setSessionLoginBehavior(FacebookSessionLoginBehavior.ForcingWebView); #endif // For debug builds register a random player RandomiseName(); }
void OnGUI() { // center labels GUI.skin.label.alignment = TextAnchor.MiddleCenter; beginColumn(); if (GUILayout.Button("Initialize Facebook")) { FacebookCombo.init(); } if (GUILayout.Button("Login")) { // Note: requesting publish permissions here will result in a crash. Only read permissions are permitted. var permissions = new string[] { "email" }; FacebookCombo.loginWithReadPermissions(permissions); } if (GUILayout.Button("Reauth with Publish Permissions")) { var permissions = new string[] { "publish_actions", "publish_stream" }; FacebookCombo.reauthorizeWithPublishPermissions(permissions, FacebookSessionDefaultAudience.OnlyMe); } if (GUILayout.Button("Logout")) { FacebookCombo.logout(); } if (GUILayout.Button("Is Session Valid?")) { // isSessionValid only checks the local session so if a user deauthorizies the application on Facebook's website it can be incorrect var isLoggedIn = FacebookCombo.isSessionValid(); Debug.Log("Facebook is session valid: " + isLoggedIn); // This way of checking a session hits Facebook's servers ensuring the session really is valid Facebook.instance.checkSessionValidityOnServer(isValid => { Debug.Log("checked session validity on server. Is it valid? " + isValid); }); } if (GUILayout.Button("Get Access Token")) { var token = FacebookCombo.getAccessToken(); Debug.Log("access token: " + token); } if (GUILayout.Button("Get Granted Permissions")) { // This way of getting session permissions uses Facebook's SDK which is a local cache. It can be wrong for various reasons. var permissions = FacebookCombo.getSessionPermissions(); foreach (var perm in permissions) { Debug.Log(perm); } // This way of getting the permissions hits Facebook's servers so it is certain to be valid. Facebook.instance.getSessionPermissionsOnServer(completionHandler); } if (GUILayout.Button("Show Share Dialog")) { var parameters = new Dictionary <string, object> { { "link", "http://prime31.com" }, { "name", "link name goes here" }, { "picture", "http://prime31.com/assets/images/prime31logo.png" }, { "caption", "the caption for the image is here" }, { "description", "description of what this share dialog is all about" } }; FacebookCombo.showFacebookShareDialog(parameters); } endColumn(true); secondColumnButtonsGUI(); endColumn(false); if (bottomRightButton("Twitter...")) { Application.LoadLevel("TwitterCombo"); } }
private void secondColumnButtonsGUI() { if (GUILayout.Button("Post Image")) { var pathToImage = Application.persistentDataPath + "/" + FacebookComboUI.screenshotFilename; if (!System.IO.File.Exists(pathToImage)) { Debug.LogError("there is no screenshot avaialable at path: " + pathToImage); return; } var bytes = System.IO.File.ReadAllBytes(pathToImage); Facebook.instance.postImage(bytes, "im an image posted from iOS", completionHandler); } if (GUILayout.Button("Post Message")) { Facebook.instance.postMessage("im posting this from Unity: " + Time.deltaTime, completionHandler); } if (GUILayout.Button("Post Message & Extras")) { Facebook.instance.postMessageWithLinkAndLinkToImage("link post from Unity: " + Time.deltaTime, "http://prime31.com", "Prime31 Studios", "http://prime31.com/assets/images/prime31logo.png", "Prime31 Logo", completionHandler); } if (GUILayout.Button("Post Score")) { // note that posting a score requires publish_actions permissions! Facebook.instance.postScore(5688, (didPost) => { Debug.Log("score did post: " + didPost); }); } if (GUILayout.Button("Show stream.publish Dialog")) { // parameters are optional. See Facebook's documentation for all the dialogs and paramters that they support var parameters = new Dictionary <string, string> { { "link", "http://prime31.com" }, { "name", "link name goes here" }, { "picture", "http://prime31.com/assets/images/prime31logo.png" }, { "caption", "the caption for the image is here" } }; FacebookCombo.showDialog("stream.publish", parameters); } if (GUILayout.Button("Get Friends")) { Facebook.instance.getFriends((error, friends) => { if (error != null) { Debug.LogError("error fetching friends: " + error); return; } Debug.Log(friends); }); } if (GUILayout.Button("Graph Request (me)")) { Facebook.instance.getMe((error, result) => { // if we have an error we dont proceed any further if (error != null) { return; } if (result == null) { return; } // grab the userId and persist it for later use _userId = result.id; Debug.Log("me Graph Request finished: "); Debug.Log(result); }); } if (_userId != null) { if (GUILayout.Button("Show Profile Image")) { Facebook.instance.fetchProfileImageForUserId(_userId, (tex) => { if (tex != null) { cube.renderer.material.mainTexture = tex; } }); } } else { GUILayout.Label("Call the me Graph request to show user specific buttons"); } }
//===================================================== public void Update() { // Show current page foreach (eRegistrationStage Stage in Enum.GetValues(typeof(eRegistrationStage))) { if (m_Pages[(int)Stage] != null) { if (Stage == m_CurrentStage) { m_Pages[(int)Stage].SetActive(true); } else { m_Pages[(int)Stage].SetActive(false); } } } // Run logic for current page switch (m_CurrentStage) { case eRegistrationStage.FacebookConfirmation: case eRegistrationStage.ChooseRegistrationMethod: { #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR // Session now valid? bool isSessionValid = FacebookCombo.isSessionValid(); if ((isSessionValid == true) && (m_bIsLoggingIn == true)) { //string token = FacebookCombo.getAccessToken(); Debug.Log("FairyRegistrationManager: Update->SessionValid"); m_CurrentStage = eRegistrationStage.FacebookRegisteringGetUserInfo; m_bIsLoggingIn = false; GetFacebookUserInfo(); } #endif } break; case eRegistrationStage.ChooseFairyName: { } break; case eRegistrationStage.FacebookRegistering: { #if UNITY_EDITOR if (UnityEngine.Random.Range(0, 200) < 2) { m_CurrentStage = eRegistrationStage.FacebookRegisteringGetUserInfo; GetFacebookUserInfo(); } #endif } break; case eRegistrationStage.FacebookRegisteringSuccess: { m_txtFacebookName.text = m_InProgressPlayerName; m_txtFacebookID.text = m_InProgressPlayerID; } break; case eRegistrationStage.FacebookRegisteringFailure: break; case eRegistrationStage.RegisteringFairy: break; case eRegistrationStage.RegisteringFairySuccess: break; case eRegistrationStage.RegisteringFairyFailure: break; case eRegistrationStage.FacebookRegisteringGetUserInfo: break; case eRegistrationStage.FindingPreviousFairies: break; case eRegistrationStage.PickPreviousFairy: break; case eRegistrationStage.RestoringPreviousFairy: break; case eRegistrationStage.RestoringPreviousFairySuccess: break; case eRegistrationStage.RestoringPreviousFairyFailure: break; case eRegistrationStage.FacebookLoginFailure: break; } }