Esempio n. 1
0
/*
 *      private void RefreshCallback(AmazonServiceResult result)
 *      {
 *              GetComponent<CharacterList> ().enabled = true;
 *      }
 */
    private void LoadFromDataset()
    {
        GetComponent <CharacterList> ().enabled = false;
        // Remote DatasetMetadata is fetched and stored in SQLiteStorage
        // Records are not fetched until ds.Synchronize() is called on the respective datasets
        syncManager.RefreshDatasetMetadataAsync(RefreshDatasetMetadataCallback, null);
    }
    void OnGUI()
    {
        GUI.color = Color.gray;
        GUILayout.BeginArea(new Rect(Screen.width * 0.2f, 0, Screen.width - Screen.width * 0.2f, Screen.height));
        GUILayout.Space(20);
        GUILayout.Label(statusMessage);

        if (syncManager == null)
        {
            GUILayout.EndArea();
            return;
        }

        GUI.color = Color.white;
        #if USE_FACEBOOK_LOGIN
        GUI.enabled = true;
        #else
        GUI.enabled = false;
        #endif
        if (GUILayout.Button("Connect to Facebook", GUILayout.MinHeight(20), GUILayout.Width(Screen.width * 0.6f)))
        {
            #if USE_FACEBOOK_LOGIN
            statusMessage = "Connecting to Facebook";
            disableButton = true;
            if (!FB.IsInitialized)
            {
                FB.Init(delegate() {
                    Debug.Log("starting thread");

                    // shows to connect the current identityid or create a new identityid with facebook authentication
                    FB.Login("email", FacebookLoginCallback);
                });
            }
            else
            {
                FB.Login("email", FacebookLoginCallback);
            }
            #endif
        }

        if (disableButton)
        {
            GUI.enabled = false;
        }
        else
        {
            GUI.enabled = true;
        }
        GUILayout.Label("Enter PlayerInfo");
        playerName = GUILayout.TextField(playerName, GUILayout.MinHeight(20), GUILayout.Width(Screen.width * 0.6f));
        alias      = GUILayout.TextField(alias, GUILayout.MinHeight(20), GUILayout.Width(Screen.width * 0.6f));

        GUILayout.Space(20);

        GUILayout.Label("Select Difficulty Level");
        selectedDifficultyLevel = GUILayout.SelectionGrid(selectedDifficultyLevel, difficultyLevels, 3, GUILayout.MinHeight(20), GUILayout.Width(Screen.width * 0.6f));
        GUILayout.Space(20);

        if (GUILayout.Button("Save offline using SyncManager", GUILayout.MinHeight(20), GUILayout.Width(Screen.width * 0.6f)))
        {
            statusMessage = "Saving offline..";
            disableButton = true;
            // syncManager creates or fetches the Dataset locally using SQLiteStorage
            // OpenOrCreateDataset(datasetName) takes the datasetName which may be like "UserSettings", "UserState"

            playerInfo.Put("playerName", playerName);
            playerInfo.Put("alias", alias);

            playerSettings.Put("selectedDifficultyLevel", selectedDifficultyLevel.ToString());

            alias      = string.IsNullOrEmpty(playerInfo.Get("alias")) ? "Enter ur alias" : playerInfo.Get("alias");
            playerName = string.IsNullOrEmpty(playerInfo.Get("playerName")) ? "Enter ur fullName" : playerInfo.Get("playerName");

            selectedDifficultyLevel = string.IsNullOrEmpty(playerSettings.Get("selectedDifficultyLevel")) ? 0 : int.Parse(playerSettings.Get("selectedDifficultyLevel"));
            statusMessage           = "Saved offline !";
            disableButton           = false;
        }
        else if (GUILayout.Button("Sync with CognitoSync Cloud", GUILayout.MinHeight(20), GUILayout.Width(Screen.width * 0.6f)))
        {
            statusMessage = "Saving to CognitoSync Cloud..";
            disableButton = true;
            playerInfo.Put("alias", alias);
            playerInfo.Synchronize();
            playerInfo.Put("playerName", playerName);

            playerSettings.Put("difficultyLevel", selectedDifficultyLevel.ToString());
            playerSettings.Synchronize();
        }
        else if (GUILayout.Button("Refresh and Sync to CognitoSync Cloud", GUILayout.MinHeight(20), GUILayout.Width(Screen.width * 0.6f)))
        {
            statusMessage = "Refreshing metadata for current player..";
            disableButton = true;
            // RefreshDatasetMetadataAsync fetches all datasets for the current IdentityID
            // Remote DatasetMetadata is fetched and stored in SQLiteStorage
            // Records are not fetched until ds.Synchronize() is called on the respective datasets
            syncManager.RefreshDatasetMetadataAsync(RefreshDatasetMetadataCallback, null);
        }
        else if (GUILayout.Button("Delete all local player data", GUILayout.MinHeight(20), GUILayout.Width(Screen.width * 0.6f)))
        {
            statusMessage = "Deleting all local data..";
            syncManager.WipeData();
            playerName = "Enter ur full name";
            alias      = "Enter ur alias";
            selectedDifficultyLevel = 0;
            statusMessage           = "Deleting all local data complete. ";
        }
        GUILayout.EndArea();
    }