Beispiel #1
0
        /// <summary>
        /// 运行小球走直线至停止
        /// </summary>
        /// <param name="nextPos"></param>
        /// <param name="dir"></param>
        /// <returns></returns>
        public Vector3 RunBallLine(Vector3 nextPos, int dir)
        {
            Vector3 endVec = nextPos;

            while (true)
            {
                GridClass gridClass = createGridClassDic[nextPos];
                if (gridClass.type == 0)
                {
                    endVec = nextPos;
                    break;
                }
                createGridClassDic[nextPos].countValue++;
                Debug.Log("^^^^&&&&$$$ " + nextPos);

                Vector3[] dirVec = { gridClass.upIndex, gridClass.downIndex, gridClass.leftIndex, gridClass.rightIndex };
                if (dirVec[dir] == outBorderVec)
                {
                    endVec = nextPos;
                    break;
                }
                GridClass gridNextClass = createGridClassDic[dirVec[dir]];
                if (gridNextClass.type == 0)
                {
                    endVec = nextPos;
                    break;
                }
                nextPos = dirVec[dir];
            }
            return(endVec);
        }
Beispiel #2
0
 public void Init(GridClass gridClass, Color color)
 {
     itemGridClass = gridClass;
     fillColor     = color;
     //fillMat = new Material(Shader.Find("Standard"));
     //fillMat.color = color;
 }
Beispiel #3
0
        /// <summary>
        /// 显示地图
        /// </summary>
        /// <param name="mapClass"></param>
        private void ShowMap(MapClass mapClass)
        {
            for (int i = 0; i < mapObjList.Count; i++)
            {
                Destroy(mapObjList[i]);
            }
            mapObjList.Clear();

            int     count     = mapClass.width * mapClass.height;
            int     halfRow   = Mathf.FloorToInt(mapClass.width / 2f);
            int     halfColum = Mathf.FloorToInt(mapClass.height / 2f);
            Vector2 xLimit    = new Vector2(-halfRow, halfRow);
            Vector2 yLimit    = new Vector2(-halfColum, halfColum);

            Color fillColor = Color.gray;

            for (int i = 0; i < mapClass.gridList.Count; i++)
            {
                GridClass  gridClass = mapClass.gridList[i];
                GameObject obj       = Instantiate(gridItemObj);
                obj.transform.SetParent(bgParentTrm);
                obj.transform.localPosition = new Vector3(gridClass.gridIndex.x, -0.29f, gridClass.gridIndex.z);
                obj.transform.localScale    = Vector3.one * 0.9f;
                GridItem gridItem = obj.GetComponent <GridItem>();
                gridItem.Init(gridClass, fillColor);

                if (gridClass.type == 2)
                {
                    //GameObject wallObj = Instantiate(fillItemObj);
                    //wallObj.transform.SetParent(obj.transform);
                    //wallObj.transform.localPosition = new Vector3(0, 1f, 0);
                    //wallObj.transform.localScale = Vector3.one;
                }
                else if (gridClass.type == 0)
                {
                    GameObject wallObj = Instantiate(wallItemObj);
                    wallObj.transform.SetParent(obj.transform);
                    wallObj.transform.localPosition = new Vector3(0, 1f, 0);
                    wallObj.transform.localScale    = Vector3.one;
                }
                else if (gridClass.type == 1)
                {
                }



                mapObjList.Add(obj);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 执行小球运行操作
        /// </summary>
        /// <param name="indexToGridClassDi"></param>
        public void RunBallOnTheMap()
        {
            Vector3 initPos = new Vector3(posX, 0, posY);
            int     runNum  = 0;

            while (runNum < runTimes)
            {
                Debug.Log("###!!!!***  " + initPos);
                if (!createGridClassDic.ContainsKey(initPos))
                {
                    return;
                }
                GridClass  gridClass = createGridClassDic[initPos];
                Vector3[]  dirVec    = { gridClass.upIndex, gridClass.downIndex, gridClass.leftIndex, gridClass.rightIndex };
                List <int> tagList   = new List <int>();
                for (int i = 0; i < dirVec.Length; i++)
                {
                    if (dirVec[i] == outBorderVec)
                    {
                        continue;
                    }
                    GridClass gridNextClass = createGridClassDic[dirVec[i]];
                    if (gridNextClass.type == 0)
                    {
                        continue;
                    }
                    tagList.Add(i);
                }

                if (tagList.Count == 0)
                {
                    return;
                }

                int random = Random.Range(0, tagList.Count);
                Debug.Log("************  " + tagList[random]);
                Vector3 endVec = RunBallLine(dirVec[tagList[random]], tagList[random]);
                initPos = endVec;
                runNum++;
            }
        }
Beispiel #5
0
        /// <summary>
        /// 创建地图文件
        /// </summary>
        private void CreateBaseMap()
        {
            createGridClassDic.Clear();
            int     halfRow     = Mathf.FloorToInt(row / 2f);
            int     halfColum   = Mathf.FloorToInt(colum / 2f);
            Vector2 xLimit      = new Vector2(-halfRow, row - halfRow - 1);
            Vector2 yLimit      = new Vector2(-halfColum, colum - halfColum - 1);
            int     index       = 1;
            int     count       = (row - 2) * (colum - 2);
            int     borderIndex = count + 1;

            for (int i = (int)xLimit.x; i <= xLimit.y; i++)
            {
                for (int j = (int)yLimit.x; j <= yLimit.y; j++)
                {
                    GridClass itemGridClass = new GridClass();
                    itemGridClass.gridIndex = new Vector3(i, 0, j);
                    if ((j + 1) > yLimit.y)
                    {
                        itemGridClass.upIndex = outBorderVec;
                    }
                    else
                    {
                        itemGridClass.upIndex = new Vector3(i, 0, j + 1);
                    }
                    if ((j - 1) < yLimit.x)
                    {
                        itemGridClass.downIndex = outBorderVec;
                    }
                    else
                    {
                        itemGridClass.downIndex = new Vector3(i, 0, j - 1);
                    }
                    if ((i - 1) < xLimit.x)
                    {
                        itemGridClass.leftIndex = outBorderVec;
                    }
                    else
                    {
                        itemGridClass.leftIndex = new Vector3(i - 1, 0, j);
                    }
                    if ((i + 1) > xLimit.y)
                    {
                        itemGridClass.rightIndex = outBorderVec;
                    }
                    else
                    {
                        itemGridClass.rightIndex = new Vector3(i + 1, 0, j);
                    }

                    if (i == xLimit.x || i == xLimit.y || j == yLimit.x || j == yLimit.y)
                    {
                        itemGridClass.index      = borderIndex;
                        itemGridClass.type       = 0;
                        itemGridClass.countValue = 0;
                        borderIndex++;
                    }
                    else
                    {
                        itemGridClass.index = index;
                        if (balkIndexPosDic.ContainsKey(index))
                        {
                            itemGridClass.type       = 2;
                            itemGridClass.countValue = 1;
                            balkIndexPosDic[index]   = itemGridClass.gridIndex;
                        }
                        else
                        {
                            itemGridClass.type       = 0;
                            itemGridClass.countValue = 0;
                        }
                        index++;
                    }
                    createGridClassDic.Add(itemGridClass.gridIndex, itemGridClass);
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// 合并地图后显示
        /// </summary>
        /// <param name="mapClass"></param>
        private void ShowCombineMap(MapClass mapClass)
        {
            isWinFull = false;
            for (int i = 0; i < mapObjList.Count; i++)
            {
                Destroy(mapObjList[i]);
            }
            mapObjList.Clear();
            if (wallParentTempObj != null)
            {
                Destroy(wallParentTempObj);
            }
            if (mapParentTempObj != null)
            {
                Destroy(mapParentTempObj);
            }

            mapGridList.Clear();
            balkVecList.Clear();
            mapVecToItemDic.Clear();

            int squareIndex = 0;

            switch (mapClass.width)
            {
            case 12:
                squareIndex = 0;
                break;

            case 16:
                squareIndex = 1;
                break;

            case 20:
                squareIndex = 2;
                break;

            default:
                squareIndex = 0;
                break;
            }

            if (lastSquareIndex != squareIndex)
            {
                if (squareTrm != null && ballTrm != null)
                {
                    Destroy(ballTrm.gameObject);
                    Destroy(squareTrm.gameObject);
                }

                GameObject squareObj = Instantiate(squarePrefabs[squareIndex]);
                squareTrm    = squareObj.transform;
                mapParentTrm = squareTrm.GetComponent <SquareItem>().groundParentTrm;

                GameObject ballObj = Instantiate(ballItemObj);
                ballTrm = ballObj.transform;
                ballObj.transform.SetParent(mapParentTrm);
                BallChangeSkin();
            }
            lastSquareIndex = squareIndex;
            touchCtrl.SetSquareTrm(squareTrm, ballTrm);

            Tweener tweener = squareTrm.DOLocalRotate(Vector3.zero, 0.5f);

            tweener.OnComplete(() => {
                Color fillColor     = ConfigSystem.instance.GetMapColor();
                Color wallColor     = ConfigSystem.instance.GetWallColor();
                Vector3 initBallPos = outBorderVec;

                #region   合并个体优化地图加载
                //GameObject wallParentObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
                //wallParentObj.transform.localPosition = Vector3.zero;
                //Destroy(wallParentObj.GetComponent<BoxCollider>());
                //wallParentObj.name = "WallParent";
                //wallParentObj.GetComponent<MeshRenderer>().material.color = wallColor;
                //wallParentTempObj = wallParentObj;

                //GameObject mapParentObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
                //mapParentObj.transform.localPosition = Vector3.zero;
                //Destroy(mapParentObj.GetComponent<BoxCollider>());
                //mapParentObj.name = "MapParent";
                //mapParentTempObj = mapParentObj;

                //float baseY = 3f;
                ////加载地图
                //for (int i = 0; i < mapClass.gridList.Count; i++)
                //{
                //    GridClass gridClass = mapClass.gridList[i];
                //    if (gridClass.type == 0)
                //    {
                //        GameObject obj = Instantiate(gridItemObj);
                //        obj.transform.SetParent(wallParentObj.transform);
                //        obj.transform.localPosition = new Vector3(gridClass.gridIndex.x, baseY + 0f, gridClass.gridIndex.z);
                //        obj.transform.localScale = new Vector3(1f, 0.5f, 1f);
                //        GridItem gridInfo = obj.GetComponent<GridItem>();
                //        gridInfo.Init(gridClass, fillColor);
                //        //mapObjList.Add(obj);

                //        gridInfo.isOpenCollision = false;
                //        GameObject wallObj = Instantiate(wallItemObj);
                //        wallObj.transform.SetParent(wallParentObj.transform);
                //        wallObj.transform.localPosition = new Vector3(gridClass.gridIndex.x, baseY + 0.5f, gridClass.gridIndex.z);
                //        wallObj.transform.localScale = new Vector3(1f, 0.5f, 1f);
                //        GridItem gridInfo2 = wallObj.GetComponent<GridItem>();
                //        gridInfo2.InitWall(wallColor);
                //        //mapObjList.Add(wallObj);
                //    }
                //    else
                //    {
                //        GameObject obj = Instantiate(gridItemObj);
                //        obj.transform.SetParent(mapParentObj.transform);
                //        obj.transform.localPosition = new Vector3(gridClass.gridIndex.x, baseY + 0f, gridClass.gridIndex.z);
                //        obj.transform.localScale = new Vector3(1f, 0.5f, 1f);
                //        GridItem gridInfo = obj.GetComponent<GridItem>();
                //        gridInfo.Init(gridClass, fillColor);
                //        //mapObjList.Add(obj);

                //        Vector3 mapIntVec = obj.transform.localPosition;
                //        mapVecToItemDic.Add(new Vector3(Mathf.Round(mapIntVec.x), baseY + 0f, Mathf.Round(mapIntVec.z)), gridInfo);
                //        gridInfo.isOpenCollision = true;
                //        mapGridList.Add(gridClass.index);
                //        if (gridClass.type == 2)
                //        {
                //            if (initBallPos == outBorderVec)
                //            {
                //                initBallPos = gridClass.gridIndex;
                //            }
                //        }

                //        balkVecList.Add(gridClass.gridIndex);
                //    }
                //}
                //CombineMeshs wallCombineMeshs = wallParentObj.AddComponent<CombineMeshs>();
                //wallCombineMeshs.NoMatCombineMeshs();
                //wallParentObj.transform.SetParent(mapParentTrm);
                //wallParentObj.transform.localPosition = new Vector3(0f, -baseY, 0f);

                //CombineMeshs mapCombineMeshs = mapParentObj.AddComponent<CombineMeshs>();
                //mapCombineMeshs.MatCombineMeshs();
                //mapParentObj.transform.SetParent(mapParentTrm);
                //mapParentObj.transform.localPosition = new Vector3(0f, -baseY, 0f);
                #endregion

                #region  未优化前加载地图
                //加载地图
                for (int i = 0; i < mapClass.gridList.Count; i++)
                {
                    GridClass gridClass = mapClass.gridList[i];
                    GameObject obj      = Instantiate(gridItemObj);
                    obj.transform.SetParent(mapParentTrm);
                    obj.transform.localPosition = new Vector3(gridClass.gridIndex.x, 0f, gridClass.gridIndex.z);
                    obj.transform.localScale    = new Vector3(1f, 0.5f, 1f);
                    GridItem gridInfo           = obj.GetComponent <GridItem>();
                    gridInfo.Init(gridClass, fillColor);
                    mapObjList.Add(obj);

                    if (gridClass.type == 0)
                    {
                        gridInfo.isOpenCollision = false;
                        GameObject wallObj       = Instantiate(wallItemObj);
                        wallObj.transform.SetParent(mapParentTrm);
                        wallObj.transform.localPosition = new Vector3(gridClass.gridIndex.x, 0.5f, gridClass.gridIndex.z);
                        wallObj.transform.localScale    = new Vector3(1f, 0.5f, 1f);
                        GridItem gridInfo2 = wallObj.GetComponent <GridItem>();
                        gridInfo2.InitWall(wallColor);
                        mapObjList.Add(wallObj);
                    }
                    else
                    {
                        Vector3 mapIntVec = obj.transform.localPosition;    //obj.transform.localPosition + transform.localPosition;
                        mapVecToItemDic.Add(new Vector3(Mathf.Round(mapIntVec.x), 0f, Mathf.Round(mapIntVec.z)), gridInfo);

                        gridInfo.isOpenCollision = true;
                        mapGridList.Add(gridClass.index);
                        if (gridClass.type == 2)
                        {
                            if (initBallPos == outBorderVec)
                            {
                                initBallPos = gridClass.gridIndex;
                            }
                        }

                        balkVecList.Add(gridClass.gridIndex);
                    }
                }
                #endregion

                EventSystem.instance.GameMapCreateEndEvent(mapVecToItemDic);

                ballTrm.position = initBallPos + mapParentTrm.position + Vector3.up * 0.5f;
                BallGravityCtrl(false);
            });
        }