Example #1
0
    //元素互换
    private static void exchangeGrid(LeaveGridMsg gridA, LeaveGridMsg gridB)
    {
        //获取互换位置的索引
        int gridAInedx = mGridListManager[gridA.vertical].IndexOf(mGridBaseListManager[gridA.vertical][gridA.horizontal].gridBean);
        int gridBInedx = mGridListManager[gridB.vertical].IndexOf(mGridBaseListManager[gridB.vertical][gridB.horizontal].gridBean);

        //复制互换的对象
        GridBean cloneGridA = GridBean.mClone(mGridBaseListManager[gridA.vertical][gridA.horizontal].gridBean, mGrid);
        GridBean cloneGridB = GridBean.mClone(mGridBaseListManager[gridB.vertical][gridB.horizontal].gridBean, mGrid);

        //移除对象
        Destroy(mGridBaseListManager[gridA.vertical][gridA.horizontal].gridBean.gridObject);
        Destroy(mGridBaseListManager[gridB.vertical][gridB.horizontal].gridBean.gridObject);

        mGridListManager[gridA.vertical].RemoveAt(gridAInedx);
        //根据索引添加复制后的对象
        if (gridAInedx < 8)
        {
            mGridListManager[gridA.vertical].Insert(gridAInedx, cloneGridB);
        }
        else
        {
            mGridListManager[gridA.vertical].Add(cloneGridB);
        }

        mGridListManager[gridB.vertical].RemoveAt(gridBInedx);
        if (gridBInedx < 8)
        {
            mGridListManager[gridB.vertical].Insert(gridBInedx, cloneGridA);
        }
        else
        {
            mGridListManager[gridB.vertical].Add(cloneGridA);
        }

        //修改互换的数据
        mGridListManager[gridA.vertical][gridAInedx].vertical   = gridA.vertical;
        mGridListManager[gridA.vertical][gridAInedx].horizontal = gridA.horizontal;
        mGridListManager[gridA.vertical][gridAInedx].gridObject.GetComponent <RectTransform>().position = mGridBaseListManager[gridA.vertical][gridA.horizontal].gridBase.GetComponent <RectTransform>().position;
        mGridListManager[gridA.vertical][gridAInedx].gridObject.name       = "grid" + gridA.vertical.ToString() + gridA.horizontal.ToString();
        mGridBaseListManager[gridA.vertical][gridA.horizontal].gridBean    = mGridListManager[gridA.vertical][gridAInedx];
        mGridBaseListManager[gridA.vertical][gridA.horizontal].spriteIndex = mGridListManager[gridA.vertical][gridAInedx].spriteIndex;

        mGridListManager[gridB.vertical][gridBInedx].vertical   = gridB.vertical;
        mGridListManager[gridB.vertical][gridBInedx].horizontal = gridB.horizontal;
        mGridListManager[gridB.vertical][gridBInedx].gridObject.GetComponent <RectTransform>().position = mGridBaseListManager[gridB.vertical][gridB.horizontal].gridBase.GetComponent <RectTransform>().position;
        mGridListManager[gridB.vertical][gridBInedx].gridObject.name       = "grid" + gridB.vertical.ToString() + gridB.horizontal.ToString();
        mGridBaseListManager[gridB.vertical][gridB.horizontal].gridBean    = mGridListManager[gridB.vertical][gridBInedx];
        mGridBaseListManager[gridB.vertical][gridB.horizontal].spriteIndex = mGridListManager[gridB.vertical][gridBInedx].spriteIndex;
    }
Example #2
0
    /// <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.mClone(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);
    }