Ejemplo n.º 1
0
 public void SetMap(GraphicsMap _GraphicsMap, bool _Split)
 {
     TimeTakenCounter = 0;
     if (_Split)
     {
         LoadMapStage    = 1;
         GraphicsMapload = _GraphicsMap;
     }
     else
     {
         SetMapStage(_GraphicsMap, 0);
         SetMapStage(_GraphicsMap, 1);
         SetMapStage(_GraphicsMap, 2);
     }
 }
Ejemplo n.º 2
0
 private void SetMapStage(GraphicsMap _GraphicsMap, int _Stage)
 {
     if (_Stage == 0)
     {
         MapWidth  = _GraphicsMap.Width;
         MapHeight = _GraphicsMap.Height;
         ClearMap(); //Deletes all chunks and all tiles.
     }
     if (_Stage == 1)
     {
         GenerateChunks(_GraphicsMap);
     }
     if (_Stage == 2)
     {
         CreatesIndividualTiles(_GraphicsMap);
     }
 }
Ejemplo n.º 3
0
    void CreatesIndividualTiles(GraphicsMap _GraphicsMap)
    {
        Tiles = new GameObject[MapWidth, MapHeight]; //Resets array for Tiles.
        for (int a = 0; a < MapWidth; a++)           //Counts each tile
        {
            for (int b = 0; b < MapHeight; b++)
            {
                GameObject _NewTile = GameObject.Instantiate(TileObject); //Creates new tile from template.
                _NewTile.SetActive(false);
                Texture2D _NewTexture;                                    //Creates new texture
                _NewTexture = Error;                                      //Sets it as eroor to start off with

                //Gets rotation and direction numbers from direction array, and so texture
                if (_GraphicsMap.GraphicsMapMatrix[a, b].Directions[0] == -1)
                {
                    //If special case
                    _NewTexture = RotationNumbersToTexture2D(_GraphicsMap.GraphicsMapMatrix[a, b].Type, _GraphicsMap.GraphicsMapMatrix[a, b].Directions[1], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[2]);
                }
                else
                {
                    if (RenderedBlocks.ContainsKey(new int[] { _GraphicsMap.GraphicsMapMatrix[a, b].Type, _GraphicsMap.GraphicsMapMatrix[a, b].Directions[0], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[1], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[2], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[3] }))
                    {
                        _NewTexture = RenderedBlocks[new int[] { _GraphicsMap.GraphicsMapMatrix[a, b].Type, _GraphicsMap.GraphicsMapMatrix[a, b].Directions[0], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[1], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[2], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[3] }];
                    }
                    else
                    {
                        Texture2D _TopLeftTexture     = RotationNumbersToTexture2D(_GraphicsMap.GraphicsMapMatrix[a, b].Type, 1, _GraphicsMap.GraphicsMapMatrix[a, b].Directions[0]);
                        Texture2D _TopRightTexture    = RotationNumbersToTexture2D(_GraphicsMap.GraphicsMapMatrix[a, b].Type, 2, _GraphicsMap.GraphicsMapMatrix[a, b].Directions[1]);
                        Texture2D _BottomLeftTexture  = RotationNumbersToTexture2D(_GraphicsMap.GraphicsMapMatrix[a, b].Type, 3, _GraphicsMap.GraphicsMapMatrix[a, b].Directions[2]);
                        Texture2D _BottomRightTexture = RotationNumbersToTexture2D(_GraphicsMap.GraphicsMapMatrix[a, b].Type, 4, _GraphicsMap.GraphicsMapMatrix[a, b].Directions[3]);
                        _NewTexture = CombineTexturesForTiles(new Texture2D[] { _BottomRightTexture, _BottomLeftTexture, _TopLeftTexture, _TopRightTexture }, 2, 2, 250); //Combines Texture into one.
                        RenderedBlocks.Add(new int[] { _GraphicsMap.GraphicsMapMatrix[a, b].Type, _GraphicsMap.GraphicsMapMatrix[a, b].Directions[0], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[1], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[2], _GraphicsMap.GraphicsMapMatrix[a, b].Directions[3] }, _NewTexture);
                    }
                }
                _NewTile.name                 = "Tile (" + a + ", " + b + ")";
                _NewTile.transform.parent     = MapHolder.transform;
                _NewTile.transform.position   = new Vector3(a * TileScaleFactor, b * TileScaleFactor, 0);
                _NewTile.transform.localScale = new Vector3(0.2f * TileScaleFactor, 0.2f * TileScaleFactor, 1);
                _NewTile.GetComponent <SpriteRenderer>().sprite = Sprite.Create(_NewTexture, new Rect(new Vector2(0, 0), new Vector2(_NewTexture.width, _NewTexture.height)), new Vector2(0.5f, 0.5f), 100f, (uint)0, SpriteMeshType.FullRect);
                Tiles[a, b] = _NewTile;
            }
        }
    }
Ejemplo n.º 4
0
    public void GenerateChunks(GraphicsMap _GraphicsMap)
    {
        int PerfectWidth  = MapWidth - (MapWidth % PixelTileChunkSideLength); //If chunks size does fit into map size, the remainder is ignored.
        int PerfectHeight = MapHeight - (MapHeight % PixelTileChunkSideLength);

        if (PerfectWidth != MapWidth || PerfectHeight != MapHeight)
        {
            print("Warning!! Incorrect chunk size for map size.");
        }

        Chunks = new GameObject[PerfectWidth, PerfectHeight];                                        //Creates 2d gameobject array.

        for (int _MapWidthC = 0; _MapWidthC < PerfectWidth / PixelTileChunkSideLength; _MapWidthC++) //Counts up through each future chunk.
        {
            for (int _MapHeightC = 0; _MapHeightC < PerfectHeight / PixelTileChunkSideLength; _MapHeightC++)
            {
                Texture2D[] TexturesToUse = new Texture2D[PixelTileChunkSideLength * PixelTileChunkSideLength]; //Creates list of textures that will be combined.

                for (int _ChunkX = 0; _ChunkX < PixelTileChunkSideLength; _ChunkX++)                            //Counts through each tile within chunk.
                {
                    for (int _ChunkY = 0; _ChunkY < PixelTileChunkSideLength; _ChunkY++)
                    {
                        //Adds each texture to array using (Y*W)+X
                        TexturesToUse[(_ChunkY * PixelTileChunkSideLength) + _ChunkX] = MapTextures[_GraphicsMap.GraphicsMapMatrix[(_MapWidthC * PixelTileChunkSideLength) + _ChunkX, (_MapHeightC * PixelTileChunkSideLength) + _ChunkY].Type];
                    }
                }

                Texture2D NewTexture = CombineTexturesForTiles(TexturesToUse, PixelTileChunkSideLength, PixelTileChunkSideLength, PixelTileSideLength);                                                                                                                                                                                      //Combines textures using pixel fucntion
                Chunks[_MapWidthC, _MapHeightC]                  = GameObject.Instantiate(DefaultChunk);                                                                                                                                                                                                                                     //Adds new GameObject to array
                Chunks[_MapWidthC, _MapHeightC].name             = "Chunk (" + _MapWidthC + "," + _MapHeightC + ")";                                                                                                                                                                                                                         //Names
                Chunks[_MapWidthC, _MapHeightC].tag              = "Chunk";                                                                                                                                                                                                                                                                  //Tags
                Chunks[_MapWidthC, _MapHeightC].transform.parent = ChunksHolder.transform;                                                                                                                                                                                                                                                   //Sets parent

                Chunks[_MapWidthC, _MapHeightC].transform.position   = new Vector3(_MapWidthC * TileScaleFactor * PixelTileChunkSideLength, _MapHeightC * TileScaleFactor * PixelTileChunkSideLength, 0);                                                                                                                                    //Postion, tile should be one apart
                Chunks[_MapWidthC, _MapHeightC].transform.localScale = new Vector3((float)(decimal.Divide(1, System.Convert.ToDecimal((float)(decimal.Divide(PixelTileSideLength, 100))))) * TileScaleFactor, (float)(decimal.Divide(1, System.Convert.ToDecimal((float)(decimal.Divide(PixelTileSideLength, 100))))) * TileScaleFactor, 1); //If scale was set to one, the actual size would be pixel size over 100, so 1/(pixel size over 100) makes true size. Note: special function used becuase doesn't work with "/".

                Chunks[_MapWidthC, _MapHeightC].GetComponent <SpriteRenderer>().sprite = Sprite.Create(NewTexture, new Rect(0, 0, NewTexture.width, NewTexture.height), Vector2.one * 0f);
                Chunks[_MapWidthC, _MapHeightC].SetActive(true);
            }
        }
        ChunksHolder.transform.localScale = new Vector3(1, 1, 1); //Makes sure scale is set right.
    }