コード例 #1
0
    void Update()
    {
        if (initializationPending)
        {
            // Loading the datasets
            characters = syncManager.OpenOrCreateDataset("characters");

            // when ds.Synchronize() is called the localDataset is merged with the remoteDataset
            // OnDatasetDeleted, OnDatasetMerged, OnDatasetSuccess,  the corresponding callback is fired.
            // The developer has the freedom of handling these events needed for the Dataset
            characters.OnSyncSuccess   += this.HandleSyncSuccess; // OnSyncSucess uses events/delegates pattern
            characters.OnSyncFailure   += this.HandleSyncFailure; // OnSyncFailure uses events/delegates pattern
            characters.OnSyncConflict   = this.HandleSyncConflict;
            characters.OnDatasetMerged  = this.HandleDatasetMerged;
            characters.OnDatasetDeleted = this.HandleDatasetDeleted;

            LoadFromDataset();

            initializationPending = false;
        }

        if (characterStrings != null)
        {
            CharacterList charList = GetComponent <CharacterList> ();
            charList.DeserializeCharacters(characterStrings);
            characterStrings = null;
            charList.enabled = true;
        }
    }
コード例 #2
0
 void Update()
 {
     if (characterStrings != null)
     {
         CharacterList charList = GetComponent <CharacterList> ();
         charList.DeserializeCharacters(characterStrings);
         characterStrings = null;
         charList.enabled = true;
     }
 }
コード例 #3
0
    private void HandleSyncSuccess(object sender, SyncSuccessEvent e)
    {
        if (mergeInCourse)
        {
            Debug.Log("Waiting for merge to complete to sync again");
            return;
        }

        var dataset = sender as Dataset;

        if (dataset != null && dataset.Metadata != null)
        {
            Debug.Log("Successfully synced for dataset : " + dataset.Metadata.DatasetName);
        }
        else
        {
            //In case we called synchronize after deleting the dataset, we can not access it anymore
            Debug.Log("Successfully synced dataset");
        }

        //Note: Cleanup added for compatibility with datasets created with old versions of the sample
        foreach (string key in dataset.GetAll().Keys)
        {
            if (key.Length < 3)
            {
                dataset.Remove(key);
            }
        }

        IDictionary <string, string> dic = dataset.GetAll();

        string[] characterStrings = new string[dic.Count];
        dic.Values.CopyTo(characterStrings, 0);

        CharacterList charList = GetComponent <CharacterList> ();

        charList.DeserializeCharacters(characterStrings);

        GetComponent <CharacterList> ().enabled = true;        //Enable GUI
    }