예제 #1
0
    public void SaveGraveInfo(string userName, string deathMessage, GraveInfo.CurseType curseType, Vector3 position)
    {
        //ユーザー名が空の場合"Unknown"に//
        userName = string.IsNullOrEmpty(userName) ? "Unknown" : userName;

        //プレイヤーが死んだ位置を加工//
        position = new Vector3(position.x, 0f, position.z);
        double[] positionDoubleArray = Utility.Vector3toDoubleArray(position);

        //データストアにGraveクラスを定義//
        NCMBObject ncmbObject = new NCMBObject("Grave");

        //Message・UserName・Position・CurseTypeをKeyに、それぞれValueを設定//
        ncmbObject.Add("Message", deathMessage);
        ncmbObject.Add("UserName", userName);
        ncmbObject.Add("Position", positionDoubleArray);
        ncmbObject.Add("CurseType", (int)curseType);

        //非同期でデータを保存する//
        ncmbObject.SaveAsync((NCMBException e) =>
        {
            if (e != null)
            {
                //エラー処理
            }
            else
            {
                Main.Instance.OnInGame();
            }
        });
    }
예제 #2
0
    public void ACLObject()
    {
        //NCMBACLオブジェクトを作成
        NCMBACL acl = new NCMBACL();

        //読み込み権限を全開放
        acl.PublicReadAccess = true;

        //書き込み権限を全開放
        acl.PublicWriteAccess = true;

        NCMBObject obj = new NCMBObject("TestClass");

        obj.Add("Name", "Unity");
        obj.Add("message", "ACL");
        obj.ACL = acl;
        obj.SaveAsync((NCMBException e) => {
            if (e != null)
            {
                //エラー処理
                Debug.LogError(e);
            }
            else
            {
                //成功時の処理
                lastedObjectID = obj.ObjectId;
                Debug.Log("Save object with ACL success " + lastedObjectID);
            }
        });
    }
예제 #3
0
    public void SavePlayerData()
    {
        string     name  = PlayerPrefs.GetString("name");
        int        score = PlayerPrefs.GetInt("score");
        NCMBObject obj   = new NCMBObject("HighScore");

        if (PlayerPrefs.HasKey("objectId"))
        {
            obj.ObjectId = PlayerPrefs.GetString("objectId");
        }
        obj.Add("name", name);
        obj.Add("score", score);
        obj.SaveAsync((NCMBException e) => {
            if (e != null)
            {
                Debug.Log("保存失敗、通信環境を確認してください");
            }
            else
            {
                Debug.Log("保存成功!");
                if (PlayerPrefs.HasKey("objectId") == false)
                {
                    PlayerPrefs.SetString("objectId", obj.ObjectId);
                }
            }
        });
    }
예제 #4
0
    /// <summary>
    /// メッセージを送信する
    /// </summary>
    /// <param name="obj">メッセージの送信相手</param>
    /// <param name="message">メッセージ内容</param>
    /// <param name="callback">コールバック関数</param>
    public void SendMessage(NCMBUser obj, string message, ErrorCallBack callback)
    {
        if (!GetIsLogIn)
        {
            callback(new NCMBException(NCMBUTErrorMessage.NOT_LOGIN_ERROR));
            return;
        }

        if (message == "")
        {
            callback(new NCMBException(NCMBUTErrorMessage.EMPTY_MESSAGE));
            return;
        }

        NCMBObject messageObj = GetClassObject(NCMBUTMessagesDefaultSettings.MESSAGE_CLASS);

        messageObj.Add(NCMBUTMessagesDefaultSettings.MessagesDefaultFields.message.ToString(), message);
        messageObj.Add(NCMBUTMessagesDefaultSettings.MessagesDefaultFields.from.ToString(), NCMBUser.CurrentUser);
        messageObj.Add(NCMBUTMessagesDefaultSettings.MessagesDefaultFields.to.ToString(), obj);
        messageObj.SaveAsync((NCMBException error) => {
            ClearValues();
            callback(error);
            return;
        });
    }
예제 #5
0
    public void SendHighScore(int sendScore)
    {
        Debug.Log("hoge");
        //		nirty上の表の名前をインスタンス時のかっこの中に入れる
        NCMBObject obj = new NCMBObject("OnlineRanking");

        //		もともとObjectIdを持っていたらObjectIdをセットする
        if (PlayerPrefs.HasKey("ObjectId"))
        {
            obj.ObjectId = PlayerPrefs.GetString("ObjectId");
        }
        //		データカラムを追加する
        obj.Add("UserName", PlayerPrefs.GetString("name"));
        obj.Add("HighScore", sendScore);
        obj.SaveAsync((NCMBException e) => {
            if (e != null)
            {
                //エラー処理
                Debug.Log("score data failed");
            }
            else
            {
                //成功時の処理
                Debug.Log("score data sent successfully");
                PlayerPrefs.SetString("ObjectId", obj.ObjectId);
            }
        });
    }
예제 #6
0
    //=====================NCMBと通信、データの保存や取得をする関数=====================

    //-*-*- 使うKey一覧 *-*-*

    //▶︎PlayCount (総プレイ回数)
    //▶︎Ave (平均クリアTime)
    //▶︎Sum (合計プレイ時間)
    //▶︎BestTime

    //-*-*-*-*-*-*-*-*-*-*-*

    //NCMBにplayデータを保存する関数
    public void SaveNCMB()
    {
        //NCMBObjectのインスタンスを作成→変数ncmbObjに格納
        NCMBObject obj = new NCMBObject("OnlineRanking"); //OnlineRankingテーブルのインスタンス作成!

        if (PlayerPrefs.HasKey("objectId") == true)       //objectId持ってた時(2回目以降のセーブの時)
        {
            //Updateの処理
            NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("OnlineRanking");
            query.WhereEqualTo("objectId", PlayerPrefs.GetString("objectId"));
            query.FindAsync((List <NCMBObject> objList, NCMBException e) => {
                if (e != null)
                {
                    //検索失敗時の処理
                    Debug.Log("ミスっとるで!");
                }
                else
                {
                    //値の更新
                    objList[0]["PlayCount"] = playCount; //プレイ回数
                    objList[0]["Ave"]       = ave;       //平均Door突破枚数
                    objList[0]["Sum"]       = sum;       //合計Door突破枚数
                    objList[0]["BestTime"]  = bestTime;  //ベストタイム
                    objList[0].SaveAsync();              //変更内容のsave
                }
            });
        }
        else//objectId持ってない時(初セーブの時)
        {
            //新しく行追加
            obj.Add("PlayCount", playCount);
            obj.Add("Ave", ave);
            obj.Add("Sum", sum);
            obj.Add("BestTime", bestTime);

            obj.SaveAsync((NCMBException e) => { //eには"例外(exeption)"が入ってる→来たらエラー来なかったらok!
                if (e != null)                   //eが空でない時→エラーの時!
                {
                    //エラー時の処理
                    Debug.Log("NCMB Save Missed!");
                }
                else//eが空の時→成功した時!
                {
                    //成功時の処理
                    Debug.Log("NCMB Save Completed!!!");

                    //NCMBObjectのObjectIdを"objectId"キーでPlayerPrefsに保存(次回以降のセーブで同一行のデータを更新していく形にしたい為)
                    PlayerPrefs.SetString("objectId", obj.ObjectId);
                }
            });
        }
    }
    // mobile backendに接続------------------------
    public void save( string name, int score )
    {
        NCMBObject obj = new NCMBObject ("Score");
        obj.Add ("name", name);//オブジェクトに名前とスコアを設定
        obj.Add ("score", score);
        obj.SaveAsync ((NCMBException e) => {
            if (e != null) {
                //エラー処理
            } else {
                //成功時の処理
            }

        });//この処理でサーバーに書き込む
    }
예제 #8
0
        /// <summary>
        /// NCMBObjectの新規作成
        /// </summary>
        /// <returns>NCMBObject</returns>
        /// <param name="className">クラス名</param>
        protected NCMBObject GetPlaneClassObject(string className)
        {
            NCMBObject obj = new NCMBObject(className);

            obj.Add("isEnable", true);
            return(obj);
        }
    public IEnumerator UpdateObject()
    {
        // テストデータ作成
        NCMBUser anonymousUser                     = new NCMBUser();
        Dictionary <string, object> param          = new Dictionary <string, object>();
        Dictionary <string, object> anonymousParam = new Dictionary <string, object>()
        {
            { "id", "anonymousId" }
        };

        param.Add("anonymous", anonymousParam);

        anonymousUser.AuthData = param;
        anonymousUser.SignUpAsync((NCMBException e) => {
            Assert.Null(e);
            Assert.NotNull(NCMBUser.CurrentUser);
            Assert.IsTrue(NCMBUser.CurrentUser.IsLinkWith("anonymous"));

            NCMBObject obj = new NCMBObject("TestClass");
            obj.ObjectId   = "dummyObjectId";
            obj.Add("key", "newValue");
            obj.SaveAsync((NCMBException ex) => {
                Assert.Null(ex);
                NCMBTestSettings.CallbackFlag = true;
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        Assert.NotNull(NCMBUser.CurrentUser);
        Assert.IsTrue(NCMBUser.CurrentUser.IsLinkWith("anonymous"));
    }
예제 #10
0
    public void SavePlayerData(string PlayerName, int score)
    {
        NCMBObject obj = new NCMBObject("PlayerData");

        obj.Add("PlayerName", PlayerName);
        obj.Add("Score", score);
        obj.SaveAsync((NCMBException e) => {
            if (e != null)
            {
                Debug.Log("保存失敗、通信環境を確認してください");
            }
            else
            {
                Debug.Log("保存成功!");
            }
        });
    }
예제 #11
0
        //----------メソッド----------

        private void Start()
        {
            mButton_Publish.onClick.AddListener(() => {
                MasterAudio.Instance.PlaySE(MasterAudio.SE_ID.Button1);
                MasterAnimation.Instance.ButtonAnimation(mButton_Publish.transform);
                MasterAnimation.Instance.FadeOut(mCanvasGroup);
                if (MasterGame.Instance.IsMulti)
                {
                    NCMBObject obj = new NCMBObject("RankingMulti");
                    obj.Add("GameName", mInputField_Name.text);
                    obj.Add("DeveloperName", string.Format("{0},{1},{2}", MasterGame.Instance.DeveloperA.Name, MasterGame.Instance.DeveloperB.Name, MasterGame.Instance.DeveloperC.Name));
                    obj.Add("Score", MasterGame.Instance.Score);
                    obj.Add("Total", MasterGame.Instance.Total);
                    obj.SaveAsync((NCMBException e) => {
                        MasterGame.Instance.LoadScene(MasterGame.Scene_ID.Ranking);
                    });
                }
                else
                {
                    NCMBObject obj = new NCMBObject("RankingSingle");
                    obj.Add("GameName", mInputField_Name.text);
                    obj.Add("DeveloperName", MasterGame.Instance.DeveloperA.Name);
                    obj.Add("Score", MasterGame.Instance.Score);
                    obj.Add("Total", MasterGame.Instance.Total);
                    obj.SaveAsync((NCMBException e) => {
                        MasterGame.Instance.LoadScene(MasterGame.Scene_ID.Ranking);
                    });
                }
            });

            mButton_Retry.onClick.AddListener(() => {
                MasterAudio.Instance.PlaySE(MasterAudio.SE_ID.Button1);
                MasterAnimation.Instance.ButtonAnimation(mButton_Retry.transform);
                MasterAnimation.Instance.FadeOut(mCanvasGroup);
                MasterGame.Instance.LoadScene(MasterGame.Scene_ID.Game);
            });

            mButton_Private.onClick.AddListener(() => {
                MasterAudio.Instance.PlaySE(MasterAudio.SE_ID.Button1);
                MasterAnimation.Instance.ButtonAnimation(mButton_Private.transform);
                MasterAnimation.Instance.FadeOut(mCanvasGroup);
                MasterGame.Instance.LoadScene(MasterGame.Scene_ID.Title);
            });

            mInputField_Name.onValueChanged.AddListener(SetButton);
        }
    void SaveLikeData(string user, string doodle)
    {
        NCMBObject obj = new NCMBObject("LikeRecord");

        obj.Add("doodle", doodle);
        obj.Add("user", user);
        obj.Save((NCMBException e) => {
            if (e != null)
            {
                Debug.Log("save like data error");
            }
            else
            {
                //成功時の処理
            }
        });
    }
    // mobile backendに接続------------------------
    public void save(string name, int score)
    {
        NCMBObject obj = new NCMBObject("Score");

        obj.Add("name", name);         //オブジェクトに名前とスコアを設定
        obj.Add("score", score);
        obj.SaveAsync((NCMBException e) => {
            if (e != null)
            {
                //エラー処理
            }
            else
            {
                //成功時の処理
            }
        });        //この処理でサーバーに書き込む
    }
예제 #14
0
    /// <summary>
    /// プレイヤークラスに追加する
    /// </summary>
    private void savePlayer()
    {
        NCMBQuery <NCMBObject> query = GetPlaneQuery(NCMBUTPlayersDefaultSettings.PLAYERS_CLASS);

        query.WhereEqualTo(NCMBUTPlayersDefaultSettings.PlayersDefaultFields.player.ToString(), NCMBUser.CurrentUser);
        query.FindAsync((List <NCMBObject> objList, NCMBException error) =>
        {
            if (error == null && objList.Count == 0)
            {
                NCMBObject player = GetPlaneClassObject(NCMBUTPlayersDefaultSettings.PLAYERS_CLASS);
                player.Add(NCMBUTPlayersDefaultSettings.PlayersDefaultFields.player.ToString(), NCMBUser.CurrentUser);
                player.Add(NCMBUTPlayersDefaultSettings.PlayersDefaultFields.userName.ToString(), NCMBUser.CurrentUser.UserName);
                player.SaveAsync();
            }

            return;
        });
    }
예제 #15
0
    public void SavePlayerData(string playerName, int score, int coin)
    {
        NCMBObject obj = new NCMBObject("playerData");

        obj.Add("PlayerName", playerName);
        obj.Add("Score", score);
        obj.Add("Coin", coin);

        obj.SaveAsync((NCMBException e) =>
        {
            if (e != null)
            {
                Debug.Log("저장 실패, 통신 환경을 확인하십시오.");
            }
            else
            {
                Debug.Log("저장 성공!");
            }
        });
    }
    public void SendHighScore(int score)
    {
        NCMBObject obj = new NCMBObject("OnlineRanking");

        obj.Add("UserName", PlayerPrefs.GetString("name"));
        obj.Add("HighScore", score);
        //http送って帰ってきたレスポンスがエラーだったら、全部自動でNCMBException型に変換されて帰ってくる、それをeっていう変数に入れてる
        obj.SaveAsync((NCMBException e) => {
            if (e != null)
            {
                //エラー処理
                Debug.Log("score data failed");
            }
            else
            {
                //成功時の処理
                Debug.Log("score data sent successfully");
                PlayerPrefs.SetString("ObjectID", obj.ObjectId);
            }
        });
    }
예제 #17
0
파일: TestScript.cs 프로젝트: fafara/Bushi
    void Create()
    {
        Debug.Log("create");
        NCMBObject obj = new NCMBObject("HighScore");

        obj.Add("score", 2345);
        obj.Add("name", "qwert");
        obj.SaveAsync((NCMBException e) => {
            if (e != null)
            {
                //エラー処理

                Debug.Log("失敗");
            }
            else
            {
                //成功時の処理
                Debug.Log("成功");
                Debug.Log(obj.ObjectId);
            }
        });
    }
예제 #18
0
    /// <summary>
    /// フレンド申請を行う
    /// </summary>
    /// <param name="obj">フレンド申請を行う相手</param>
    /// <param name="callback">コールバック関数</param>
    public void SendFriendRequest(NCMBObject obj, ErrorCallBack callback)
    {
        base.CheckMatchClass(obj.ClassName, new string[] { NCMBUTPlayersDefaultSettings.PLAYERS_CLASS });

        if (!GetIsLogIn)
        {
            callback(new NCMBException(NCMBUTErrorMessage.NOT_LOGIN_ERROR));
            return;
        }

        // 自分から相手へのフレンド申請を登録する
        NCMBObject fromObj = GetPlaneClassObject(NCMBUTFriendsDefaultSettings.FRIEND_CLASS);

        fromObj.Add(NCMBUTFriendsDefaultSettings.FriendsDefaultFields.from.ToString(), NCMBUser.CurrentUser);
        fromObj.Add(NCMBUTFriendsDefaultSettings.FriendsDefaultFields.to.ToString(), (NCMBObject)obj["player"]);
        fromObj.Add(NCMBUTFriendsDefaultSettings.FriendsDefaultFields.isAccept.ToString(), false);
        fromObj.Add(NCMBUTFriendsDefaultSettings.FriendsDefaultFields.isPending.ToString(), true);
        fromObj.SaveAsync((NCMBException fromError) => {
            callback(fromError);

            if (fromError != null)
            {
                return;
            }

            // 相手から自分へのフレンドを登録する
            NCMBObject toObj = GetPlaneClassObject(NCMBUTFriendsDefaultSettings.FRIEND_CLASS);
            toObj.Add(NCMBUTFriendsDefaultSettings.FriendsDefaultFields.from.ToString(), (NCMBObject)obj["player"]);
            toObj.Add(NCMBUTFriendsDefaultSettings.FriendsDefaultFields.to.ToString(), NCMBUser.CurrentUser);
            toObj.Add(NCMBUTFriendsDefaultSettings.FriendsDefaultFields.isAccept.ToString(), false);
            toObj.Add(NCMBUTFriendsDefaultSettings.FriendsDefaultFields.isPending.ToString(), false);
            toObj.SaveAsync((NCMBException toError) => {
                callback(toError);
                return;
            });
        });
    }
예제 #19
0
파일: highscore.cs 프로젝트: YSumita/escape
    // サーバーにハイスコアを保存 -------------------------
    public void Save()
    {
        NCMBObject obj = new NCMBObject("HighScore");

        obj.Add("Name", name);
        obj.Add("Score", highscore);

        if (!PlayerPrefs.HasKey("ObjectIdKey"))
        {
            Debug.Log("abc");
            obj.SaveAsync((NCMBException e) => {
                if (e != null)
                {
                    //エラー処理
                }
                else
                {
                    //成功時の処理
                    PlayerPrefs.SetString("ObjectIdKey", obj.ObjectId);
                }
            });
        }
        else
        {
            obj.ObjectId = PlayerPrefs.GetString("ObjectIdKey");
            obj.SaveAsync((NCMBException e) => {
                if (e != null)
                {
                    //エラー処理
                }
                else
                {
                    //成功時の処理
                }
            });
        }
    }
예제 #20
0
    void saveImageData(string filename)
    {
        NCMBObject obj = new NCMBObject("DoodleRecord");

        obj.Add("username", Configuration.username);
        obj.Add("filename", filename);
        obj.Add("date", DateTime.Now.Date);
        obj.Add("theme", Configuration.theme);
        obj.Add("likes", 0);
        if (Configuration.status == Status.newDoodle)
        {
            obj.Add("type", "doodle");
        }
        else if (Configuration.status == Status.newTheme)
        {
            obj.Add("type", "theme");
        }
        obj.Save((NCMBException e) => {
            if (e != null)
            {
                Debug.Log("save data error");
                showError(e);
            }
            else
            {
                //成功時の処理
                //TODO
                if (Configuration.status == Status.newTheme)
                {
#if UNITY_2019_3_OR_NEWER
                    SceneManager.LoadScene("themes");
#else
                    Application.LoadLevel("themes");
#endif
                }
                else if (Configuration.status == Status.newDoodle)
                {
#if UNITY_2019_3_OR_NEWER
                    SceneManager.LoadScene("doodles");
#else
                    Application.LoadLevel("doodles");
#endif
                }
            }
        });
    }
예제 #21
0
    public void SaveObject()
    {
        NCMBObject obj = new NCMBObject("TestClass");

        obj.Add("Name", "Unity");
        obj.SaveAsync((NCMBException e) => {
            if (e != null)
            {
                //エラー処理
                Debug.LogError(e);
            }
            else
            {
                //成功時の処理
                lastedObjectID = obj.ObjectId;
                Debug.Log("Save object success " + lastedObjectID);
            }
        });
    }
예제 #22
0
        /// <summary>
        /// データストアにセーブ
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="data"></param>
        /// <param name="communicationCallback"></param>
        /// <param name="addUserRelation">NCMBUserにリレーションを付与</param>
        /// <returns></returns>
        public IEnumerator SaveCoroutine(string tableName, Dictionary <string, object> data, Action <CommunicationResult> communicationCallback, bool addUserRelation = false)
        {
            bool isConnecting              = true;
            CommunicationResult cr         = new CommunicationResult();
            NCMBObject          ncmbObject = new NCMBObject(tableName);

            foreach (KeyValuePair <string, object> pair in data)
            {
                ncmbObject.Add(pair.Key, pair.Value);
            }

            ncmbObject.SaveAsync((NCMBException e) =>
            {
                isConnecting = false;

                if (e != null)
                {
                    cr.IsSuccess   = false;
                    cr.ErroMessage = e.ErrorMessage;
                    cr.ErrorCode   = e.ErrorCode;
                }
                else
                {
                    cr.IsSuccess = true;

                    if (addUserRelation)
                    {
                        NCMBUser.CurrentUser.Add(tableName, ncmbObject);
                    }
                    cr.objectId = ncmbObject.ObjectId;
                }
            });

            while (isConnecting)
            {
                yield return(null);
            }

            communicationCallback(cr);
        }
예제 #23
0
    public IEnumerator AddObjectAfterLogin()
    {
        // テストデータ作成
        NCMBUser.LogInAsync("tarou", "tarou", (e) => {
            Assert.Null(e);
            NCMBObject obj = new NCMBObject("TestClass");
            obj.Add("key", "value");
            obj.SaveAsync((NCMBException ex) => {
                Assert.Null(ex);

                NCMBTestSettings.CallbackFlag = true;
            });
        });

        yield return(NCMBTestSettings.AwaitAsync());

        // 登録成功の確認
        Assert.True(NCMBTestSettings.CallbackFlag);
        Assert.AreEqual("tarou", NCMBUser.CurrentUser.UserName);
        Assert.AreEqual("dummySessionToken", NCMBUser._getCurrentSessionToken());
        Assert.AreEqual("*****@*****.**", NCMBUser.CurrentUser.Email);
    }
예제 #24
0
    /// <summary>
    /// スコア送信を行う
    /// </summary>
    /// <param name="score">スコア</param>
    /// <param name="callback">コールバック関数</param>
    public void SendScore(int score, ErrorCallBack callback)
    {
        // 会員登録を行っていた場合、同会員のレコードを検索する
        if (GetIsLogIn)
        {
            NCMBQuery <NCMBObject> query = GetQuery(NCMBUTRankingsDefaultSettings.RANKING_CLASS);
            query.WhereEqualTo(NCMBUTRankingsDefaultSettings.RankingsDefaultFields.player.ToString(), NCMBUser.CurrentUser);
            query.WhereEqualTo(NCMBUTRankingsDefaultSettings.RankingsDefaultFields.stage.ToString(), Stage);
            query.FindAsync((List <NCMBObject> objList, NCMBException error) => {
                if (error != null)
                {
                    callback(error);
                    return;
                }

                if (objList.Count == 0)
                {
                    // 対象会員のレコードがないため新規レコードを作成する
                    NCMBObject scoreObj = GetClassObject(NCMBUTRankingsDefaultSettings.RANKING_CLASS);
                    scoreObj.Add(NCMBUTRankingsDefaultSettings.RankingsDefaultFields.player.ToString(), NCMBUser.CurrentUser);
                    scoreObj.Add(NCMBUTRankingsDefaultSettings.RankingsDefaultFields.score.ToString(), score);
                    scoreObj.Add(NCMBUTRankingsDefaultSettings.RankingsDefaultFields.stage.ToString(), Stage);
                    saveRecord(scoreObj, callback);
                }
                else
                {
                    // 強制上書きフラグがFalseの時かつ、スコアを更新するか確認する
                    if (!ForceUpdate)
                    {
                        switch (Sort)
                        {
                        case NCMBUTSortType.Ascending:
                            if (int.Parse(objList[0][NCMBUTRankingsDefaultSettings.RankingsDefaultFields.score.ToString()].ToString()) < score)
                            {
                                callback(null);
                                return;
                            }
                            break;

                        case NCMBUTSortType.Descending:
                            if (int.Parse(objList[0][NCMBUTRankingsDefaultSettings.RankingsDefaultFields.score.ToString()].ToString()) > score)
                            {
                                callback(null);
                                return;
                            }
                            break;
                        }
                    }
                    objList[0][NCMBUTRankingsDefaultSettings.RankingsDefaultFields.score.ToString()] = score;
                    saveRecord(objList[0], callback);
                }
            });
        }
        else
        {
            // 会員登録していないため常に新規でレコードを作成する
            NCMBObject createObj = GetClassObject(NCMBUTRankingsDefaultSettings.RANKING_CLASS);
            createObj.Add(NCMBUTRankingsDefaultSettings.RankingsDefaultFields.score.ToString(), score);
            createObj.Add(NCMBUTRankingsDefaultSettings.RankingsDefaultFields.stage.ToString(), Stage);
            saveRecord(createObj, callback);
        }
    }
예제 #25
0
    public void Login()
    {
        Debug.Log(Mail.text);
        Debug.Log(Pass.text);
        NCMBUser.LogInWithMailAddressAsync(Mail.text, Pass.text, (NCMBException e) => {
            if (e != null)
            {
                Notification.OpenNotification();
                UnityEngine.Debug.Log("ログインに失敗: " + e.ErrorMessage);
            }
            else
            {
                NCMBUser current = NCMBUser.CurrentUser;
                Userquery.WhereEqualTo("UserID", current.ObjectId);
                Userquery.FindAsync((List <NCMBObject> objList, NCMBException e_userdata) => {
                    if (e_userdata != null)
                    {
                        //検索失敗時の処理
                    }
                    else
                    {
                        if (objList.Count == 0)
                        {
                            UserDataStore.Add("MailAd", Mail.text);
                            UserDataStore.Add("Pass", Pass.text);
                            UserDataStore.Add("UserID", current.ObjectId);
                            UserDataStore.SaveAsync();
                            PlayerPrefs.SetString("MailAd", Mail.text);
                            PlayerPrefs.SetString("Pass", Pass.text);
                        }
                        else
                        {
                            NCMBObject UserData = objList[0];
                            PlayerPrefs.SetString("MailAd", (string)UserData["MailAd"]);
                            PlayerPrefs.SetString("Pass", (string)UserData["Pass"]);
                        }
                    }
                });
                NCMBQuery <NCMBObject> BookMark = new NCMBQuery <NCMBObject> ("BookMark");

                BookMark.WhereEqualTo("UserID", NCMBUser.CurrentUser.ObjectId);
                BookMark.FindAsync((List <NCMBObject> objList, NCMBException er) => {
                    if (e != null)
                    {
                        //検索失敗時の処理
                        Debug.Log("bookmarkError");
                    }
                    else
                    {
                        if (objList.Count == 0)
                        {
                            Debug.Log("Unbookmarked");
                            NCMBObject bookobj = new NCMBObject("BookMark");
                            bookobj.Add("UserID", NCMBUser.CurrentUser.ObjectId);
                            List <string> List = new List <string>();
                            bookobj.Add("Bookmarks", List);
                            bookobj.SaveAsync();
                            return;
                        }
                    }
                });
                UnityEngine.Debug.Log("ログインに成功!");
                //   testvoiddata();
                LoadingScene.LoadNextScene("selection");
                //   SceneManager.LoadScene("selection");
            }
        });
    }
    void RegistBookmark(string ID)
    {
        BookMark.WhereEqualTo("UserID", NCMBUser.CurrentUser.ObjectId);
        BookMark.FindAsync((List <NCMBObject> objList, NCMBException e) => {
            if (e != null)
            {
                //検索失敗時の処理
                Debug.Log("bookmarkError");
            }
            else
            {
                if (objList.Count == 0)
                {
                    Debug.Log("Unbookmarked");
                    NCMBObject bookobj = new NCMBObject("BookMark");
                    bookobj.Add("UserID", NCMBUser.CurrentUser.ObjectId);
                    ArrayList bmArray = new ArrayList();
                    bmArray.Add(ID);
                    bookobj.Add("Bookmarks", bmArray);
                    bookobj.SaveAsync();
                    musicquery.WhereEqualTo("ID", ID);
                    musicquery.FindAsync((List <NCMBObject> MusicList, NCMBException Er) => {
                        NCMBObject MusicData       = MusicList[0];
                        int b_count                = Transition_to_play.BookCount;
                        MusicData["BookmarkCount"] = b_count + 1;
                        MusicData.SaveAsync();
                    });
                    Debug.Log("Saved");
                    return;
                }
                NCMBObject BookmarkData = objList[0];
                if (BookmarkData == null)
                {
                    Debug.Log("BookmarkData==null");
                }
                // Debug.Log((BookmarkData["Bookmarks"]).Count+"bookmarks");
                // Debug.Log((string)BookmarkData["Bookmarks"][0]);

                // List<string> BookMarks = (List<string>)BookmarkData["Bookmarks"];
                ArrayList BookMarksArray = (BookmarkData["Bookmarks"]) as ArrayList;
                List <string> BookMarks  = new List <string> ((string[])BookMarksArray.ToArray(typeof(string)));
                if (BookMarks == null)
                {
                    musicquery.WhereEqualTo("ID", ID);
                    musicquery.FindAsync((List <NCMBObject> MusicList, NCMBException Er) => {
                        NCMBObject MusicData       = MusicList[0];
                        int b_count                = Transition_to_play.BookCount;
                        MusicData["BookmarkCount"] = b_count + 1;
                        MusicData.SaveAsync();
                    });
                    //             musicdata.ObjectId = ID;
                    //             musicdata.FetchAsync((NCMBException error) =>
                    // {
                    //     if (error != null)
                    //     {
                    //         Debug.Log("Error");
                    //     }
                    //     else
                    //     {
                    //         int b_count = (int)musicdata["BookmarkCount"];
                    //         musicdata["BookmarkCount"] = b_count + 1;
                    //         musicdata.SaveAsync();
                    //     }
                    // });
                    // Debug.Log("BookMarks==null");
                    List <string> newbookmarks = new List <string> {
                        ID
                    };
                    // BookMarks.Sort();
                    BookmarkData["Bookmarks"] = newbookmarks;
                    BookmarkData.SaveAsync();
                }
                else
                {
                    // Debug.Log("BookMarks!=null");
                    if (BinarySearch(BookMarks, ID))
                    {
                        BookMarks.RemoveAt(idkey);
                        musicquery.WhereEqualTo("ID", ID);
                        musicquery.FindAsync((List <NCMBObject> MusicList, NCMBException Er) => {
                            NCMBObject MusicData       = MusicList[0];
                            int b_count                = Transition_to_play.BookCount;
                            MusicData["BookmarkCount"] = b_count - 1;
                            MusicData.SaveAsync();
                        });
                        //             musicdata.ObjectId = ID;
                        //             musicdata.FetchAsync((NCMBException error) =>
                        // {
                        //     if (error != null)
                        //     {
                        //         Debug.Log("Error");
                        //     }
                        //     else
                        //     {
                        //         int b_count = (int)musicdata["BookmarkCount"];
                        //         musicdata["BookmarkCount"] = b_count - 1;
                        //         musicdata.SaveAsync();
                        //     }
                        // });
                        Debug.Log("RemoveBookmark");
                    }
                    else
                    {
                        musicquery.WhereEqualTo("ID", ID);
                        musicquery.FindAsync((List <NCMBObject> MusicList, NCMBException Er) => {
                            NCMBObject MusicData       = MusicList[0];
                            int b_count                = Transition_to_play.BookCount;
                            MusicData["BookmarkCount"] = b_count + 1;
                            MusicData.SaveAsync();
                        });
                        BookMarks.Add(ID);
                        BookMarks.Sort();
                        //             musicdata.ObjectId = ID;
                        //             musicdata.FetchAsync((NCMBException error) =>
                        // {
                        //     if (error != null)
                        //     {
                        //         Debug.Log("Error");
                        //     }
                        //     else
                        //     {
                        //         int b_count = (int)musicdata["BookmarkCount"];
                        //         musicdata["BookmarkCount"] = b_count + 1;
                        //         musicdata.SaveAsync();
                        //     }
                        // });
                        Debug.Log("RegistBookmark");
                    }
                    BookmarkData["Bookmarks"] = BookMarks;
                    BookmarkData.SaveAsync();
                }
                // Debug.Log("BookMarks==null");
                // Debug.Log(BookMarks.Count);
                // BookMarks.Sort();
            }
        });
    }