Exemple #1
0
    public void MakeMovePuzzle()
    {
        if (cloneForMove == null)
        {
            cloneForMove = GameObject.Instantiate(this.gameObject, puzzleMoveTrans);
            PuzzleItemUI clonePuzzleItemUI = cloneForMove.GetComponent <PuzzleItemUI>();
            clonePuzzleItemUI.puzzleItemData = new PuzzleItemData();
            PuzzleItemData clonePuzzleItemData = clonePuzzleItemUI.puzzleItemData;

            clonePuzzleItemData.InitButtomPuzzleItemData(
                puzzleItemData.PID,
                puzzleItemData.Pwidth,
                puzzleItemData.Pheight,
                puzzleItemData.Playout,
                puzzleItemData.Pcenter);

            clonePuzzleItemUI.screenSpaceRectTransform = this.screenSpaceRectTransform;

            cloneForMove.name = this.gameObject.name + "Move";
        }
        cloneForMove.SetActive(false);
    }
Exemple #2
0
    public void SettlePuzzleFunc(SettlePuzzle settlePuzzle)
    {
        int pid = settlePuzzle.puzzleID;
        int prs = settlePuzzle.puzzleRotateState;
        int pgi = settlePuzzle.puzzleGridIndex;

        Debug.Log("pid:" + pid);
        Debug.Log("puzzleBarTrans.childCount:" + puzzleBarTrans.childCount);

        GameObject settlePuzzleOrigin = puzzleBarTrans.GetChild(pid).gameObject;
        GameObject settlePuzzleTemp   = GameObject.Instantiate(settlePuzzleOrigin);

        PuzzleItemUI   settlePuzzleOriginUI   = settlePuzzleOrigin.GetComponent <PuzzleItemUI>();
        PuzzleItemData settlePuzzleOriginData = settlePuzzleOriginUI.puzzleItemData;

        PuzzleItemUI   settlePuzzleTempUI   = settlePuzzleTemp.GetComponent <PuzzleItemUI>();
        PuzzleItemData settlePuzzleTempData = settlePuzzleTempUI.puzzleItemData;

        settlePuzzleTempData.InitButtomPuzzleItemData(
            settlePuzzleOriginData.PID,
            settlePuzzleOriginData.Pwidth,
            settlePuzzleOriginData.Pheight,
            settlePuzzleOriginData.Playout,
            settlePuzzleOriginData.Pcenter);

        settlePuzzleTempUI.cloneForMove             = settlePuzzleOriginUI.cloneForMove;
        settlePuzzleTempUI.screenSpaceRectTransform = settlePuzzleOriginUI.screenSpaceRectTransform;

        settlePuzzleTempData.PanelGridIndex = pgi;

        settlePuzzleTempUI.RotatePuzzleToState(prs);

        InsertPuzzle(settlePuzzleTemp, false);

        Destroy(settlePuzzleTemp);
    }
Exemple #3
0
    public void InsertPuzzle(GameObject puzzle = null, bool opRecordFlag = true)
    {
        Debug.Log("insert!");
        PuzzleItemUI   puzzleItemUI   = puzzle.GetComponent <PuzzleItemUI>();
        PuzzleItemData puzzleItemData = puzzleItemUI.puzzleItemData;

        int gridIndex = puzzleItemData.PanelGridIndex;

        if (puzzleItemData.NotSettleFlag)
        {
            //删除摄像机后不存在屏幕空间与世界空间的区分,但仍保留放置与否的区分
            //如果是从底部拖上来的拼图:
            //插入拼图时,生成一份新的拼图放在当前面板的同级面板puzzleContainPanel中
            //FINISH:如果在puzzleContainPanel中(即settlePuzzleList中)存在一个位置(gridIndex)相同,playout和rotatestate也相同的拼图,直接setactive即可
            bool       existFlag = false;
            GameObject opPuzzle  = null;
            for (int i = 0; i < puzzleContainPanelTrans.childCount; ++i)
            {
                GameObject     settlePuzzle         = puzzleContainPanelTrans.GetChild(i).gameObject;
                PuzzleItemUI   settlePuzzleItemUI   = settlePuzzle.GetComponent <PuzzleItemUI>();
                PuzzleItemData settlePuzzleItemData = settlePuzzleItemUI.puzzleItemData;

                // Debug.Log(
                //     "difference:" + "\n" +
                //     settlePuzzleItemUI.RotateState + " " + puzzleItemUI.RotateState + "\n" +
                //     settlePuzzleItemData.PanelGridIndex + " " + puzzleItemData.PanelGridIndex + "\n" +
                //     MatrixUtil.PrintIntArray(settlePuzzleItemData.Playout) + " " + MatrixUtil.PrintIntArray(puzzleItemData.Playout)
                // );

                //!数组不可直接用==进行对比//已修改成直接用PID进行对比

                if (settlePuzzleItemUI.RotateState == puzzleItemUI.RotateState &&
                    settlePuzzleItemData.PanelGridIndex == puzzleItemData.PanelGridIndex &&
                    settlePuzzleItemData.PID == puzzleItemData.PID)
                {
                    existFlag = true;
                    opPuzzle  = settlePuzzle;
                    break;
                }
            }


            if (existFlag)
            {
                opPuzzle.transform.localScale = Vector3.one;
                opPuzzle.GetComponent <PuzzleItemUI>().cloneForMove = puzzleItemUI.cloneForMove;
            }
            else
            {
                //这里还需要根据拼图的中心与pcenter的位置关系修改位置关系
                Transform gridTrans     = this.transform.GetChild(gridIndex);
                float     pwidthCenter  = puzzleItemData.Pwidth / 2.0f;
                float     pheightCenter = puzzleItemData.Pheight / 2.0f;

                float pcenterX = puzzleItemData.Pcenter[0] + 0.5f;
                float pcenterY = puzzleItemData.Pcenter[1] + 0.5f;

                float offsetX = (pwidthCenter - pcenterX) * gridLength;
                float offsetY = (pheightCenter - pcenterY) * gridLength;

                Vector3 gridTransCanvasSpacePos = gridTrans.GetComponent <RectTransform>().anchoredPosition;//Camera.main.WorldToScreenPoint(gridTrans.position);

                Vector3 newPos = new Vector3(gridTransCanvasSpacePos.x + offsetX, gridTransCanvasSpacePos.y - offsetY, puzzle.transform.position.z);

                // Debug.Log("PcenterX" + pcenterX + "PcenterY" + pcenterY + "\n" +
                //     "gridIndex:" + gridIndex + "\n" + "newPos:" + newPos + "\n" +
                // "gridTrans.position:" + gridTrans.position + " " + gridTransCanvasSpacePos + "\n" +
                // "offsetX:" + offsetX + "\n" +
                // "offsetY:" + offsetY + "\n" +
                // "gridLength:" + gridLength + "\n" +
                // "canvasScaler.scaleFactor:" + canvasScaler.scaleFactor);

                //Debug.Log("Insert Puzzle:" + puzzle.name);

                GameObject    newPuzzle          = GameObject.Instantiate(puzzle, puzzleContainPanelTrans);
                RectTransform newPuzzleRectTrans = newPuzzle.GetComponent <RectTransform>();
                newPuzzleRectTrans.anchorMin        = new Vector2(0, 1);
                newPuzzleRectTrans.anchorMax        = new Vector2(0, 1);
                newPuzzleRectTrans.anchoredPosition = newPos;

                //Debug.LogWarning(gridIndex + " " + gridTransCanvasSpacePos + " " + gridTrans.position + " " + newPos);

                // settlePuzzleList.Add(newPuzzle);
                newPuzzle.name = "SettlePuzzle";
                //将raycastTarget设为false避免触摸空白区域会拖动当前拼图
                newPuzzle.GetComponent <Image>().raycastTarget = false;

                // Debug.Log("gen pos:" + newPuzzle.transform.position + " " + Camera.main.WorldToScreenPoint(newPuzzle.transform.position));

                PuzzleItemUI newPuzzleItemUI = newPuzzle.GetComponent <PuzzleItemUI>();
                newPuzzleItemUI.puzzleItemData = new PuzzleItemData();
                PuzzleItemData newPuzzleItemData = newPuzzleItemUI.puzzleItemData;

                //newPuzzleItemData=puzzleItemData;

                newPuzzleItemData.InitButtomPuzzleItemData(
                    puzzleItemData.PID,
                    puzzleItemData.Pwidth,
                    puzzleItemData.Pheight,
                    puzzleItemData.Playout,
                    puzzleItemData.Pcenter);


                newPuzzleItemData.PanelGridIndex = puzzleItemData.PanelGridIndex;

                newPuzzleItemUI.ScaleRatio  = puzzleItemUI.ScaleRatio;
                newPuzzleItemUI.RotateState = puzzleItemUI.RotateState;

                newPuzzleItemUI.screenSpaceRectTransform = puzzleItemUI.screenSpaceRectTransform;



                if (newPuzzleItemUI.RotateState == 0 || newPuzzleItemUI.RotateState == 2)
                {
                    newPuzzle.GetComponent <RectTransform>().sizeDelta = new Vector2(gridLength * newPuzzleItemData.Pwidth, gridLength * newPuzzleItemData.Pheight);
                }
                else
                {
                    newPuzzle.GetComponent <RectTransform>().sizeDelta = new Vector2(gridLength * newPuzzleItemData.Pheight, gridLength * newPuzzleItemData.Pwidth);
                }

                newPuzzle.GetComponent <GridLayoutGroup>().cellSize = new Vector2(gridLength, gridLength);

                //要为拼图设置可以移动的拼图
                newPuzzleItemData.NotSettleFlag          = false;
                newPuzzleItemUI.cloneForMove             = puzzleItemUI.cloneForMove;
                newPuzzleItemUI.screenSpaceRectTransform = puzzleItemUI.screenSpaceRectTransform;

                opPuzzle = newPuzzle;
            }


            int[] oldLayout = generalPanelData.Playout;
            generalPanelData.ModiLayout(GeneralPanelData.GridType.Fill, puzzleItemData);
            int[] newLayout = generalPanelData.Playout;

            opPuzzle.SetActive(true);

            if (opRecordFlag)
            {
                //操作历史记录
                //TODO:记录摆放的拼图
                Operation op = new Operation(0, oldLayout, newLayout, opPuzzle);
                operationHistoryRecorder.Record(op);

                //播放下落动画
                // StartCoroutine(PuzzleDownMove(opPuzzle, 0.5f, 0.1f, () =>
                // {
                //     //检查游戏是否结束
                //     if (generalPanelData.CheckOver())
                //     {
                //         //通关
                //         //跳转到UIEnd
                //         uiplayPage.LevelOverStep1();
                //     }
                // }));

                StartCoroutine(PuzzleSettleAnim(opPuzzle, () => { }));
            }
        }
        else
        {
            //-删除摄像机后不存在屏幕空间与世界空间的区分,但仍保留放置与否的区分
            //如果是从面板中拖出的拼图:
            //直接修改拼图的位置即可
            puzzle.transform.localScale = Vector3.one;
            Transform gridTrans = this.transform.GetChild(gridIndex);

            float pwidthCenter  = puzzleItemData.Pwidth / 2.0f;
            float pheightCenter = puzzleItemData.Pheight / 2.0f;

            float pcenterX = puzzleItemData.Pcenter[0] + 0.5f;
            float pcenterY = puzzleItemData.Pcenter[1] + 0.5f;

            float offsetX = (pwidthCenter - pcenterX) * gridLength;
            float offsetY = (pheightCenter - pcenterY) * gridLength;

            Vector3 gridTransCanvasSpacePos = gridTrans.GetComponent <RectTransform>().anchoredPosition;

            Vector3 newPos = new Vector3(gridTransCanvasSpacePos.x + offsetX, gridTransCanvasSpacePos.y - offsetY, puzzle.transform.position.z);

            RectTransform puzzleRectTrans = puzzle.GetComponent <RectTransform>();
            puzzleRectTrans.anchorMin        = new Vector2(0, 1);
            puzzleRectTrans.anchorMax        = new Vector2(0, 1);
            puzzleRectTrans.anchoredPosition = newPos;

            // puzzle.transform.position = Camera.main.ScreenToWorldPoint(newPos);

            int[] oldLayout = generalPanelData.Playout;
            generalPanelData.ModiLayout(GeneralPanelData.GridType.Fill, puzzleItemData);
            int[] newLayout = generalPanelData.Playout;
            puzzle.SetActive(true);

            if (opRecordFlag)
            {
                //FINISH:操作历史记录
                Operation op = new Operation(1, oldLayout, newLayout, puzzle, puzzleItemData.LastPanelGridIndex, gridIndex);
                operationHistoryRecorder.Record(op);

                //播放下落动画
                // StartCoroutine(PuzzleDownMove(puzzle, 0.5f, 0.1f, () => { }));

                StartCoroutine(PuzzleSettleAnim(puzzle, () => { }));
            }
        }
    }