Пример #1
0
    public static void MoveEnd(VisualElement[,] mapVis, ElementData[,] map, int row, int shift = 0)
    {
        int dir = (int)Mathf.Sign(shift);

        shift = Mathf.Abs(shift);
        int shiftAmount = shift - (shift / mapVis.GetLength(1)) * mapVis.GetLength(1);

        //Debug.Log("SHIFT AMOUNT"+shiftAmount);

        VisualElement[] mapVis1Row = new VisualElement[mapVis.GetLength(1)];
        ElementData[]   mapRow     = new ElementData[map.GetLength(1)];


        for (int i = 0; i < mapVis.GetLength(1); i++)
        {
            mapVis1Row[i] = mapVis[row, i];
            mapRow[i]     = map[row, i];
        }

        VisualElement[] mapVisNew;
        ElementData[]   mapNew;


        if (dir == 1)
        {
            VisualElement[] step1 = mapVis1Row.Skip(shiftAmount).Take(mapVis1Row.Length - shiftAmount).ToArray();
            VisualElement[] step2 = mapVis1Row.Take(shiftAmount).ToArray();
            mapVisNew = step1.Concat(step2).ToArray();
            ElementData[] stepData1 = mapRow.Skip(shiftAmount).Take(mapRow.Length - shiftAmount).ToArray();
            ElementData[] stepData2 = mapRow.Take(shiftAmount).ToArray();
            mapNew = stepData1.Concat(stepData2).ToArray();
        }
        else
        {
            VisualElement[] step1 = mapVis1Row.Skip(mapVis1Row.Length - shiftAmount).Take(shiftAmount).ToArray();
            VisualElement[] step2 = mapVis1Row.Take(mapVis1Row.Length - shiftAmount).ToArray();
            mapVisNew = step1.Concat(step2).ToArray();


            ElementData[] stepData1 = mapRow.Skip(mapRow.Length - shiftAmount).Take(shiftAmount).ToArray();
            ElementData[] stepData2 = mapRow.Take(mapRow.Length - shiftAmount).ToArray();
            mapNew = stepData1.Concat(stepData2).ToArray();
        }
        for (int j = 0; j < mapVis.GetLength(1); j++)
        {
            mapVis[row, j] = mapVisNew[j];
            map[row, j]    = mapNew[j];
            Vector3 posMin = new Vector3(Mathf.Cos(anglesOfRows[j].x) * radiuses[row].x, Mathf.Sin(anglesOfRows[j].x) * radiuses[row].y, 0);
            mapVis[row, j].transform.localPosition = posMin;
            mapVis[row, j].SetRotation(anglesOfRows[j].x);
        }
    }