예제 #1
0
    //=============================================================================

    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");
        }
    }