예제 #1
0
 // Goal到着が検知されたとき
 void OnGoal()
 {
     goal = true;
     NCMBObject timeClass = new NCMBObject("Time");
     timeClass["time"] = lapTime;
     timeClass.SaveAsync();
 }
예제 #2
0
 // mobile backendに接続------------------------
 public void save( string name, int score )
 {
     NCMBObject obj = new NCMBObject ("Score");
     obj ["name"] = name;//オブジェクトに名前とスコアを設定
     obj ["score"] = score;
     obj.SaveAsync ();//この処理でサーバーに書き込む
 }
예제 #3
0
 /// <summary>
 /// スコアの保存.
 /// </summary>
 void HighScoreSetter(string playerName, int score)
 {
     NCMBObject obj = new NCMBObject ("HighScore");
     obj ["Name"] = playerName;
     obj ["Score"] = score;
     obj.SaveAsync ();
 }
        // サーバーからハイスコアを取得  -----------------
        public void fetch()
        {
            // データストアの「HighScore」クラスから、Nameをキーにして検索
              NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore");
              query.WhereEqualTo ("Name", name);
              query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => {

              //検索成功したら
              if (e == null) {

            // ハイスコアが未登録だったら
            if( objList.Count == 0 )
              {
            NCMBObject obj = new NCMBObject("HighScore");
            obj["Name"]  = name;
            obj["Score"] = 0;
            obj.SaveAsync();
            score = 0;
              }

            // ハイスコアが登録済みだったら
            else {
              score = System.Convert.ToInt32( objList[0]["Score"] );
            }
              }
            });
        }
예제 #5
0
 // サーバーからハイスコアを取得する
 public void fetch()
 {
     Debug.Log ("fetch name " + name);
     // データストアの「HighScore」から,Nameをキーにして検索する
     NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore");
     query.WhereEqualTo ("Name", name);
     query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => {
         //検索が成功した場合
         if (e == null) {
             // ハイスコアが未登録だった場合
             if (objList.Count == 0) {
                 NCMBObject obj = new NCMBObject ("HighScore");
                 obj ["Name"] = name;
                 obj ["Score"] = 0;
                 obj.SaveAsync ();
                 //score = 0;
                 Debug.Log ("取得1");
             }
             // ハイスコアが登録済みだった場合
             else {
                 score = System.Convert.ToInt32 (objList [0] ["Score"]);
                 Debug.Log ("取得2");
             }
         }
     });
 }
예제 #6
0
 // サーバーにコメントを保存 -------------------------
 public void save()
 {
     // Commentクラスのオブジェクトをつくる
     NCMBObject obj = new NCMBObject ("Comment");
     // フィールドを設定して保存
     obj["Wave"]   = wave;
     obj["Text"]   = text;
     obj["Player"] = player;
     obj.SaveAsync ();
 }
        //前回のローカルデータから新規ローカルデータの作成
        public object Apply(object oldValue, NCMBObject obj, string key)
        {
            //前回のローカルデータ(estimatedDataに指定のキーが無い場合)がNullの場合
            if (oldValue == null) {
                //return new List<object> ();
                return new ArrayList ();//追加
            }
            //配列のみリムーブ実行
            if ((oldValue is IList)) {

                //削除処理を行う
                //ArrayList result = new ArrayList ((IList)oldValue);
                //result = NCMBUtility._removeAllFromListMainFunction ((IList)oldValue, this.objects);

                //取り出したローカルデータから今回の引数で渡されたオブジェクトの削除
                ArrayList result = new ArrayList ((IList)oldValue);
                foreach (object removeObj in this.objects) {
                    while (result.Contains(removeObj)) {//removeAllと同等
                        result.Remove (removeObj);
                    }
                }
                //以下NCMBObject重複処理
                //今回引数で渡されたオブジェクトから1.のオブジェクトの削除
                ArrayList objectsToBeRemoved = new ArrayList ((IList)this.objects);

                foreach (object removeObj2 in result) {
                    while (objectsToBeRemoved.Contains(removeObj2)) {//removeAllと同等
                        objectsToBeRemoved.Remove (removeObj2);
                    }
                }

                //結果のリスト(引数)の中のNCMBObjectがすでに保存されている場合はobjectIdを返す
                HashSet<object> objectIds = new HashSet<object> ();
                foreach (object hashSetValue in objectsToBeRemoved) {
                    if (hashSetValue is NCMBObject) {
                        NCMBObject valuesNCMBObject = (NCMBObject)hashSetValue;
                        objectIds.Add (valuesNCMBObject.ObjectId);
                    }

                    //resultの中のNCMBObjectからobjectIdsの中にあるObjectIdと一致するNCMBObjectの削除
                    object resultValue;
                    for (int i = 0; i < result.Count; i++) {
                        resultValue = result [i];
                        if (resultValue is NCMBObject) {
                            NCMBObject resultNCMBObject = (NCMBObject)resultValue;
                            if (objectIds.Contains (resultNCMBObject.ObjectId)) {
                                result.RemoveAt (i);
                            }
                        }
                    }
                }
                return result;
            }
            throw new  InvalidOperationException ("Operation is invalid after previous operation.");
        }
        public object Apply(object oldValue, NCMBObject obj, string key)
        {
            if (oldValue == null) {
                return this.amount;
            }
            if (oldValue is string || oldValue == null) {
                throw new  InvalidOperationException ("You cannot increment a non-number.");

            }
            return NCMBObject._addNumbers (oldValue, this.amount);
        }
예제 #9
0
 public object Apply(object oldValue, NCMBObject obj, string key)
 {
     if (oldValue == null) {
         return this.objects;
     }
     if ((oldValue is IList)) {
         ArrayList result = new ArrayList ((IList)oldValue);
         result.AddRange (this.objects);
         return result;
     }
     throw new  InvalidOperationException ("Operation is invalid after previous operation.");
 }
    // 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 {
                //成功時の処理
            }

        });//この処理でサーバーに書き込む
    }
        public object Apply(object oldValue, NCMBObject obj, string key)
        {
            //初回 estimatedDataに対象のデータが無かった場合
            if (oldValue == null) {
                return new ArrayList (this.objects);//追加
            }

            //estimatedDataにすでに対象データがあり,配列だった場合
            if ((oldValue is IList)) {
                ArrayList result = new ArrayList ((IList)oldValue);	//追加

                //前回のオブジェクトのobjectIDを補完する。 key : objectId value : int(連番)
                Hashtable existingObjectIds = new Hashtable ();
                //全要素検索
                foreach (object resultValue in result) {
                    int i = 0;
                    //前回のオブジェクトからNCMBObjectの要素を検索
                    if (resultValue is NCMBObject) {
                        //あればkeyにobjectId,valueに連番を追加
                        NCMBObject resultNCMBObject = (NCMBObject)resultValue;
                        existingObjectIds.Add (resultNCMBObject.ObjectId, i);//追加したいNCMBObjectのid
                    }
                }

                //同じNCMBObjectだったら重複しないようAPI側でさばいているかも
                IEnumerator localEnumerator = this.objects.GetEnumerator ();
                while (localEnumerator.MoveNext()) {
                    object objectsValue = (object)localEnumerator.Current;
                    if ((objectsValue is NCMBObject)) {
                        //objrcts2のobjectIdと先ほど生成したexistingObjectIdsのobjectIDが一致した場合、
                        //existingObjectIdsのvalue:連番を返す。なければnull
                        NCMBObject objectsNCMBObject = (NCMBObject)objectsValue;
                        if (existingObjectIds.ContainsKey (objectsNCMBObject.ObjectId)) {
                            //すでにある
                            int index = Convert.ToInt32 (existingObjectIds [objectsNCMBObject.ObjectId]);
                            result.Insert (index, objectsValue);
                        } else {
                            //ユニークなのでadd。追加する
                            result.Add (objectsValue);
                        }
                    } else if (!result.Contains (objectsValue)) {
                        //基本的にこちら。重複していない値のみaddする
                        result.Add (objectsValue);
                    }
                }
                return result;
            }
            //対象データが配列以外だった場合
            throw new  InvalidOperationException ("Operation is invalid after previous operation.");
        }
예제 #12
0
 public void Login()
 {
     NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("TestClass");
     query.WhereEqualTo ("message", "Hello, Tarou!");
     query.FindAsync ((List<NCMBObject> objectList,NCMBException e) => {
         if (objectList.Count != 0) {
             NCMBObject obj = objectList [0];
             Debug.Log ("message : " + obj ["message"]);
         } else {
             NCMBObject testClass = new NCMBObject ("TestClass");
             testClass ["message"] = "Hello, NCMB!";
             testClass.SaveAsync ();
         }
     });
 }
예제 #13
0
    void OnGUI()
    {
        //getMessage from server
        NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("Message");
        query.WhereEqualTo ("placeid", "1");
        query.FindAsync ((List<NCMBObject> objectList,NCMBException e) => {
            if (objectList.Count != 0) {
                NCMBObject obj = objectList [0];
                string message = (string) obj["msg"];
                GUI.Label(new Rect(0,0,Screen.width,Screen.height), message);
                //Save log
                NCMBObject testClass = new NCMBObject ("ShowLog");
                testClass ["message"] = "Unitychan is showed";
                testClass.SaveAsync ();
            } else {

            }
        });
    }
예제 #14
0
파일: HelloNCMB.cs 프로젝트: saihe/Unity
    // Use this for initialization
    void Start()
    {
        NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject>("TestClass");
        query.WhereEqualTo("message", "Hello, Tarou!");
        query.FindAsync((List<NCMBObject> objectList, NCMBException e) => {
            if (objectList.Count != 0)
            {
                NCMBObject obj = objectList[0];
                Debug.Log("message : " + obj["message"]);
            }
            else
            {
                NCMBObject testClass = new NCMBObject("TestClass");
                testClass["message"] = "Hello, NCMB!";
                testClass.SaveAsync();

                scoretext = Score.GetComponent<GUIText>();
                print("scoretext: " + scoretext);
                //scoretext.text = testClass["message"].ToString();
            }
        });
    }
예제 #15
0
    // Use this for initialization
    void Start()
    {
        NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("Score");
        query.OrderByDescending ("score");
        query.Limit = 1;
        query.FindAsync ((List<NCMBObject> objList,NCMBException e)=>{

            if(e !=null){
                //検索失敗時の処理
            }else{
                //検索成功時の処理
                //取得したレコードをscoreクラスとして保存
                if(objList.Count > 0){
                    Debug.Log("GhostData");
                    readyGhost = true;
                    foreach(NCMBObject obj in objList){
                        posObj = obj;
                    }
                }
            }
        });
    }
예제 #16
0
		// ハイスコアを更新して保存 -------------------------
		public void updateScore()
		{
			#if False
			NCMBObject obj = new NCMBObject("HighScore");
			obj["Uuid"]  = uuid;
			obj["Name"]  = name;
			obj["Score"] = score;
			obj.SaveAsync();
			#else
			// データストアの「HighScore」クラスから、Uuidをキーにして検索
			NCMBQuery<NCMBObject> query = new NCMBQuery<NCMBObject> ("HighScore");
			query.WhereEqualTo ("Uuid", uuid);
			query.FindAsync ((List<NCMBObject> objList ,NCMBException e) => {
				
				//検索成功したら    
				if (e == null) {
					objList[0]["Score"] = score;
					objList[0]["Uuid"] = uuid;
					objList[0]["Name"] = name;
					objList[0].SaveAsync();
				}
			});
			#endif
		}
    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();
            }
        });
    }
예제 #18
0
 public object Apply(object oldValue, NCMBObject obj, string key)
 {
     return this.Value;
 }
 public object Apply(object oldValue, NCMBObject obj, string key)
 {
     return null;
 }
예제 #20
0
        /// <summary>
        /// 疎通テストのプロセス
        /// </summary>
        /// <param name="i_callback">完了コールバック</param>
        /// <returns></returns>
        private IEnumerator CommunicateTestProcess(Action i_callback)
        {
            this.IsRunning = true;

            UnityEngine.Object settingprefab = Resources.Load(PATH_NCMBSETTING_PREFAB);
            GameObject         settingObject = GameObject.Instantiate <GameObject>(settingprefab as GameObject);
            NCMBSettings       settings      = settingObject != null?settingObject.GetComponent <NCMBSettings>() : null;

            if (settings == null)
            {
                yield break;
            }

            // マルチシーンで意図しないシーンにインスタンス化しないように親子付け
            settingObject.transform.SetParent(this.transform);

            // アプリケーションキー、クライアントキー設定確認(空かどうかだけ)
            if (string.IsNullOrEmpty(settings.applicationKey) || string.IsNullOrEmpty(settings.clientKey))
            {
                EditorUtility.DisplayDialog("Error", "NCMBSettingsの設定不備があります。\n講師へ申し出をして下さい。", "OK");
                yield break;
            }

            // 疎通用送信データとしてローカルIPアドレスを取得
            string ipAddress = GetIpAddress();

            if (ipAddress == string.Empty)
            {
                EditorUtility.DisplayDialog("Error", "ローカルIPアドレスの取得に失敗しました。\nネットワークに未接続の可能性があります。", "OK");
                yield break;
            }

            bool isFinshed = false;
            NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("CommunicateTest");

            query.WhereEqualTo("IP", ipAddress);
            query.FindAsync((List <NCMBObject> i_objectList, NCMBException i_exception) =>
            {
                if (i_exception != null)
                {
                    EditorUtility.DisplayDialog("Error", string.Format("NCMB接続時にエラーが発生しました。\n講師へ申し出をして下さい。\n(エラーメッセージ:{0})", i_exception.Message), "OK");
                    return;
                }

                if (i_objectList.Count > 0)
                {
                    i_objectList[0]["IP"] = ipAddress;
                    i_objectList[0].Save();
                }
                else
                {
                    NCMBObject newObject = new NCMBObject("CommunicateTest");
                    newObject["IP"]      = ipAddress;
                    newObject.Save();
                }

                EditorUtility.DisplayDialog("完了", "疎通テストが正常に完了しました。", "OK");

                isFinshed = true;
            });

            while (isFinshed == false)
            {
                yield return(null);
            }

            if (i_callback != null)
            {
                i_callback();
            }

            this.IsRunning = false;
        }
예제 #21
0
 //コンストラクター
 internal NCMBRelation(NCMBObject parent, string key)
 {
     this._parent      = parent;
     this._key         = key;
     this._targetClass = null;
 }
예제 #22
0
        //estimatedDataのvalueの値がオブジェクト型の場合はここで適切に変換
        private static IDictionary <string, object> _encodeJSONObject(object value, bool allowNCMBObjects)
        {
            //日付型をNcmb仕様に変更してクラウドに保存
            if (value is DateTime)
            {
                DateTime dt = (DateTime)value;
                Dictionary <string, object> Datedic = new Dictionary <string, object> ();
                string iso = dt.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'");
                Datedic.Add("__type", "Date");
                Datedic.Add("iso", iso);
                return(Datedic);
            }
            if (value is NCMBObject)
            {
                NCMBObject obj = (NCMBObject)value;
                if (!allowNCMBObjects)
                {
                    throw new ArgumentException("NCMBObjects not allowed here.");
                }
                //GetRelationなどしたオブジェクトが未保存の場合はエラー
                if (obj.ObjectId == null)
                {
                    throw new ArgumentException("Cannot create a pointer to an object without an objectId.");
                }
                Dictionary <string, object> NCMBDic = new Dictionary <string, object> ();
                NCMBDic.Add("__type", "Pointer");
                NCMBDic.Add("className", obj.ClassName);
                NCMBDic.Add("objectId", obj.ObjectId);
                return(NCMBDic);
            }
            if (value is NCMBGeoPoint)
            {
                NCMBGeoPoint point = (NCMBGeoPoint)value;
                Dictionary <string, object> GeoDic = new Dictionary <string, object> ();
                GeoDic.Add("__type", "GeoPoint");
                GeoDic.Add("latitude", point.Latitude);
                GeoDic.Add("longitude", point.Longitude);
                return(GeoDic);
            }

            //MiniJsonで処理できる
            if (value is IDictionary)
            {
                Dictionary <string, object> beforeDictionary = new Dictionary <string, object> ();
                IDictionary afterDictionary = (IDictionary)value;
                foreach (object key in afterDictionary.Keys)
                {
                    if (key is string)
                    {
                        beforeDictionary [(string)key] = _maybeEncodeJSONObject(afterDictionary [key], allowNCMBObjects);
                    }
                    else
                    {
                        throw new NCMBException(new ArgumentException("Invalid type for key: " + key.GetType().ToString() + ".key type string only."));
                    }
                }

                return(beforeDictionary);
            }

            if (value is NCMBRelation <NCMBObject> )
            {
                NCMBRelation <NCMBObject> relation = (NCMBRelation <NCMBObject>)value;
                return(relation._encodeToJSON());
            }

            if (value is NCMBACL)
            {
                NCMBACL acl = (NCMBACL)value;
                return(acl._toJSONObject());
            }
            return(null);
        }
예제 #23
0
        internal static Object decodeJSONObject(object jsonDicParameter)
        {
            //check array
            if (jsonDicParameter is IList)
            {
                ArrayList     tmpArrayList = new ArrayList();
                List <object> objList      = new List <object> ();
                objList = (List <object>)jsonDicParameter;
                //NCMBDebug.Log (" Check list!!");
                object objTmp = null;
                for (int i = 0; i < objList.Count; i++)                   // Loop through List with for
                //NCMBDebug.Log (" List item " + objList [i]);
                {
                    objTmp = decodeJSONObject(objList [i]);
                    if (objTmp != null)
                    {
                        tmpArrayList.Add(decodeJSONObject(objList [i]));
                    }
                    else
                    {
                        tmpArrayList.Add(objList [i]);
                    }
                }
                return(tmpArrayList);
            }

            //check if json or not
            Dictionary <string, object> jsonDic;

            if ((jsonDicParameter is IDictionary))
            {
                jsonDic = (Dictionary <string, object>)jsonDicParameter;
            }
            else
            {
                return(null);
            }
            object typeString;

            jsonDic.TryGetValue("__type", out typeString);

            /*
             *                      if (typeString == null) {
             *                                      return jsonDic;
             *                      }
             */

            if (typeString == null)               //Dictionary
            {
                Dictionary <string, object> tmpDic = new Dictionary <string, object> ();
                object decodeObj;
                foreach (KeyValuePair <string, object> pair in jsonDic)
                {
                    decodeObj = decodeJSONObject(pair.Value);
                    if (decodeObj != null)
                    {
                        //NCMBDebug.Log ("[TEST:" + pair.Key + " VALUE:" + pair.Value);
                        tmpDic.Add(pair.Key, decodeObj);
                    }
                    else
                    {
                        tmpDic.Add(pair.Key, pair.Value);
                    }
                }
                //return jsonDic;
                return(tmpDic);
            }


            if (typeString.Equals("Date"))
            {
                object iso;
                jsonDic.TryGetValue("iso", out iso);
                return(parseDate((string)iso));
            }

            if (typeString.Equals("Pointer"))
            {
                object className;
                jsonDic.TryGetValue("className", out className);
                object objectId;
                jsonDic.TryGetValue("objectId", out objectId);
                return(NCMBObject.CreateWithoutData((string)className, (string)objectId));
            }

            if (typeString.Equals("GeoPoint"))
            {
                double latitude  = 0;
                double longitude = 0;
                try {
                    object latitudeString;
                    jsonDic.TryGetValue("latitude", out latitudeString);
                    latitude = (double)Convert.ToDouble(latitudeString);
                    object longitudeString;
                    jsonDic.TryGetValue("longitude", out longitudeString);
                    longitude = Convert.ToDouble(longitudeString);
                } catch (Exception e) {
                    throw new NCMBException(e);
                }
                return(new NCMBGeoPoint(latitude, longitude));
            }

            if (typeString.Equals("Object"))
            {
                object className;
                jsonDic.TryGetValue("className", out className);
                NCMBObject output = NCMBObject.CreateWithoutData((string)className, null);
                output._handleFetchResult(true, jsonDic);
                return(output);
            }

            //Relation対象クラスを増やす時は要注意
            if (typeString.Equals("Relation"))
            {
                if (jsonDic ["className"].Equals("user"))
                {
                    return(new NCMBRelation <NCMBUser> ((string)jsonDic ["className"]));
                }
                else if (jsonDic ["className"].Equals("role"))
                {
                    return(new NCMBRelation <NCMBRole> ((string)jsonDic ["className"]));
                }
                else
                {
                    return(new NCMBRelation <NCMBObject> ((string)jsonDic ["className"]));
                }
            }

            return(null);
        }
예제 #24
0
 /// <summary>
 /// フレンド申請の拒否を行うメソッド
 /// </summary>
 /// <param name="target">拒否するユーザ</param>
 private void declineFriendRequest(NCMBObject target)
 {
     Connection.DeclineFriendRequest(target, new ErrorCallBack(setDeclineFriendRequestError));
 }
예제 #25
0
 /// <summary>
 /// フレンド申請の承認を行うメソッド
 /// </summary>
 /// <param name="target">承認するユーザ</param>
 private void acceptFriendRequest(NCMBObject target)
 {
     Connection.AcceptFriendRequest(target, new ErrorCallBack(setAcceptFriendRequestError));
 }
예제 #26
0
 /// <summary>
 /// フレンド申請を送るメソッド
 /// </summary>
 /// <param name="target">申請するユーザ</param>
 private void sendFriendRequest(NCMBObject target)
 {
     Connection.SendFriendRequest(target, new ErrorCallBack(setSendFriendRequestError));
 }
예제 #27
0
 /// <summary>
 /// メッセージを削除するメソッド
 /// </summary>
 /// <param name="target">削除するメッセージ</param>
 private void removeMessage(NCMBObject target)
 {
     Connection.RemoveMessage(target, new ErrorCallBack(setRemoveMessageError));
 }
예제 #28
0
    // アップロード
    public void UploadLevel()
    {
        // レベルを更新してないとアップロードさせない
        if (level == 1 || level <= PlayerPrefs.GetInt(LAST_LEVEL_UPLOAD_KEY))
        {
            Message("レベルを更新してください。");
            return;
        }
        // 名前を入力してないとアップロードさせない
        string upName = nameField.text;

        if (string.IsNullOrEmpty(upName))
        {
            Message("名前を入力してください。");
            return;
        }
        // アップロードする
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("Ranking");

        query.WhereEqualTo("Name", upName);
        query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
        {
            if (e == null)
            {
                if (objList.Count == 0)
                {
                    // 新規登録
                    NCMBObject obj = new NCMBObject("Ranking");
                    obj["Name"]    = upName;
                    obj["Level"]   = level;
                    obj.SaveAsync((NCMBException ee) =>
                    {
                        if (ee == null)
                        {
                            Uploaded();
                        }
                        else
                        {
                            Message("エラーが発生しました。");
                        }
                    });
                }
                else
                {
                    // 念のためサーバの値より大きいときのみ更新
                    float cloudLevel = (float)System.Convert.ToDouble(objList[0]["Level"]);
                    if (level > cloudLevel)
                    {
                        objList[0]["Level"] = level;
                        objList[0].SaveAsync((NCMBException ee) =>
                        {
                            if (ee == null)
                            {
                                // アップロード成功
                                Uploaded();
                            }
                            else
                            {
                                Message("エラーが発生しました。");
                            }
                        });
                    }
                    else
                    {
                        // ランキングを更新
                        GetRanking();
                    }
                }
            }
            else
            {
                Message("エラーが発生しました。");
            }
        });
    }
예제 #29
0
 /// <summary>
 /// フレンドの削除を行うメソッド
 /// </summary>
 /// <param name="friend">削除するユーザ</param>
 private void removeFriend(NCMBObject friend)
 {
     Connection.RemoveFriend(friend, new ErrorCallBack(setRemoveFriendError));
 }
예제 #30
0
    // public bool Ready=false;

    void Start()
    {
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject> ("MusicData");

        query.Limit = 1;
        query.FindAsync((List <NCMBObject> objList, NCMBException e) => {
            if (e != null)
            {
                Debug.Log("検索失敗時の処理");
                //検索失敗時の処理
            }
            else
            {
                NCMBObject Data = objList[0];
                Debug.Log(Data["Title"]);
                Debug.Log(Data["Comment"]);
                // NCMBFile file=new NCMBFile(Data["ID"].ToString());
                NCMBFile file = new NCMBFile("83is6C0qeCRD1Rfa");
                file.FetchAsync((byte[] fileData, NCMBException error) => {
                    if (error != null)
                    {
                        UnityEngine.Debug.Log("file検索失敗時の処理");
                    }
                    else
                    {
                        LoadMSF(fileData);
                        ModificationEventTimes();
                        Debug.Log(noteList.Count);
                        // Debug.Log(tempoList.Count);
                        // Debug.Log("EventTime");
                        KeyCode = new bool[130, Enumerable.Last(noteList).eventTime *2];
                        for (int i = 0; i < noteList.Count; i++)
                        {
                            Debug.Log(noteList[i].laneIndex + " , " + noteList[i].eventTime / 100);
                            if (noteList[i].type != NoteType.LongEnd)
                            {
                                KeyCode[noteList[i].laneIndex - 21, noteList[i].eventTime / 100] = true;
                            }
                        }
                    }
                });
            }
        });



        // // var fileName = @"C:\\Users\\famil\\OneDrive\\ドキュメント\\GitHub\\music_game\\test 3D\\Assets\\Scenes\\doremi.mid";
        // // var fileName = @"C:\\Users\\famil\\OneDrive\\ドキュメント\\GitHub\\music_game\\test 3D\\doremi.mid";
        // var fileName=@"C:\\Users\\famil\\OneDrive\\ドキュメント\\Alice_in_冷凍庫\\Alice in 冷凍庫.mid";
        // // var fileName=@"C:\Users\famil\Downloads\toruko.mid";

        // LoadMSF(fileName);
        // ModificationEventTimes();
        // // Debug.Log(noteList.Count);
        // // Debug.Log(tempoList.Count);
        // // Debug.Log("EventTime");
        // KeyCode=new bool[130,Enumerable.Last(noteList).eventTime*2];
        // for(int i=0;i<noteList.Count;i++){
        //     // Debug.Log(noteList[i].laneIndex+" , "+noteList[i].eventTime/100);
        //     if(noteList[i].type != NoteType.LongEnd) KeyCode[noteList[i].laneIndex , noteList[i].eventTime/100] = true;
        // }
        // Ready=true;
    }
예제 #31
0
 //コンストラクター
 //decodeJSONObjectのみ仕様
 internal NCMBRelation(string targetClass)
 {
     this._parent      = null;
     this._key         = null;
     this._targetClass = targetClass;
 }
예제 #32
0
        //前回のローカルデータから新規ローカルデータの作成
        public object Apply(object oldValue, NCMBObject obj, string key)
        {
            //前回のローカルデータ(estimatedDataに指定のキーが無い場合)がNullの場合
            if (oldValue == null)
            {
                //return new List<object> ();
                return(new ArrayList());                //追加
            }
            //配列のみリムーブ実行
            if ((oldValue is IList))
            {
                //削除処理を行う
                //ArrayList result = new ArrayList ((IList)oldValue);
                //result = NCMBUtility._removeAllFromListMainFunction ((IList)oldValue, this.objects);

                //1.取り出したローカルデータから今回の引数で渡されたオブジェクトの削除
                //例:estimatedData(result)={1,NCMBObject} 引数(values)={2,NCMBObject}の時,結果:{1}
                ArrayList result = new ArrayList((IList)oldValue);
                foreach (object removeObj in this.objects)
                {
                    while (result.Contains(removeObj))                      //removeAllと同等
                    {
                        result.Remove(removeObj);
                    }
                }
                //ここから下は引数の中で「NCMBObjectが保存されているかつ、
                //estimatedData(result)の中の一致するNCMBObjectが消せなかった」時の処理です。
                //つまり 「上で消せなかったNCMBObject=インスタンスが違う」
                //estimatedData(result)の中のNCMBObjectと引数のNCMBObjectがどちらもnewで作られたものなら上で消せるが、
                //どちらかがnewでどちらかがCreateWithoutDataで作られた場合は上で消せない。
                //そのため下の処理はobjectIdで検索をかけてobjectIdが一致するNCMBObjectの削除を行う

                //2.今回引数で渡されたオブジェクトから1.のオブジェクトの削除
                //例:引数(objectsToBeRemoved)={2,NCMBObject} 1の結果={1}の時,結果:{2,NCMBObject}
                ArrayList objectsToBeRemoved = new ArrayList((IList)this.objects);

                foreach (object removeObj2 in result)
                {
                    while (objectsToBeRemoved.Contains(removeObj2))                      //removeAllと同等
                    {
                        objectsToBeRemoved.Remove(removeObj2);
                    }
                }

                //3.2の結果のリスト(引数)の中のNCMBObjectがすでに保存されている場合はobjectIdを返す
                //まだ保存されていない場合はnullを返す
                //例:CreateWithoutDataの場合「objectIds Value:ppmQNGZahXpO8YSV」newの場合「objectIds Value:null」
                HashSet <object> objectIds = new HashSet <object> ();
                foreach (object hashSetValue in objectsToBeRemoved)
                {
                    if (hashSetValue is NCMBObject)
                    {
                        NCMBObject valuesNCMBObject = (NCMBObject)hashSetValue;
                        objectIds.Add(valuesNCMBObject.ObjectId);
                    }

                    //4.resultの中のNCMBObjectからobjectIdsの中にあるObjectIdと一致するNCMBObjectの削除
                    //ここだけfor文で対応している理由は,
                    //「foreach文により要素を列挙している最中には、そのリスト(result)から要素を削除することはできない(Exception吐く)」
                    //例:上記の例の場合の結果result = {1}
                    object resultValue;
                    for (int i = 0; i < result.Count; i++)
                    {
                        resultValue = result [i];
                        if (resultValue is NCMBObject)
                        {
                            NCMBObject resultNCMBObject = (NCMBObject)resultValue;
                            if (objectIds.Contains(resultNCMBObject.ObjectId))
                            {
                                result.RemoveAt(i);
                            }
                        }
                    }
                }
                return(result);
            }
            throw new  InvalidOperationException("Operation is invalid after previous operation.");
        }
예제 #33
0
    // Start is called before the first frame update
    void Start()
    {
        stageName = SceneController.getStage();

        enemyBoxNumber = EditPosition.getEnemyBoxNumber();

        if (enemyBoxNumber == 1)
        {
            enemyOFbox2 = GameObject.FindWithTag("enemyBox2");
            enemyOFbox3 = GameObject.FindWithTag("enemyBox3");
            enemyOFbox4 = GameObject.FindWithTag("enemyBox4");

            enemyOFbox2.GetComponent <enemyBlackBox>().enabled = true;
            enemyOFbox3.GetComponent <enemyWhiteBox>().enabled = true;
            enemyOFbox4.GetComponent <enemyBlueBox>().enabled  = true;
        }
        else if (enemyBoxNumber == 2)
        {
            enemyOFbox1 = GameObject.FindWithTag("enemyBox1");
            enemyOFbox3 = GameObject.FindWithTag("enemyBox3");
            enemyOFbox4 = GameObject.FindWithTag("enemyBox4");

            enemyOFbox1.GetComponent <enemyRedBox>().enabled   = true;
            enemyOFbox3.GetComponent <enemyWhiteBox>().enabled = true;
            enemyOFbox4.GetComponent <enemyBlueBox>().enabled  = true;
        }
        else if (enemyBoxNumber == 3)
        {
            enemyOFbox1 = GameObject.FindWithTag("enemyBox1");
            enemyOFbox2 = GameObject.FindWithTag("enemyBox2");
            enemyOFbox4 = GameObject.FindWithTag("enemyBox4");

            enemyOFbox1.GetComponent <enemyRedBox>().enabled   = true;
            enemyOFbox2.GetComponent <enemyBlackBox>().enabled = true;
            enemyOFbox4.GetComponent <enemyBlueBox>().enabled  = true;
        }
        else if (enemyBoxNumber == 4)
        {
            enemyOFbox1 = GameObject.FindWithTag("enemyBox1");
            enemyOFbox2 = GameObject.FindWithTag("enemyBox2");
            enemyOFbox3 = GameObject.FindWithTag("enemyBox3");

            enemyOFbox1.GetComponent <enemyRedBox>().enabled   = true;
            enemyOFbox2.GetComponent <enemyBlackBox>().enabled = true;
            enemyOFbox3.GetComponent <enemyWhiteBox>().enabled = true;
        }


        playerBoxNumber = Random.Range(1, 5);

        if (playerBoxNumber == 1)
        {
            Instantiate(
                playerOFbox2,
                new Vector3(-2f, transform.position.y, 1f),
                transform.rotation
                );
            Instantiate(
                playerOFbox3,
                new Vector3(0f, transform.position.y, 1f),
                transform.rotation
                );
            Instantiate(
                playerOFbox4,
                new Vector3(2f, transform.position.y, 1f),
                transform.rotation
                );
        }
        else if (playerBoxNumber == 2)
        {
            Instantiate(
                playerOFbox1,
                new Vector3(-2f, transform.position.y, 1f),
                transform.rotation
                );
            Instantiate(
                playerOFbox3,
                new Vector3(0f, transform.position.y, 1f),
                transform.rotation
                );
            Instantiate(
                playerOFbox4,
                new Vector3(2f, transform.position.y, 1f),
                transform.rotation
                );
        }
        else if (playerBoxNumber == 3)
        {
            Instantiate(
                playerOFbox1,
                new Vector3(-2f, transform.position.y, 1f),
                transform.rotation
                );
            Instantiate(
                playerOFbox2,
                new Vector3(0f, transform.position.y, 1f),
                transform.rotation
                );
            Instantiate(
                playerOFbox4,
                new Vector3(2f, transform.position.y, 1f),
                transform.rotation
                );
        }
        else if (playerBoxNumber == 4)
        {
            Instantiate(
                playerOFbox1,
                new Vector3(-2f, transform.position.y, 1f),
                transform.rotation
                );
            Instantiate(
                playerOFbox2,
                new Vector3(0f, transform.position.y, 1f),
                transform.rotation
                );
            Instantiate(
                playerOFbox3,
                new Vector3(2f, transform.position.y, 1f),
                transform.rotation
                );
        }


        ResultText.text     = "";
        ReplayText.text     = "";
        Possession1.text    = "";
        Possession2.text    = "";
        PossessionText.text = "";
        right.text          = "";
        isVictory           = false;
        isDefeat            = false;

        emptyOFbox = GameObject.FindGameObjectsWithTag("emptyBox");

        DF1 = GameObject.FindGameObjectsWithTag("playerDF1");
        DF2 = GameObject.FindGameObjectsWithTag("playerDF2");
        DF3 = GameObject.FindGameObjectsWithTag("playerDF3");
        DF4 = GameObject.FindGameObjectsWithTag("playerDF4");
        DF5 = GameObject.FindGameObjectsWithTag("playerDF5");
        DF6 = GameObject.FindGameObjectsWithTag("playerDF6");

        //TestClassからデータを取得する
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject> ("possession");

        //データを検索し取得
        query.FindAsync((List <NCMBObject> objectList, NCMBException e) => {
            //取得失敗
            if (e != null)
            {
                //エラーコード表示
                Debug.Log(e.ToString());
                return;
            }

            //取得した全データのmessageを表示
            foreach (NCMBObject ncmbObject in objectList)
            {
                beforePossession = System.Convert.ToInt32(ncmbObject["Point"]);
            }
            foreach (NCMBObject ncmbObject in objectList)
            {
                obj1 = ncmbObject;
            }
        });


        if (stageName == "1_1" || stageName == "2_1" || stageName == "3_1" || stageName == "4_1")
        {
            afterPossession = beforePossession + 50;
        }
        if (stageName == "1_2" || stageName == "2_2" || stageName == "3_2" || stageName == "4_2")
        {
            afterPossession = beforePossession + 100;
        }
        if (stageName == "1_3" || stageName == "2_3" || stageName == "3_3" || stageName == "4_3")
        {
            afterPossession = beforePossession + 150;
        }
        if (stageName == "1_4" || stageName == "2_4" || stageName == "3_4" || stageName == "4_4")
        {
            afterPossession = beforePossession + 200;
        }
        if (stageName == "1_5" || stageName == "2_5" || stageName == "3_5" || stageName == "4_5")
        {
            afterPossession = beforePossession + 250;
        }
        if (stageName == "1_boss" || stageName == "2_boss" || stageName == "3_boss" || stageName == "4_boss")
        {
            afterPossession = beforePossession + 300;
        }
    }
예제 #34
0
    // スコア送信処理は非同期でまとめて処理するため、categoryが途中で変わってしまう。
    public void saveReplay(ReplayDataV1 param, int category)
    {
        // データストアの「ReplayData」クラスから、Nameをキーにして検索
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("ReplayDataV1");

        query.WhereEqualTo("Id", param.Id);
        query.WhereEqualTo("ScoreKindValue", param.ScoreKindValue);
        query.WhereEqualTo("Row", param.Row);
        query.WhereEqualTo("Col", param.Col);
        query.WhereEqualTo("Color", param.Color);
        query.WhereEqualTo("Link", param.Link);
        query.WhereEqualTo("Direction", param.Direction);
        query.WhereEqualTo("Time", param.Time);
        query.WhereEqualTo("Stop", param.Stop);
        query.WhereEqualTo("CountDisp", param.CountDisp);
        query.WhereEqualTo("Garbage", param.Garbage);
        query.WhereEqualTo("ScoreCategoryValue", category);

        query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
        {
            //検索成功したら
            if (e == null)
            {
                // リプレイが未登録だったら
                if (objList.Count == 0)
                {
                    NCMBObject obj        = new NCMBObject("ReplayDataV1");
                    obj["Version"]        = param.Version;
                    obj["Id"]             = param.Id;
                    obj["PlayDateTime"]   = param.PlayDateTime;
                    obj["ScoreKindValue"] = param.ScoreKindValue;
                    obj["Seed"]           = param.Seed;
                    obj["FrameCount"]     = param.FrameCount;
                    obj["InputCount"]     = param.InputCount;
                    obj["InputFrame"]     = param.InputFrame;
                    obj["InputType"]      = param.InputType;
                    obj["InputData1"]     = param.InputData1;
                    obj["InputData2"]     = param.InputData2;

                    obj["Row"]                = param.Row;
                    obj["Col"]                = param.Col;
                    obj["Color"]              = param.Color;
                    obj["Link"]               = param.Link;
                    obj["Direction"]          = param.Direction;
                    obj["Time"]               = param.Time;
                    obj["Stop"]               = param.Stop;
                    obj["CountDisp"]          = param.CountDisp;
                    obj["Garbage"]            = param.Garbage;
                    obj["ScoreCategoryValue"] = category;

                    obj.SaveAsync();
                }
                // リプレイが登録済みだったら
                else
                {
                    objList[0]["PlayDateTime"] = param.PlayDateTime;
                    objList[0]["Seed"]         = param.Seed;
                    objList[0]["Version"]      = param.Version;
                    objList[0]["FrameCount"]   = param.FrameCount;
                    objList[0]["InputCount"]   = param.InputCount;
                    objList[0]["InputFrame"]   = param.InputFrame;
                    objList[0]["InputType"]    = param.InputType;
                    objList[0]["InputData1"]   = param.InputData1;
                    objList[0]["InputData2"]   = param.InputData2;
                    objList[0].SaveAsync();
                }
            }
        });
    }
예제 #35
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");
            }
        });
    }
예제 #36
0
    public void OnClick()
    {
        //TestClassからデータを取得する
        NCMBQuery <NCMBObject> query1 = new NCMBQuery <NCMBObject> ("possession");

        //データを検索し取得
        query1.FindAsync((List <NCMBObject> objectList, NCMBException e) => {
            //取得失敗
            if (e != null)
            {
                //エラーコード表示
                Debug.Log(e.ToString());
                return;
            }

            //取得した全データのmessageを表示
            foreach (NCMBObject ncmbObject in objectList)
            {
                possession = System.Convert.ToInt32(ncmbObject["Point"]);
            }
        });


        //TestClassからデータを取得する
        NCMBQuery <NCMBObject> query2 = new NCMBQuery <NCMBObject> ("BlueDFstatus");

        //データを検索し取得
        query2.FindAsync((List <NCMBObject> objectList, NCMBException e) => {
            //取得失敗
            if (e != null)
            {
                //エラーコード表示
                Debug.Log(e.ToString());
                return;
            }

            //取得した全データのmessageを表示
            foreach (NCMBObject ncmbObject in objectList)
            {
                ATK = System.Convert.ToInt32(ncmbObject["ATK"]);
            }
            foreach (NCMBObject ncmbObject in objectList)
            {
                Point = System.Convert.ToInt32(ncmbObject["Point"]);
            }

            foreach (NCMBObject ncmbObject in objectList)
            {
                obj1 = ncmbObject;
            }
        });

        possession = possession - Point;

        obj2          = new NCMBObject("BlueDFstatus");
        obj2.ObjectId = obj1.ObjectId;
        obj2["ATK"]   = Mathf.FloorToInt(ATK * 1.05f);
        obj2["Point"] = Mathf.FloorToInt(Point * 1.5f);

        obj2.SaveAsync();

        beforeATKText.text = string.Format("{0:#,0}", ATK);
        afterATKText.text  = string.Format("{0:#,0}", Mathf.FloorToInt(ATK * 1.05f));
        pointText.text     = string.Format("{0:#,0}", Mathf.FloorToInt(Point * 1.5f));

        Possession.possession = possession;
        possessionText.text   = string.Format("{0:#,0}", possession);
    }
        //前回のローカルデータから新規ローカルデータの作成
        public object Apply(object oldValue, NCMBObject obj, string key)
        {
            //前回のローカルデータ(estimatedDataに指定のキーが無い場合)がNullの場合
            if (oldValue == null) {
                //return new List<object> ();
                return new ArrayList ();//追加
            }
            //配列のみリムーブ実行
            if ((oldValue is IList)) {

                //削除処理を行う
                //ArrayList result = new ArrayList ((IList)oldValue);
                //result = NCMBUtility._removeAllFromListMainFunction ((IList)oldValue, this.objects);

                //1.取り出したローカルデータから今回の引数で渡されたオブジェクトの削除
                //例:estimatedData(result)={1,NCMBObject} 引数(values)={2,NCMBObject}の時,結果:{1}
                ArrayList result = new ArrayList ((IList)oldValue);
                foreach (object removeObj in this.objects) {
                    while (result.Contains(removeObj)) {//removeAllと同等
                        result.Remove (removeObj);
                    }
                }
                //ここから下は引数の中で「NCMBObjectが保存されているかつ、
                //estimatedData(result)の中の一致するNCMBObjectが消せなかった」時の処理です。
                //つまり 「上で消せなかったNCMBObject=インスタンスが違う」
                //estimatedData(result)の中のNCMBObjectと引数のNCMBObjectがどちらもnewで作られたものなら上で消せるが、
                //どちらかがnewでどちらかがCreateWithoutDataで作られた場合は上で消せない。
                //そのため下の処理はobjectIdで検索をかけてobjectIdが一致するNCMBObjectの削除を行う

                //2.今回引数で渡されたオブジェクトから1.のオブジェクトの削除
                //例:引数(objectsToBeRemoved)={2,NCMBObject} 1の結果={1}の時,結果:{2,NCMBObject}
                ArrayList objectsToBeRemoved = new ArrayList ((IList)this.objects);

                foreach (object removeObj2 in result) {
                    while (objectsToBeRemoved.Contains(removeObj2)) {//removeAllと同等
                        objectsToBeRemoved.Remove (removeObj2);
                    }
                }

                //3.2の結果のリスト(引数)の中のNCMBObjectがすでに保存されている場合はobjectIdを返す
                //まだ保存されていない場合はnullを返す
                //例:CreateWithoutDataの場合「objectIds Value:ppmQNGZahXpO8YSV」newの場合「objectIds Value:null」
                HashSet<object> objectIds = new HashSet<object> ();
                foreach (object hashSetValue in objectsToBeRemoved) {
                    if (hashSetValue is NCMBObject) {
                        NCMBObject valuesNCMBObject = (NCMBObject)hashSetValue;
                        objectIds.Add (valuesNCMBObject.ObjectId);
                    }

                    //4.resultの中のNCMBObjectからobjectIdsの中にあるObjectIdと一致するNCMBObjectの削除
                    //ここだけfor文で対応している理由は,
                    //「foreach文により要素を列挙している最中には、そのリスト(result)から要素を削除することはできない(Exception吐く)」
                    //例:上記の例の場合の結果result = {1}
                    object resultValue;
                    for (int i = 0; i < result.Count; i++) {
                        resultValue = result [i];
                        if (resultValue is NCMBObject) {
                            NCMBObject resultNCMBObject = (NCMBObject)resultValue;
                            if (objectIds.Contains (resultNCMBObject.ObjectId)) {
                                result.RemoveAt (i);
                            }
                        }
                    }
                }
                return result;
            }
            throw new  InvalidOperationException ("Operation is invalid after previous operation.");
        }
예제 #38
0
        public object Apply(object oldValue, NCMBObject obj, string key)
        {
            //初回 estimatedDataに対象のデータが無かった場合
            if (oldValue == null)
            {
                return(new ArrayList(this.objects));                //追加
            }

            //estimatedDataにすでに対象データがあり,配列だった場合
            if ((oldValue is IList))
            {
                ArrayList result = new ArrayList((IList)oldValue);                      //追加


                //前回のオブジェクトのobjectIDを補完する。 key : objectId value : int(連番)
                Hashtable existingObjectIds = new Hashtable();
                //全要素検索
                foreach (object resultValue in result)
                {
                    int i = 0;
                    //前回のオブジェクトからNCMBObjectの要素を検索
                    if (resultValue is NCMBObject)
                    {
                        //あればkeyにobjectId,valueに連番を追加
                        NCMBObject resultNCMBObject = (NCMBObject)resultValue;
                        existingObjectIds.Add(resultNCMBObject.ObjectId, i);                         //追加したいNCMBObjectのid
                    }
                }

                //同じNCMBObjectだったら重複しないようAPI側でさばいているかも
                IEnumerator localEnumerator = this.objects.GetEnumerator();
                while (localEnumerator.MoveNext())
                {
                    object objectsValue = (object)localEnumerator.Current;
                    if ((objectsValue is NCMBObject))
                    {
                        //objrcts2のobjectIdと先ほど生成したexistingObjectIdsのobjectIDが一致した場合、
                        //existingObjectIdsのvalue:連番を返す。なければnull
                        NCMBObject objectsNCMBObject = (NCMBObject)objectsValue;
                        if (existingObjectIds.ContainsKey(objectsNCMBObject.ObjectId))
                        {
                            //すでにある
                            int index = Convert.ToInt32(existingObjectIds [objectsNCMBObject.ObjectId]);
                            result.Insert(index, objectsValue);
                        }
                        else
                        {
                            //ユニークなのでadd。追加する
                            result.Add(objectsValue);
                        }
                    }
                    else if (!result.Contains(objectsValue))
                    {
                        //基本的にこちら。重複していない値のみaddする
                        result.Add(objectsValue);
                    }
                }
                return(result);
            }
            //対象データが配列以外だった場合
            throw new  InvalidOperationException("Operation is invalid after previous operation.");
        }
예제 #39
0
        // 思考の保存
        public void save()
        {
            NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject> ("ExpertData");

            query.WhereEqualTo("Name", Name);
            query.FindAsync((List <NCMBObject> objList, NCMBException e) => {
                // 検索成功したら
                if (e == null)
                {
                    isSearch = true;
                    // 未登録だったら
                    if (objList.Count == 0)
                    {
                        NCMBObject obj        = new NCMBObject("ExpertData");
                        obj["Name"]           = Name;
                        obj["Rating"]         = 1500;
                        int type_count        = (MyConnects.connectLists).Count;
                        List <int[]> tmp_list = new List <int[]>();
                        for (int i = 0; i < type_count; i++)
                        {
                            int countConect = (MyConnects.connectLists[i]).Count;
                            if (countConect == 0)
                            {
                                tmp_list.Add(new int[6] {
                                    0, 0, 0, 0, 0, 0
                                });
                            }
                            else
                            {
                                int[] tmp = new int[6 * countConect];
                                int idx   = 0;
                                // Debug.Log("countConect = "+countConect);
                                foreach (int[] connect in MyConnects.connectLists[i])
                                {
                                    tmp[idx]     = connect[0];
                                    tmp[idx + 1] = connect[1];
                                    tmp[idx + 2] = connect[2];
                                    tmp[idx + 3] = connect[3];
                                    tmp[idx + 4] = connect[4];
                                    tmp[idx + 5] = connect[5];
                                    idx          = idx + 6;
                                }
                                tmp_list.Add(tmp);
                            }
                        }
                        obj["Connect"] = tmp_list;
                        obj.SaveAsync();
                        isNewSaved = true;
                    }
                    else
                    {
                        int type_count        = (MyConnects.connectLists).Count;
                        List <int[]> tmp_list = new List <int[]>();
                        for (int i = 0; i < type_count; i++)
                        {
                            int countConect = MyConnects.connectLists[i].Count;
                            int[] tmp       = new int[6 * countConect];
                            int idx         = 0;
                            // Debug.Log("countConect = "+countConect);

                            foreach (int[] connect in MyConnects.connectLists[i])
                            {
                                tmp[idx]     = connect[0];
                                tmp[idx + 1] = connect[1];
                                tmp[idx + 2] = connect[2];
                                tmp[idx + 3] = connect[3];
                                tmp[idx + 4] = connect[4];
                                tmp[idx + 5] = connect[5];
                                idx          = idx + 6;
                            }

                            /*
                             * for(int i= 0; i<tmp.Length; i++){
                             * // Debug.Log(tmp[i]);
                             * }*/
                            // Debug.Log("objList = "+objList.Count);
                            tmp_list.Add(tmp);
                        }
                        objList[0]["Connect"] = tmp_list;
                        objList[0].SaveAsync();
                        isSaved  = true;
                        isNoData = false;
                    }
                    // saver_alert.text = "サーバ連携 成功";

                    /*
                     * if(User.Level == 5){
                     * User.LevelUP();
                     * }*/
                }
                else
                {
                    isSaved  = false;
                    isNoData = true;
                    // saver_alert.text = "サーバ連携 失敗";
                }
                //Invoke("SaverAlertOFF", 2);
            });
        }
예제 #40
0
 internal NCMBQuery <T> _whereRelatedTo(NCMBObject parent, String key)
 {
     this._addCondition("$relatedTo", "object", NCMBUtility._maybeEncodeJSONObject(parent, true));
     this._addCondition("$relatedTo", "key", key);
     return(this);
 }
예제 #41
0
    // スコアをアップロード
    public void UploadScore()
    {
        // タイムがないとアップロードできない
        if (DataManager.GetBestScore() < 0.01f)
        {
            ShowToast("スコアがありません。");
            return;
        }
        // 名前を入力してないとアップロードできない
        string upName = GameObject.Find("UI/Ranking/Panel/InputField").GetComponent <InputField> ().text;

        if (string.IsNullOrEmpty(upName))
        {
            ShowToast("名前を入力してください。");
            return;
        }
        // ローディングのクルクルを表示
        Loading();
        // アップロード
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject> ("Ranking");

        query.WhereEqualTo("Name", upName);
        query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
        {
            if (e == null)
            {
                // 新規登録
                if (objList.Count == 0)
                {
                    NCMBObject obj = new NCMBObject("Ranking");
                    obj["Name"]    = upName;
                    obj["Time"]    = DataManager.GetBestScore();
                    obj.SaveAsync((NCMBException ee) =>
                    {
                        if (ee == null)
                        {
                            Init();
                        }
                        else
                        {
                            LoadEnd();
                            ShowToast("エラーが発生しました。");
                        }
                    });
                }
                else // 更新
                {
                    // サーバーの方が遅い時更新できる
                    float cloudScore = (float)System.Convert.ToDouble(objList[0]["Time"]);
                    if (DataManager.GetBestScore() < cloudScore)
                    {
                        objList[0]["Time"] = DataManager.GetBestScore();
                        objList[0].SaveAsync((NCMBException ee) =>
                        {
                            if (ee == null)
                            {
                                Init();
                            }
                            else
                            {
                                LoadEnd();
                                ShowToast("エラーが発生しました。");
                            }
                        });
                    }
                    else
                    {
                        // 初期化
                        Init();
                    }
                }
            }
            else
            {
                LoadEnd();
                ShowToast("エラーが発生しました。");
            }
        });
    }
 public object Apply(object oldValue, NCMBObject obj, string key)
 {
     return(null);
 }
예제 #43
0
    //指定したレコードデータをランキングに登録
    public void SaveRanking(RecordData recordData, Save_ranking_item save_Ranking_Item, CallbackVoid callback)
    {
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>(rankingClassName);

        query.WhereEqualTo("name", settings.name);                 // プレイヤー名でデータを絞る
        query.WhereEqualTo("gameModeId", recordData.game_mode_id); // 種目でデータを絞る
        query.WhereEqualTo("type", (int)save_Ranking_Item);        // MAX・MINでデータを絞る

        query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
        {
            if (e == null)
            {     // データの検索が成功したら、
                if (objList.Count == 0)
                { // ハイスコアが未登録の場合
                    NCMBObject cloudObj    = new NCMBObject(rankingClassName);
                    cloudObj["gameModeId"] = recordData.game_mode_id;
                    cloudObj["type"]       = (int)save_Ranking_Item;
                    cloudObj["name"]       = settings.name;



                    switch (save_Ranking_Item)
                    {
                    case Save_ranking_item.SAVE_RANKING_HIGH:
                        cloudObj["distance"] = recordData.max_distance;
                        cloudObj["timeSpan"] = recordData.timespan_maxdistance;
                        break;

                    case Save_ranking_item.SAVE_RANKING_LOW:
                        cloudObj["distance"] = recordData.min_distance;
                        cloudObj["timeSpan"] = recordData.timespan_mindistance;
                        break;

                    default:
                        break;
                    }
                    cloudObj.SaveAsync(); // セーブ
                }
                else
                {                                     // ハイスコアが登録済みの場合
                    NCMBObject cloudObj = objList[0]; // クラウド上のレコードデータを取得
                    float distance      = System.Convert.ToSingle(cloudObj["distance"]);
                    float timeSpan      = System.Convert.ToSingle(cloudObj["timeSpan"]);
                    switch (save_Ranking_Item)
                    {
                    case Save_ranking_item.SAVE_RANKING_HIGH:
                        if (distance < recordData.max_distance || (distance == recordData.max_distance && timeSpan > recordData.timespan_maxdistance))
                        {
                            cloudObj["distance"] = recordData.max_distance;
                            cloudObj["timeSpan"] = recordData.timespan_maxdistance;
                            cloudObj.SaveAsync();
                        }
                        break;

                    case Save_ranking_item.SAVE_RANKING_LOW:
                        if (distance > recordData.min_distance || (distance == recordData.min_distance && timeSpan > recordData.timespan_mindistance))
                        {
                            cloudObj["distance"] = recordData.min_distance;
                            cloudObj["timeSpan"] = recordData.timespan_mindistance;
                            cloudObj.SaveAsync();
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            callback();
        });
    }
        //前回のローカルデータから新規ローカルデータの作成
        public object Apply(object oldValue, NCMBObject obj, string key)
        {
            //前回のローカルデータ(estimatedDataに指定のキーが無い場合)がNullの場合
            if (oldValue == null)
            {
                //return new List<object> ();
                return(new ArrayList());                //追加
            }
            //配列のみリムーブ実行
            if ((oldValue is IList))
            {
                //削除処理を行う
                //ArrayList result = new ArrayList ((IList)oldValue);
                //result = NCMBUtility._removeAllFromListMainFunction ((IList)oldValue, this.objects);

                //取り出したローカルデータから今回の引数で渡されたオブジェクトの削除
                ArrayList result = new ArrayList((IList)oldValue);
                foreach (object removeObj in this.objects)
                {
                    while (result.Contains(removeObj))                      //removeAllと同等
                    {
                        result.Remove(removeObj);
                    }
                }
                //以下NCMBObject重複処理
                //今回引数で渡されたオブジェクトから1.のオブジェクトの削除
                ArrayList objectsToBeRemoved = new ArrayList((IList)this.objects);

                foreach (object removeObj2 in result)
                {
                    while (objectsToBeRemoved.Contains(removeObj2))                      //removeAllと同等
                    {
                        objectsToBeRemoved.Remove(removeObj2);
                    }
                }

                //結果のリスト(引数)の中のNCMBObjectがすでに保存されている場合はobjectIdを返す
                HashSet <object> objectIds = new HashSet <object> ();
                foreach (object hashSetValue in objectsToBeRemoved)
                {
                    if (hashSetValue is NCMBObject)
                    {
                        NCMBObject valuesNCMBObject = (NCMBObject)hashSetValue;
                        objectIds.Add(valuesNCMBObject.ObjectId);
                    }

                    //resultの中のNCMBObjectからobjectIdsの中にあるObjectIdと一致するNCMBObjectの削除
                    object resultValue;
                    for (int i = 0; i < result.Count; i++)
                    {
                        resultValue = result [i];
                        if (resultValue is NCMBObject)
                        {
                            NCMBObject resultNCMBObject = (NCMBObject)resultValue;
                            if (objectIds.Contains(resultNCMBObject.ObjectId))
                            {
                                result.RemoveAt(i);
                            }
                        }
                    }
                }
                return(result);
            }
            throw new  InvalidOperationException("Operation is invalid after previous operation.");
        }
예제 #45
0
 public object Apply(object oldValue, NCMBObject obj, string key)
 {
     return(this.Value);
 }
예제 #46
0
 /// <summary>
 /// フレンド申請をキャンセルするメソッド
 /// </summary>
 /// <param name="target">キャンセルするフレンド申請</param>
 private void cancelFriendRequest(NCMBObject target)
 {
     Connection.CancelRequest(target, new ErrorCallBack(setCancelFriendRequestError));
 }