예제 #1
0
        void showTip()
        {
            if (GameData.getInstance().tipRemain > 0)
            {
                GameData.getInstance().tipRemain--;
                PlayerPrefs.SetInt("tipRemain", GameData.getInstance().tipRemain);
                GameData.getInstance().main.refreshView();

                //have not give a tip
                //GameData.getInstance().tickStartTime = PlayerPrefs.GetString("tipStart", "0");
                //if (GameData.getInstance().tickStartTime == "0")
                //{
                //    canTick = false;
                //    //				long tcTime = System.DateTime.Now.Ticks;

                //    TimeSpan ts = new TimeSpan(50, 0, 0, 0);
                //    DateTime dt2 = DateTime.Now.Subtract(ts);
                //    //				print (dt2.Ticks/10000000/3600);
                //    long tcTime = dt2.Ticks / 10000000;

                //    PlayerPrefs.SetString("tipStart", tcTime.ToString());
                //    GameData.getInstance().tickStartTime = tcTime.ToString();
                //    //				print (tcTime+"tctime11");
                //    canTick = true;
                //}
            }

            if (GameData.getInstance().tipRemain == 0)
            {
                canTick = true;
            }
            else
            {
                canTick = false;
            }



            GameObject tContainer = GameObject.Find("crispContainer");
            GameObject chessBoard = GameObject.Find("chessboard");
            GameObject placeRect  = GameObject.Find("placeRect");

            //reset all first,and record which one is current,skip to tip the correct block

            //record already correct;
            List <int> tCorrectBlockIds = new List <int>();

            for (int i = 0; i < GameData.instance.tangramPositions.Count; i++)
            {
                if (GameData.instance.currentStartPoses[i] == GameData.instance.tangramPositions[i])
                {
                    tCorrectBlockIds.Add(i);
                }
            }
            string tc = "";

            for (int a = 0; a < tCorrectBlockIds.Count; a++)
            {
                tc += tCorrectBlockIds[a];
            }

            foreach (Transform tblock in tContainer.transform)
            {
                string tblockName = tblock.name;

                bool ignoreCurrentBlock = false;
                for (int i = 0; i < tCorrectBlockIds.Count; i++)
                {
                    if (int.Parse(tblockName) == tCorrectBlockIds[i])
                    {
                        ignoreCurrentBlock = true;
                        break;
                    }
                }

                if (ignoreCurrentBlock)
                {
                    continue;
                }
                tblock.GetComponent <TouchPoly>().canplace = false;
                tblock.GetComponent <TouchPoly>().SendMessage("OnMouseUp");
            }



            //for (int i = 0; i <= GameData.instance.tipUsed; i++)
            for (int i = 0; i < tContainer.transform.childCount; i++)
            {
                if (GameData.instance.tipUsed < tContainer.transform.childCount)
                {
                    Transform tTipblock  = tContainer.transform.Find(i.ToString());//test
                    string    tblockName = tTipblock.name;

                    if (GameData.instance.tipRemain > 0)
                    {
                        //if no tip neccessary anymore.Disable tip button to disable waste.
                        //if no tip left,not disable the button. click tip again would ask for buy
                        if (GameData.instance.tipUsed >= tContainer.transform.childCount - 2)
                        {
                            GameObject.Find("btnTip").GetComponent <Button>().interactable = false;
                        }
                    }

                    bool isPlacedCorrect = false;
                    for (int ii = 0; ii < tCorrectBlockIds.Count; ii++)
                    {
                        if (int.Parse(tblockName) == tCorrectBlockIds[ii])
                        {
                            //print(tblockName + "id");
                            isPlacedCorrect = true;
                            break;
                        }
                    }
                    if (isPlacedCorrect)
                    {
                        continue;                 //ignore this block;
                    }
                    int selectedBlockId = int.Parse(tblockName);
                    tCorrectBlockIds.Add(selectedBlockId);

                    tTipblock.transform.localScale = Vector3.one;
                    tTipblock.transform.Find("Colliders").gameObject.SetActive(false);//GetComponent<MeshCollider>().enabled = false;
                    tTipblock.GetComponent <BoxCollider>().enabled = false;
                    Vector2 tpos = GameData.instance.tangramPositions[selectedBlockId];


                    //test
                    placeRect.transform.position = chessBoard.transform.position - new Vector3(GameData.instance.cheesBoardSize.x / 2, GameData.instance.cheesBoardSize.y / 2)
                                                   + new Vector3((tpos.x) * GameData.instance.cheesBoardSize.x / GameData.instance.gridSizeX, tpos.y * GameData.instance.cheesBoardSize.y / GameData.instance.gridSizeY);

                    //print(chessBoard.transform.position);


                    //placeRect.transform.position = new Vector2(-99999, 0);
                    tTipblock.transform.position = placeRect.transform.position;
                    tTipblock.GetComponent <TouchPoly>().getCurrentGrid(tTipblock.gameObject);//
                    tTipblock.GetComponent <TouchPoly>().canplace = true;
                    tTipblock.GetComponent <TouchPoly>().SendMessage("OnMouseUp");
                    //only give one tip
                    break;
                }
            }
            GameData.instance.tipUsed++;
        }