예제 #1
0
    void InstantiateElements(MapInfo mapInfo)
    {
        for (int i = 0; i < mapInfo.tileMap.Count; i++)
        {
            MapRow mapRow = mapInfo.tileMap[i];


            for (int j = 0; j < mapRow.tiles.Count; j++)
            {
                MapTile mapTile = mapRow.tiles[j];

                GridCell cell = cells[i][j];

                cell.tile = tileFactory.CreateNewTile(mapTile.tileType);

                // TODO: Esto lo necesitamos?
                cell.xPos = i;
                cell.yPos = j;
                // -----------

                Vector2 gridPosition  = new Vector2(i, j);
                Vector3 worldPosition = CalculateWorldPosition(gridPosition);
                cell.tile.transform.position = worldPosition;
                cell.tile.name       = "tile" + i + "|" + j;
                cell.tile.resistance = mapTile.tileResist;
                cell.tile.X          = i;
                cell.tile.Y          = j;

                // If has actor
                if (mapTile.actorType >= 0)
                {
                    Actor actor = actorFactory.CreateNewActor(mapTile.actorType);
                    actor.name = "actor" + i + "|" + j;

                    // Ultra hack, no hagan esto en casa chicxs
                    Fire fire = actor as Fire;
                    if (fire != null)
                    {
                        cell.tile.Fire = fire;
                    }
                    else
                    {
                        cell.tile.Actor = actor;
                    }
                    actor.transform.parent = cell.tile.transform;
                }
            }
        }

        SetNeighbors(cells);
    }