/// <summary>
    /// 从传送门补充方块到List中
    /// </summary>
    private static void DropFromDoor(DoorBean doorBean, int addCounts)
    {
        int inV  = doorBean.inVertical;
        int inH  = doorBean.inHorizontal;
        int outV = doorBean.outVertical;
        int outH = doorBean.outHorizontal;

        int inVGridCounts = 0;

        //判断入口列还剩余多少个方块,是否足以掉落至出口列,
        for (int h = inH; h >= 0; h--)
        {
            if (mGridBaseListManager[inV][h].isHasGrid && mGridBaseListManager[inV][h].spriteIndex != -1 && !(mGridBaseListManager[inV][h].spriteIndex >= 15 && mGridBaseListManager[inV][h].spriteIndex <= 21))
            {
                inVGridCounts++;
            }
        }

        //若不足,则从备用列生成补充
        if (inVGridCounts < addCounts)
        {
            DropFromTopList(inV, addCounts - inVGridCounts);
        }

        //根据addCounts执行循环
        for (int i = 0, inIndex = inH, topMoveCounts = 0; i < addCounts; i++, inIndex--, topMoveCounts++)
        {
            //下移的距离
            dropHeight = addCounts * mInterval;

            //修改入口列的掉落信息和List处理
            mGridListManager[inV][inIndex].dropHeight = dropHeight;
            mGridBaseListManager[inV][mGridListManager[inV][inIndex].horizontal].gridBean  = null;
            mGridBaseListManager[inV][mGridListManager[inV][inIndex].horizontal].isHasGrid = false;
            mGridListManager[inV][inIndex].isDropInDoor = true;
            mGridListManager[inV][inIndex].isDestroy    = true;

            //复制一个对象
            GridBean gridBean = GridBean.Clone(mGridListManager[inV][inIndex], mGrid);

            //计算传送出口在GridList中的索引
            outIndex = 0;
            for (int x = 0; x < mGridListManager[outV].Count; x++)
            {
                if (inV != outV)
                {
                    if (mGridListManager[outV][x].horizontal < outH)
                    {
                        outIndex++;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    if (mGridListManager[outV][x].horizontal < outH + addCounts - i)
                    {
                        outIndex++;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            //将该方块添加进传送出口的索引位置
            mGridListManager[outV].Insert(outIndex, gridBean);

            //修改出口列的掉落信息和List处理
            mGridListManager[outV][outIndex].horizontal = outH + addCounts - 1 - i;
            mGridListManager[outV][outIndex].vertical   = outV;
            mGridListManager[outV][outIndex].gridObject.GetComponent <RectTransform>().position = mGridBaseListManager[outV][outH].gridBase.GetComponent <RectTransform>().position + new Vector3(0.0f, (i + 1) * mInterval, 0.0f);
            mGridListManager[outV][outIndex].gridObject.name = "grid" + outV.ToString() + mGridListManager[outV][outIndex].horizontal.ToString();
            mGridBaseListManager[outV][mGridListManager[outV][outIndex].horizontal].isHasGrid   = true;
            mGridBaseListManager[outV][mGridListManager[outV][outIndex].horizontal].gridBean    = mGridListManager[outV][outIndex];
            mGridBaseListManager[outV][mGridListManager[outV][outIndex].horizontal].spriteIndex = gridBean.spriteIndex;
            mGridListManager[outV][outIndex].gridObject.SetActive(false);
            mGridListManager[outV][outIndex].isDropInDoor  = false;
            mGridListManager[outV][outIndex].isDestroy     = false;
            mGridListManager[outV][outIndex].isDropOutDoor = true;

            //入口的列的剩余方块,需掉落addCounts个格子
            if (i + 1 == addCounts)
            {
                for (int x = inH - addCounts; x >= 0; x--)
                {
                    mGridListManager[inV][x].dropHeight += addCounts * mInterval;
                    mGridListManager[inV][x].dropCounts += addCounts;
                    mGridBaseListManager[inV][mGridListManager[inV][x].horizontal].gridBean  = null;
                    mGridBaseListManager[inV][mGridListManager[inV][x].horizontal].isHasGrid = false;
                    mGridListManager[inV][x].horizontal     += addCounts;
                    mGridListManager[inV][x].gridObject.name = "grid" + inV.ToString() + mGridListManager[inV][x].horizontal.ToString();
                    mGridBaseListManager[inV][mGridListManager[inV][x].horizontal].isHasGrid   = true;
                    mGridBaseListManager[inV][mGridListManager[inV][x].horizontal].gridBean    = mGridListManager[inV][x];
                    mGridBaseListManager[inV][mGridListManager[inV][x].horizontal].spriteIndex = mGridListManager[inV][x].spriteIndex;
                }
            }
        }

        //从备用行补充传送门入口方块
        DropFromTopList(inV, addCounts);
    }
Exemple #2
0
    //类型选择方块点击事件
    public void OnGridTypeClick()
    {
        //用于计算选择了哪个类型
        gridSize = Screen.width / 10;

        originOfgridTypeBg = gridTypeBackground.GetComponent <RectTransform>().position.y;
        gridTpyeBgHeight   = gridTypeBackground.GetComponent <RectTransform>().sizeDelta.y;
        lines        = (int)(Math.Abs(Input.mousePosition.y - (originOfgridTypeBg + gridTpyeBgHeight / 2)) / gridSize);
        currentIndex = lines * 10 + (int)(Input.mousePosition.x / gridSize);

        //格子内容大小,用于计算坐标偏移
        gridSize = (Screen.width - leaveSize - (9 - 1) * intervalPx) / 9;

        //设置格子内容
        if (startVertical >= 0 && startHorizontal >= 0)
        {
            switch (currentIndex)
            {
            case 8:    //若选择了传送门出入口,则对应生成一个UI用于显示
                isCreateOne = true;
                if (doorListOfEditor != null && doorListOfEditor.Count > 0)
                {
                    //遍历List,如果传送门入口不存在则新创建,若存在,则消除
                    for (int i = 0; i < doorListOfEditor.Count; i++)
                    {
                        //删除传送门入口
                        if (doorListOfEditor[i].inVertical == startVertical && doorListOfEditor[i].inHorizontal == startHorizontal)
                        {
                            Destroy(doorListOfEditor[i].indoor);
                            Destroy(doorListOfEditor[i].outdoor);
                            doorListOfEditor.RemoveAt(i);
                            isCreateOne = false;
                            break;
                        }
                    }
                }
                //生成传送门入口
                if (isCreateOne)
                {
                    GameObject indoor = Instantiate(Resources.Load("prefabs/gridbase"), GridContentSet.transform) as GameObject;
                    Destroy(indoor.GetComponent <SpriteRenderer>());
                    indoor.name = "indoor" + startVertical.ToString() + startHorizontal.ToString();
                    indoor.AddComponent <Image>();
                    indoor.GetComponent <Image>().sprite = mSprites[currentIndex];
                    doorPoint = mGridBaseListManager[startVertical][startHorizontal].gridBase.GetComponent <RectTransform>().position;
                    indoor.GetComponent <RectTransform>().position  = doorPoint + new Vector3(0.0f, -gridSize * 2 / 3, 0.0f);
                    indoor.GetComponent <RectTransform>().sizeDelta = new Vector2(gridSize, gridSize);
                    indoor.GetComponent <RectTransform>().Rotate(new Vector3(75, 0.0f, 0.0f));

                    DoorBean doorBean = new DoorBean();
                    doorBean.inVertical   = startVertical;
                    doorBean.inHorizontal = startHorizontal;
                    doorBean.indoor       = indoor;
                    if (doorListOfEditor == null)
                    {
                        doorListOfEditor = new List <DoorBean>();
                    }
                    doorListOfEditor.Add(doorBean);
                }
                break;

            case 9:    //传送门出口坐标
                isCreateOne = true;
                if (doorListOfEditor != null && doorListOfEditor.Count > 0)
                {
                    //遍历List,如果传送门入口不存在则新创建,若存在,则消除
                    for (int i = 0; i < doorListOfEditor.Count; i++)
                    {
                        //删除传送门入口
                        if (doorListOfEditor[i].outVertical == startVertical && doorListOfEditor[i].outHorizontal == startHorizontal)
                        {
                            Destroy(doorListOfEditor[i].outdoor);
                            doorListOfEditor[i].outVertical = -1;
                            isCreateOne = false;
                            break;
                        }
                    }
                }
                //生成传送门出口
                if (isCreateOne)
                {
                    GameObject outdoor = Instantiate(Resources.Load("prefabs/gridbase"), GridContentSet.transform) as GameObject;
                    Destroy(outdoor.GetComponent <SpriteRenderer>());
                    outdoor.name = "outdoor" + startVertical.ToString() + startHorizontal.ToString();
                    outdoor.AddComponent <Image>();
                    outdoor.GetComponent <Image>().sprite = mSprites[currentIndex];
                    doorPoint = mGridBaseListManager[startVertical][startHorizontal].gridBase.GetComponent <RectTransform>().position;
                    outdoor.GetComponent <RectTransform>().position  = doorPoint + new Vector3(0.0f, gridSize * 2 / 3, 0.0f);
                    outdoor.GetComponent <RectTransform>().sizeDelta = new Vector2(gridSize, gridSize);
                    outdoor.GetComponent <RectTransform>().Rotate(new Vector3(75, 0.0f, 0.0f));

                    //遍历List,查找出口列为-1的索引,并设置
                    for (int i = 0; i < doorListOfEditor.Count; i++)
                    {
                        if (doorListOfEditor[i].outVertical == -1)
                        {
                            doorListOfEditor[i].outVertical   = startVertical;
                            doorListOfEditor[i].outHorizontal = startHorizontal;
                            doorListOfEditor[i].outdoor       = outdoor;
                            break;
                        }
                    }
                }
                break;

            case 10:    //设置冰块
            case 11:
            case 12:
                isCreateOne = true;
                if (iceListOfEditor != null && iceListOfEditor.Count > 0)
                {
                    for (int i = 0; i < iceListOfEditor.Count; i++)
                    {
                        //若已存在冰块,直接修改或者删除冰块,同一个格子,选择相同类型即去掉冰块
                        if (iceListOfEditor[i].iceVertical == startVertical && iceListOfEditor[i].iceHorizontal == startHorizontal)
                        {
                            if (iceListOfEditor[i].iceLevel != currentIndex - 9)
                            {
                                iceListOfEditor[i].iceLevel = currentIndex - 9;
                                iceListOfEditor[i].ice.GetComponent <Image>().sprite = mSprites[currentIndex];
                            }
                            else
                            {
                                Destroy(iceListOfEditor[i].ice);
                                iceListOfEditor.Remove(iceListOfEditor[i]);
                            }
                            isCreateOne = false;
                            break;
                        }
                    }
                }
                if (isCreateOne)
                {
                    CreateIce(startVertical, startHorizontal, currentIndex);
                }
                break;

            case 14:    //设置金豆荚篮子
                isCreateOne = true;
                if (basketListOfEditor != null && basketListOfEditor.Count > 0)
                {
                    for (int i = 0; i < basketListOfEditor.Count; i++)
                    {
                        if (basketListOfEditor[i].basketVertical == startVertical && basketListOfEditor[i].basketHorizontal == startHorizontal)
                        {
                            Destroy(basketListOfEditor[i].basket);
                            basketListOfEditor.Remove(basketListOfEditor[i]);
                            isCreateOne = false;
                            break;
                        }
                    }
                }
                if (isCreateOne)
                {
                    CreateBasket(startVertical, startHorizontal);
                }
                break;

            case 21:
                isCreateOne = true;
                if (timboListOfEditor != null && timboListOfEditor.Count > 0)
                {
                    for (int i = 0; i < timboListOfEditor.Count; i++)
                    {
                        if (timboListOfEditor[i].timboVertical == startVertical && timboListOfEditor[i].timboHorizontal == startHorizontal)
                        {
                            Destroy(timboListOfEditor[i].timbo);
                            timboListOfEditor.Remove(timboListOfEditor[i]);
                            isCreateOne = false;
                            break;
                        }
                    }
                }
                if (isCreateOne)
                {
                    CreateTimbo(startVertical, startHorizontal);
                }
                break;

            default:    //设置格子内容
                gridListOfEditor[startVertical][startHorizontal].gridObject.GetComponent <Image>().sprite = mSprites[currentIndex];
                gridListOfEditor[startVertical][startHorizontal].spriteIndex = currentIndex;
                break;
            }
        }

        //设置消除类型
        if (startVertical < 0 && startHorizontal < 0)
        {
            //编辑器更新目标类型
            targetTypeChoose.GetComponent <Image>().sprite = mSprites[currentIndex];
            targetTypeIndex = currentIndex;
        }

        //隐藏方块类型选择列表
        gridTypeBackground.SetActive(false);
    }
    public void InitData()
    {
        //[0]读取配置,获取对象
        editorData = JsonUtil.GetEditorData(10);
        GridUIAttributeManager.GetInstance().editorData = editorData;

        //[1]获取格子内容信息
        if (!editorData.gridData.Equals(""))
        {
            string[] gridDatas = editorData.gridData.Split(',');
            gridDataList = new List <GridBean>();
            foreach (string grid in gridDatas)
            {
                if (!grid.Equals(""))
                {
                    string[] result   = grid.Split('|');
                    GridBean gridBean = new GridBean();
                    gridBean.vertical    = int.Parse(result[0]);
                    gridBean.horizontal  = int.Parse(result[1]);
                    gridBean.spriteIndex = int.Parse(result[2]);
                    gridDataList.Add(gridBean);
                }
            }
            GridUIAttributeManager.GetInstance().gridDataList = gridDataList;
        }

        //[2]获取传送门数据
        if (!editorData.doorData.Equals(""))
        {
            string[] doorDatas = editorData.doorData.Split(',');
            doorDataList = new List <DoorBean>();
            foreach (string door in doorDatas)
            {
                if (!door.Equals(""))
                {
                    string[] result   = door.Split('|');
                    DoorBean doorBean = new DoorBean();
                    doorBean.inVertical    = int.Parse(result[0]);
                    doorBean.inHorizontal  = int.Parse(result[1]);
                    doorBean.outVertical   = int.Parse(result[2]);
                    doorBean.outHorizontal = int.Parse(result[3]);
                    doorDataList.Add(doorBean);
                }
            }
            GridUIAttributeManager.GetInstance().doorDataList = doorDataList;
        }

        //[3]获取冰块数据
        if (!editorData.iceData.Equals(""))
        {
            string[] iceDatas = editorData.iceData.Split(',');
            iceDataList = new List <IceBean>();
            foreach (string ice in iceDatas)
            {
                if (!ice.Equals(""))
                {
                    string[] result  = ice.Split('|');
                    IceBean  iceBean = new IceBean();
                    iceBean.iceVertical   = int.Parse(result[0]);
                    iceBean.iceHorizontal = int.Parse(result[1]);
                    iceBean.iceLevel      = int.Parse(result[2]);
                    iceDataList.Add(iceBean);
                }
            }
            GridUIAttributeManager.GetInstance().iceDataList = iceDataList;
        }

        //获取金豆荚篮子数据
        if (!editorData.basketData.Equals(""))
        {
            string[] basketDatas = editorData.basketData.Split(',');
            basketDataList = new List <BasketBean>();
            foreach (string basket in basketDatas)
            {
                if (!basket.Equals(""))
                {
                    string[]   result     = basket.Split('|');
                    BasketBean basketBean = new BasketBean();
                    basketBean.basketVertical   = int.Parse(result[0]);
                    basketBean.basketHorizontal = int.Parse(result[1]);
                    basketDataList.Add(basketBean);
                }
            }
            GridUIAttributeManager.GetInstance().basketDataList = basketDataList;
        }

        //获取树藤数据
        if (!editorData.timboData.Equals(""))
        {
            string[] timboDatas = editorData.timboData.Split(',');
            timboDataList = new List <TimboBean>();
            foreach (string timbo in timboDatas)
            {
                if (!timbo.Equals(""))
                {
                    string[]  result    = timbo.Split('|');
                    TimboBean timboBean = new TimboBean();
                    timboBean.timboVertical   = int.Parse(result[0]);
                    timboBean.timboHorizontal = int.Parse(result[1]);
                    timboDataList.Add(timboBean);
                }
            }
            GridUIAttributeManager.GetInstance().timboDataList = timboDataList;
        }
    }