Esempio n. 1
0
    public static TileStruct[][] CropMap(TileStruct[][] map,int x1, int y1, int x2, int y2)
    {
        int height = Mathf.Abs(y1 - y2);
        IEnumerable<TileStruct> arr = map.Skip(x1)
                            .Take(x2 - x1)
                            .SelectMany(a => a.Skip(y1).Take(y2 - y1));

         var array = arr.Select((x, i) => new { Index = i, Value = x })
        .GroupBy(x => x.Index / height)
        .Select(x => x.Select(v => v.Value).ToList().ToArray())
        .ToArray();

        TileStruct[][] outArray = new TileStruct[array.Length][];
         for (int i = 0; i < array.Length; i++)
		{
             outArray[i] = new TileStruct[array[i].Length];
            for (int y = 0; y < array[i].Length; y++)
            {
                var input = array[i][y];
                outArray[i][y] = new TileStruct(input.X, input.Y, input.Type);
            }
		}

         return outArray;
    }
Esempio n. 2
0
    //no cloning
    public static TileStruct[][] CropMap2(TileStruct[][] map, int x1, int y1, int x2, int y2, TileType corridor)
    {
        int height = Mathf.Abs(y1 - y2);
        IEnumerable<TileStruct> arr = map.Skip(x1)
                            .Take(x2 - x1)
                            .SelectMany(a => a.Skip(y1).Take(y2 - y1));

        var array = arr.Select((x, i) => new { Index = i, Value = x })
       .GroupBy(x => x.Index / height)
       
       .Select(x => x.Select(v => v.Value).ToList().ToArray())
   
       .ToArray();


        foreach (var item in array)
        {
            foreach (var item2 in item)
            {
                item2.Type = corridor;
            }
        }

        

        return array;
    }