//--------------------------------------------------------------------------------------------- // 会員登録を行うメソッド //--------------------------------------------------------------------------------------------- private IEnumerator userRegistrationCoroutine() { // NCMBUserクラスのインスタンス生成 NCMBUser user = new NCMBUser(); // パスワード,初期ポイント,初期金額を設定 string password = genRandomString(16); user.Password = password; user.Add("points", initialPoints); user.Add("money", initialMoney); // UserIDが重複したらやり直し bool isSuccess = false; while (!isSuccess) { bool isConnecting = true; // ランダム文字列でユーザ名を設定してユーザ登録実行(非同期処理) user.UserName = genRandomString(16); user.SignUpAsync((NCMBException e) => { if (e != null) { // ユーザ登録失敗 if (e.ErrorCode != NCMBException.DUPPLICATION_ERROR) { // ユーザ名重複以外のエラーが発生 Debug.Log("Failed to registerate: " + e.ErrorMessage); } } else { // ユーザ登録成功 isSuccess = true; Debug.Log("Succeeded to registrate"); // Unity(端末)に情報を設定 PlayerPrefs.SetString("_user_name_", user.UserName); PlayerPrefs.SetString("_pass_word_", password); } // ユーザ登録処理(1ループ)終了 isConnecting = false; }); // ユーザ登録処理(1ループ)が終了するまで以下の行でストップ(強制的に同期処理にする) yield return(new WaitWhile(() => { return isConnecting; })); } }
public void Register() { // Userインスタンスの生成 NCMBUser user = new NCMBUser(); // ユーザー名・パスワードを設定 user.UserName = "******"; /* ユーザー名 */ user.Password = "******"; /* パスワード */ user.Add("phone", "987-654-3210"); /* 任意フィールドも追加可能 */ // ユーザーの新規登録処理 user.SignUpAsync((NCMBException e) => { if (e != null) { UnityEngine.Debug.Log("ユーザーの新規登録に失敗: " + e.ErrorMessage); } else { UnityEngine.Debug.Log("ユーザーの新規登録に成功"); } }); }
/// <summary> /// ユーザー情報を更新する /// (パスワードは NCMB の仕様で更新できない) /// </summary> /// <param name="email"></param> /// <param name="customData"></param> void UpdateUserInfo(string email, string customData) { NCMBUser user = NCMBUser.CurrentUser; if (user == null) { Debug.LogWarning("Not logged in. Log in first."); return; } if (email != "") { user.Email = email; } // カスタムデータはキーがない可能性があるため、キーがある場合はデータを更新し、キーがない場合はキーとデータのペアを追加する if (user.ContainsKey(m_customDataKey)) { user[m_customDataKey] = customData; } else { Debug.LogFormat("Key [{0}] is not found. Add key...", m_customDataKey); user.Add(m_customDataKey, customData); } user.SaveAsync((NCMBException e) => { if (e != null) { Debug.LogError("Failed to save: " + e.ErrorMessage); } else { Debug.Log("Saved successfully."); } }); }