Beispiel #1
0
        /// <summary>
        /// Spawn a tile at the correct position
        /// </summary>
        /// <param name="x">Postition on x</param>
        /// <param name="y">Position on y</param>
        /// <param name="z">Postion on z</param>
        /// <param name="pixelColor">Pixel color of the tile to spawn</param>
        /// <param name="mapping">Mapping to know wich prefab to spawn</param>
        private void GenerateTile(int x, int y, int z, Color pixelColor, ColorMappings mapping)
        {
            GameObject prefab   = mapping.GetPrefabFromColor(pixelColor);
            Vector2    position = new Vector3(x, y, z);

            Instantiate(prefab, position, Quaternion.identity, transform);
        }
Beispiel #2
0
        /// <summary>
        /// Generate one layer for the level
        /// </summary>
        /// <param name="map">Map of the level to generate</param>
        /// <param name="mapping">Mapping associated to the level</param>
        /// <param name="center">Center of the level</param>
        /// <param name="z">Depth of the layer</param>
        private void GenerateLayer(Texture2D map, ColorMappings mapping, Vector2 center, int z)
        {
            for (int x = 0; x < map.width; x++)
            {
                for (int y = 0; y < map.height; y++)
                {
                    Color pixelColor = map.GetPixel(x, y);

                    //If pixel is transparent, ignore it
                    if (pixelColor.a != 0)
                    {
                        GenerateTile((int)center.x + x, (int)center.y + y, z, pixelColor, mapping);
                    }
                }
            }
        }