RaposoTKD

Untitled

Mar 4th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. private void ReadMapData(){
  2.         //Le o scriptable obj
  3.         foreach(MapData.Obstacle obstacle in mapData[currentMap].obstacles){
  4.             int x = (int)obstacle.position.x, y = (int)obstacle.position.y;
  5.             map[(int)x,(int)y] = 1;
  6.             Vector2 position = new Vector2((float)x, (float)y) * tiles[0].GetComponent<SpriteRenderer>().size.x;
  7.             var go = CreateTile((TileType)1, position);
  8.             go.name = tiles[map[x,y]].name +" ("+x+","+y+")";
  9.             SetOrdingLayerByPosition(go.GetComponent<SpriteRenderer>(), y, totalSize);
  10.             go.GetComponent<SpriteRenderer>().sprite = obstacle.sprite;
  11.             if (obstacle.mirrored) go.transform.Rotate(Vector2.up * 180);
  12.         }
  13.     }
  14.     private void InitializeMap(){
  15.         //A partir da matriz map o metodo instancia os tiles. Ele centraliza a posicao de mapParente e também faz um efeito de xadrez com as cores
  16.         for(int y = 0; y < totalSize; y++){
  17.             for(int x = 0; x < totalSize; x++){
  18.                 int tileIndex = map[x,y];
  19.                 Vector2 position = new Vector2((float) x,(float) y)*tiles[0].GetComponent<SpriteRenderer>().size.x;
  20.                 GameObject go = CreateTile(0, position);
  21.                 go.name = tiles[map[x,y]].name +" ("+x+","+y+")";
  22.                 /*if(map[x,y] == TileType.EMPTY.GetHashCode())*/ SetColorByPosition(go.GetComponent<SpriteRenderer>(),x+y);
  23.                 SetOrdingLayerByPosition(go.GetComponent<SpriteRenderer>(), y, totalSize);
  24.                 if (x == 0 || y == 0 || x == totalSize - 1 || y == totalSize - 1) {
  25.                     //jesus cristo
  26.                     GameObject wall = CreateTile((TileType)1, position);
  27.                     SetOrdingLayerByPosition(wall.GetComponent<SpriteRenderer>(), y, totalSize);
  28.                 }
  29.             }
  30.         }
  31.         mapParent.transform.position -= new Vector3(totalSize*tileSize - tileSize*0.5f,totalSize*tileSize - tileSize,0)*0.5f;
  32.     }
Advertisement
Add Comment
Please, Sign In to add comment