Пример #1
0
    /// <summary>
    /// Handles assignment of map colours and height modifications using the passed array of generated perlin values
    /// </summary>
    public void GenerateMap()
    {
        //2D array of float values generated within the NoiseGen script and returned here
        float[,] noiseGrid = NoiseGen.GenerateNoise(mapWidth, mapHeight, noiseScale, octaves, persistance, seed, offset);
        Color[] colourMap = new Color[mapWidth * mapHeight];

        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                float currentHeight = noiseGrid[x, y];

                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions[i].height)
                    {
                        colourMap[y * mapWidth + x] = regions[i].colour;
                        break;
                    }
                }
            }
        }

        MapDisplay mapDisplay = FindObjectOfType <MapDisplay>();

        mapDisplay.DrawMesh(MeshGenerator.GenerateTerrainMesh(noiseGrid, meshHeightMultiplier, meshHeightCurve), TextureGenerator.TextureFromColourMap(colourMap, mapWidth, mapHeight));
        terrainObject.AddComponent <MeshCollider>();

        //Calls for the terrain to be populated with environmental objects
        MapObjectGeneration.GenerateObjects(terrainObject, treeParent, rockParent, metalParent, crystalParent, playerBuildingsParent, mapWidth, mapWidth);

        navMeshSurface = terrainObject.GetComponent <NavMeshSurface>();
        navMeshSurface.BuildNavMesh();

        NavMeshHit navHit;
        Vector3    engineerSpawn;
        bool       engineerSpawned = false;
        GameObject spawnedUnit;


        do
        {
            //Selects a random vector3 position within a sphere centering around the transform position of the base core
            engineerSpawn = Random.insideUnitSphere * 50 + GameObject.Find("BaseCore(Clone)").transform.position;

            //Creates a new ray object using this random position and sets it to be above the terrain
            Ray raycast = new Ray(new Vector3(engineerSpawn.x, 180.0f, engineerSpawn.z), Vector3.down);

            //Casts another collider raycast using the ray object
            if (NavMesh.SamplePosition(engineerSpawn, out navHit, 200f, NavMesh.AllAreas))
            {
                engineerSpawn = navHit.position;

                //Then spawns the engineer unit
                spawnedUnit = Instantiate(Resources.Load("PlayerUnits/Engineer"), engineerSpawn, Quaternion.identity, GameObject.Find("UnitParent").transform) as GameObject;
                spawnedUnit.GetComponent <Unit>().SpawnUnit();
                engineerSpawned = true;
            }
        }while (!engineerSpawned);
    }
Пример #2
0
    public void Test()
    {
        //Teeb world geni randomiks

        xOffset = Random.Range(0, 9999);
        yOffset = Random.Range(0, 9999);

        //Teeb kindlaks et mapi laiused oleksid paaritud arvud

        if (width % 2 == 0)
        {
            width += 1;
        }
        if (heigth % 2 == 0)
        {
            heigth += 1;
        }

        //Genereerib noisemapi

        float[,] noiseMap = NoiseGen.GenerateNoise(width, heigth, scale, levels, intensity, opacity, xOffset, yOffset, opacity2);

        //DrawTexture drawScript = GetComponent<DrawTexture>();

        //drawScript.DrawNoise(width,heigth,noiseMap);

        MakeMesh makeMesh = GetComponent <MakeMesh>();

        makeMesh.CreateMesh(width, heigth, noiseMap, heigths, coast, waterLevel, mapRadius, animalSpawnDist);
    }
Пример #3
0
 MapData GenerateMapData(Vector3 center)      //correlates noiseMap with a color
 {
     if (mode is Mode.compute || mode is Mode.radius)
     {
         float[] noiseMap = NoiseGen.GenerateNoise(
             size, seed, scale, octaves, persistence, lacunarity,
             center + offset, noiseGen);
         return(new MapData(noiseMap, color));
     }
     else
     {
         float[,,] noiseMap = NoiseGen.GenerateNoise(
             size, seed, scale, octaves, persistence, lacunarity,
             center + offset);
         return(new MapData(noiseMap, color));
     }
 }