123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- using UnityEngine;
- using System.Collections;
- public class FacebookDialogManager : MonoBehaviour
- {
- public UIElementTransition noInternetDialog;
- public UIElementTransition loginDialog;
- public UIElementTransition likeDialog;
- void OnEnable()
- {
- FacebookHelper.AddSuccessfulLoginWithPermissionsListener(OnSuccessfulLoginWithPermissions);
- FacebookHelper.AddQueryHasLikedPageCompleteListener(OnQueryHasLikedPageComplete);
- DebugViewManager.OnDebugView += OnDebugView;
- CoreNotificationCenter.AddListener(OnConnectivityChange, CoreNotificationType.ConnectivityChange);
- ShowAppropriateDialog();
- }
- void OnDisable()
- {
- FacebookHelper.RemoveSuccessfulLoginWithPermissionsListener(OnSuccessfulLoginWithPermissions);
- FacebookHelper.RemoveQueryHasLikedPageCompleteListener(OnQueryHasLikedPageComplete);
- DebugViewManager.OnDebugView -= OnDebugView;
- CoreNotificationCenter.RemoveListener(OnConnectivityChange, CoreNotificationType.ConnectivityChange);
- }
- void OnApplicationPause()
- {
- AVDebug.Log("OnApplicationPause");
- //when switching back to app, and if the like dialog is active,
- //recheck if he has really liked the page
- StartCoroutine(RecheckPageLikeCoroutine());
- }
- void ShowAppropriateDialog()
- {
- if (!ConnectivityPollManager.HasInternet)
- {
- Debug.Log("ShowAppropriateDialog");
- noInternetDialog.Show();
- loginDialog.Hide();
- likeDialog.Hide();
- } else
- //if (!FacebookHelper.Instance.IsLoggedIn())
- //{
- // noInternetDialog.Hide();
- // loginDialog.Show();
- // likeDialog.Hide();
- //} else
- {
- noInternetDialog.Hide();
- loginDialog.Hide();
- }
- }
- IEnumerator RecheckPageLikeCoroutine()
- {
- if (likeDialog.gameObject.activeSelf)
- {
- yield return new WaitForSeconds(0.1f);
- FacebookHelper.Instance.QueryHasLikedPage();
- }
- }
- void OnDebugView()
- {
- if (GUILayout.Button("Reset facebook dummy stuff"))
- {
- FacebookHelper.Instance.Reset();
- }
- }
- void OnLoginButtonMsg()
- {
- Logger.LogFlurryEvent("Facebook Login from Scores screen");
- FacebookHelper.Instance.LogIn();
- }
- void OnLikeButtonMsg()
- {
- Logger.LogFlurryEvent("Facebook Like button pressed");
- FacebookHelper.Instance.LikePage();
- }
- void OnSuccessfulLoginWithPermissions()
- {
- loginDialog.Hide();
- //Danish Requirement: Only check for like on game over
- if (MenuManager.CurrentState == MenuManager.MenuState.ViewingScoresAfterGame)
- {
- FacebookHelper.Instance.QueryHasLikedPage();
- }
- }
- void OnQueryHasLikedPageComplete(bool isLiked)
- {
- AVDebug.Log("OnQueryHasLikedPageComplete " + isLiked);
- if (isLiked)
- {
- likeDialog.Hide();
- } else
- //Ask for like page after game over
- if (MenuManager.CurrentState == MenuManager.MenuState.ViewingScoresAfterGame)
- {
- likeDialog.Show();
- }
- }
- void OnConnectivityChange(CoreNotification note)
- {
- Debug.Log("ShowAppropriateDialog");
- ShowAppropriateDialog();
- }
- }
|