示例#1
0
    private IEnumerator PostScore(string playerName, int score)
    {
        Debug.Log(playerName + "のスコア" + score + "を新規投稿します。");

        var scoreData = new ScoreDataSend {
            playerName = playerName, score = score
        };
        NCMBDataStoreParamSet paramSet = new NCMBDataStoreParamSet(scoreData);

        IEnumerator coroutine = ncmbRestController.Call(NCMBRestController.RequestType.POST, "classes/" + DATASTORE_CLASSNAME, paramSet);

        yield return(StartCoroutine(coroutine));

        JsonUtility.FromJsonOverwrite((string)coroutine.Current, paramSet);

        yield return(paramSet.objectId);
    }
示例#2
0
    private IEnumerator PutScore(string playerName, int score, string objectId)
    {
        string formerPlayerName = PlayerPrefs.GetString(PLAYERNAME);

        if (formerPlayerName != playerName)
        {
            Debug.Log("プレイヤー名が " + formerPlayerName + " から " + playerName + " に変更されました");
            PlayerPrefs.SetString(PLAYERNAME, playerName);
        }

        Debug.Log(playerName + "のスコア" + score + "を更新します。レコードのID:" + objectId);

        var scoreData = new ScoreDataSend {
            playerName = playerName, score = score
        };
        NCMBDataStoreParamSet paramSet = new NCMBDataStoreParamSet(scoreData);

        IEnumerator coroutine = ncmbRestController.Call(
            NCMBRestController.RequestType.PUT, "classes/" + DATASTORE_CLASSNAME + "/" + objectId, paramSet,
            (erroCode) =>
        {
            if (erroCode == 404)
            {
                Debug.Log("レコードID:" + objectId + "が見つからなかったため、新規レコードを作成します");
                StartCoroutine(SendScoreUncheck(playerName, score));
            }
        }

            );

        yield return(StartCoroutine(coroutine));

        JsonUtility.FromJsonOverwrite((string)coroutine.Current, paramSet);

        yield return(paramSet.objectId);
    }