Ejemplo n.º 1
0
    }//Used Onclick() in Back_Button

    void CheckCurrentPuzzle(string puzzleID)
    {
        int find = 0;

        for (int i = 0; i < puzzles.Length; i++)
        {
            if (HarimTool.EditValue.EditText.Left(puzzles[i][0].id, 2) == HarimTool.EditValue.EditText.Left(puzzleID, 2))
            {
                for (int j = 0; j < puzzles[i].Length; j++)
                {
                    if (puzzles[i][j].id == puzzleID)
                    {
                        currentPuzzle = puzzles[i][j]; find++;
                    }
                }
            }
        }
        if (find > 0)
        {
            currentPuzzleSize = currentPuzzle.size;
        }
        else
        {
            Debug.Log("Not found puzzle of this ID : " + puzzleID);
        }
    }//DB에 해당 퍼즐이 있는지 확인.
Ejemplo n.º 2
0
    }//After Check That Internet Connection.

    IEnumerator LoadPuzzles()
    {
        loadPuzzle = false;
        loadAll    = false;

        float time = 0;

        while (time < 5f)
        {
            if (NetworkConnectionChecker.instance.success == true)
            {
                List <DataBase.Puzzle> tempPuzzleList = new List <DataBase.Puzzle>();
                #region LoadPuzzleDB_Firebase
                FirebaseDatabase.DefaultInstance.GetReference("Puzzles").GetValueAsync().ContinueWith
                (
                    task =>
                {
                    if (task.IsFaulted)
                    {
                        Debug.Log("Puzzle, Handle the error");
                    }   // Handle the error...
                    else if (task.IsCompleted)
                    {
                        Debug.Log("Puzzle, TaskComplite");
                        DataSnapshot snapshot = task.Result;

                        #region tempPuzzleList
                        for (int i = 1; i < snapshot.ChildrenCount; i++)
                        {
                            DataBase.Puzzle tempPuzzle = new DataBase.Puzzle();
                            string i_ = i.ToString();

                            tempPuzzle.id            = snapshot.Child(i_).Child("0").GetValue(true).ToString();
                            tempPuzzle.name          = snapshot.Child(i_).Child("1").GetValue(true).ToString();
                            tempPuzzle.size          = System.Convert.ToInt32(snapshot.Child(i_).Child("2").GetValue(true));
                            tempPuzzle.useSpriteNum1 = System.Convert.ToInt32(snapshot.Child(i_).Child("3").GetValue(true));
                            tempPuzzle.useSpriteNum2 = System.Convert.ToInt32(snapshot.Child(i_).Child("4").GetValue(true));
                            tempPuzzle.type          = snapshot.Child(i_).Child("5").GetValue(true).ToString();
                            tempPuzzle.spawnCount    = System.Convert.ToInt32(snapshot.Child(i_).Child("6").GetValue(true));
                            tempPuzzle.maxCount      = System.Convert.ToInt32(snapshot.Child(i_).Child("7").GetValue(true));

                            tempPuzzleList.Add(tempPuzzle);
                        }  //칼럼 제외 이유로 i = 1 부터 시작.
                        #endregion

                        List <DataBase.Puzzle[]> puzzleList = new List <DataBase.Puzzle[]>(); //tempPuzzleList의 것을 Land 별로 옮겨담을 곳.

                        #region puzzleList
                        int targetPuzzleListNum = 1;
                        int puzzleCount         = tempPuzzleList.Count;

                        while (puzzleCount > 0)
                        {
                            #region tempBaseSetting
                            List <DataBase.Puzzle> tempTempPuzzleList = new List <DataBase.Puzzle>(); //tempPuzzleList의 Puzzle을 Land순서별로 담는다.
                            List <int> tempTempNum = new List <int>();                                //tempTempPuzzleList의 퍼즐을 가져올때 사용할 int
                            #endregion
                            for (int i = 0; i < tempPuzzleList.Count; i++)
                            {
                                string targetPuzzleListStr = targetPuzzleListNum < 10 ? "0" + targetPuzzleListNum : targetPuzzleListNum.ToString();
                                if (targetPuzzleListStr == HarimTool.EditValue.EditText.Left(tempPuzzleList[i].id, 2))
                                {
                                    tempTempPuzzleList.Add(tempPuzzleList[i]);
                                    tempTempNum.Add(i);
                                    puzzleCount--;
                                } //Debug.Log(targetPuzzleListStr +", "+ puzzleCount);
                            }     //Land가 같은 것 끼리 모음.1번 Land부터 시작.
                            DataBase.Puzzle[] tempPuzzleArr = new DataBase.Puzzle[tempTempPuzzleList.Count];
                            for (int i = 0; i < tempTempPuzzleList.Count; i++)
                            {
                                tempPuzzleArr[i] = tempTempPuzzleList[i];
                            }  //PuzzleList에 순차적으로 Puzzle들을 담기 위해 List를 Array로 만든다.
                            puzzleList.Add(tempPuzzleArr);
                            tempTempPuzzleList.Clear();
                            tempTempNum.Clear();
                            targetPuzzleListNum++;
                        }
                        #endregion

                        #region PuzzleManager.puzzles
                        PuzzleManager.instance.puzzles = new DataBase.Puzzle[puzzleList.Count][];// [landCount][puzzleCount]
                        for (int i = 0; i < puzzleList.Count; i++)
                        {
                            for (int j = 0; j < puzzleList[i].Length; j++)
                            {
                                Array.Sort(puzzleList[i], delegate(DataBase.Puzzle a, DataBase.Puzzle b)
                                {
                                    return(a.id.CompareTo(b.id));
                                });  //퍼즐 ID를 순서대로 정렬
                            }
                            PuzzleManager.instance.puzzles[i] = puzzleList[i];
                        }
                        #endregion

                        loadPuzzle = true;
                        SaveDB_Local();
                        Debug.Log("Kind of Puzzle : Land Count : " + PuzzleManager.instance.puzzles.Length);
                        // Debug.Log(snapshot.Child("1").Child("0").GetValue(true));
                    }
                }
                );
                #endregion
                if (loadPuzzle == true)
                {
                    break;
                }
            }
            else
            {
                if (LoadDB_Local() == true)
                {
                    loadPuzzle = true;
                    Debug.Log("Load_LocalDB");
                }
                else
                {
                    Debug.Log("Network_Error");
                }
            }
            yield return(new WaitForSeconds(0.05f));

            time += 0.02f;
        }
        Debug.Log("NeedMoreTime_LoadPuzzleDB");
    }//After Check That Internet Connection.