Esempio n. 1
0
    void OnGUI()
    {
        float ratio = Screen.width / 600.0f;

        GUI.skin.label.fontSize  = (int)(15 * ratio);
        GUI.skin.button.fontSize = (int)(15 * ratio);

        if (syncManager == null)
        {
            GUILayout.Space(20);
            GUILayout.Label("Please setup the Cognito credentials");
            return;
        }


        if (GetComponent <CharacterList> ().enabled)
        {
            if (GUI.Button(new Rect(30 * ratio, 30 * ratio, 120 * ratio, 30 * ratio), "Save"))
            {
                SaveToDataset();
            }
            else if (GUI.Button(new Rect(30 * ratio, 70 * ratio, 120 * ratio, 30 * ratio), "Load"))
            {
                LoadFromDataset();
            }
            else if (GUI.Button(new Rect(Screen.width - 150 * ratio, 30 * ratio, 120 * ratio, 30 * ratio), "Logout"))
            {
                if (credentials.IdentityProvider.Logins.Count > 0)                   //Auth identity
                {
                    if (FB.IsLoggedIn)
                    {
                        FB.Logout();
                    }
                    credentials.ClearCredentialsAndIdentity();
                    syncManager.WipeData();
                }
                Application.LoadLevel(Application.loadedLevel);
            }
            if (credentials.IdentityProvider.Logins.Count == 0)               //Unauth
            {
                if (GUI.Button(new Rect(Screen.width - 150 * ratio, 70 * ratio, 120 * ratio, 30 * ratio), "Link with FB"))
                {
                    GetComponent <CharacterList> ().enabled = false;
                    FB.Login("email", FacebookLoginCallback);
                }
            }
        }
        else
        {
            GUI.Label(new Rect(30 * ratio, 30 * ratio, 120 * ratio, 30 * ratio), "Please wait...");
        }

        GUI.Label(new Rect(20 * ratio, Screen.height - 50 * ratio, 600 * ratio, 30 * ratio), "Identity: " + credentials.IdentityProvider.GetCurrentIdentityId());
    }
    private void OnGUI()
    {
        float ratio = Screen.width / 600.0f;

        GUI.skin.label.fontSize  = (int)(15 * ratio);
        GUI.skin.button.fontSize = (int)(15 * ratio);

        GUI.Label(new Rect(30 * ratio, 30 * ratio, 800 * ratio, 30 * ratio), "Identity: " + myIdentity);

        if (loading)
        {
            return;
        }

        if (loggedIn)
        {
            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2 - 40 * ratio, 160 * ratio, 30 * ratio), "GetCognitoId"))
            {
                GetIdentity();
            }

            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2, 160 * ratio, 30 * ratio), "Clear identity"))
            {
                myIdentity = "";
                credentials.ClearCredentialsAndIdentity();
            }

            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2 + 40 * ratio, 160 * ratio, 30 * ratio), "Logout"))
            {
                Application.LoadLevel(Application.loadedLevel);
                loggedIn = false;
            }
        }
        else
        {
            GUI.skin.button.fontSize = (int)(15 * ratio);
            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2 - 20 * ratio, 160 * ratio, 30 * ratio), "Login with Facebook"))
            {
                loading = true;
                FB.Login("email", FacebookLoginCallback);
            }
            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2 + 20 * ratio, 160 * ratio, 30 * ratio), "Skip authentication"))
            {
                loading = true;
                InitUnauth();
            }
        }
    }