Пример #1
0
        private void SetupTerrain()
        {
            int mapWidth  = PropertiesManager.Properties.TerrainDetailFactor;
            int mapHeight = (int)(PropertiesManager.Properties.TerrainDetailFactor * (float)Arena.Surface.Height / Arena.Surface.Width);

            for (int y = 0; y < mapHeight; y++)
            {
                for (int x = 0; x < mapWidth; x++)
                {
                    int   maskX       = x * TerrainMask.Width / mapWidth;
                    int   maskY       = y * TerrainMask.Height / mapHeight;
                    Color pixelColour = TerrainMask.GetPixel(maskX, maskY);
                    if (!(pixelColour.B >= 128 && pixelColour.G >= 128 && pixelColour.R >= 128))
                    {
                        int arenaX1 = x * Arena.Surface.Width / mapWidth;
                        int arenaX2 = (x + 1) * Arena.Surface.Width / mapWidth;
                        int arenaY1 = y * Arena.Surface.Height / mapHeight;
                        int arenaY2 = (y + 1) * Arena.Surface.Height / mapHeight;
                        Arena.AddTerrain(arenaX1, arenaX2, arenaY1, arenaY2);
                    }
                }
            }
        }
    void Start()
    {
        // Check to make sure a TerrainGenerator and TerrainMask are assigned, and if not try to assign one
        if (terrainGenerator == null)
        {
            terrainGenerator = GetComponentInChildren <TerrainGenerator> ();
            if (terrainGenerator == null)
            {
                Debug.LogError("TerrainManager: No TerrainGenerator found!");
                this.enabled = false;
            }
        }

        if (terrainMask == null)
        {
            terrainMask = GetComponentInChildren <TerrainMask> ();
            if (terrainMask == null)
            {
                Debug.LogError("TerrainManager: No TerrainMask found!");
                this.enabled = false;
            }
        }
    }