Inheritance: NetworkBehaviour
    //Generate terrain and any settings set by it
    private void generateTerrain()
    {
        //Class for terrain settings object
        CreateTerrain createTerrain = new CreateTerrain();

        //Create the terrain in world
        GameObject generatedTerrain = Terrain.CreateTerrainGameObject(createTerrain.generateTerrain(terrainSettings));

        //Check if water has enabled, if so create it in scene
        if (waterEnabled == true)
        {
            try
            {
                //Create a game object callled water from resources
                GameObject water = GameObject.Instantiate(Resources.Load("Water") as GameObject);
                water.transform.localScale    = new Vector3(terrainSettings.Height * 2, 1, terrainSettings.Width * 2);
                water.transform.localPosition = new Vector3(0, 30, 0);
            }
            catch (Exception exception)
            {
                Debug.Log("Water needs to be added as a game object within resource folder before being generated");
                throw new ApplicationException("Terrain Generator has failed with the folloing exception : \n : ", exception);
            }
        }
    }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        CreateTerrain myScript = (CreateTerrain)target;

        if (GUILayout.Button("generate perlin"))
        {
            myScript.generatePerlin();
        }
    }
Exemplo n.º 3
0
    void Start()
    {
        script1 = (CreateTerrain)face1.GetComponent(typeof(CreateTerrain));
        script2 = (CreateTerrain)face2.GetComponent(typeof(CreateTerrain));
        script3 = (CreateTerrain)face3.GetComponent(typeof(CreateTerrain));
        script4 = (CreateTerrain)face4.GetComponent(typeof(CreateTerrain));
        script5 = (CreateTerrain)face5.GetComponent(typeof(CreateTerrain));
        script6 = (CreateTerrain)face6.GetComponent(typeof(CreateTerrain));
        Mesh mesh = GetComponent <MeshFilter>().mesh;

        mesh.Clear();
    }
Exemplo n.º 4
0
    /// <summary>
    /// Editor script for the CreateSmoothTerrain script, incase you want to generate a terrain outside runtime.
    /// </summary>
    public override void OnInspectorGUI()
    {
        CreateTerrain terrainGen = (CreateTerrain)target;

        if (GUILayout.Button("generate"))
        {
            terrainGen.Generate();
        }
        if (DrawDefaultInspector())
        {
        }
        if (GUILayout.Button("generate"))
        {
            terrainGen.Generate();
        }
    }
Exemplo n.º 5
0
 void Awake()
 {
     mapCreator  = GetComponent <CreateGolfTerrain>();
     terrMaker   = GetComponent <CreateTerrain>();
     terrPainter = GetComponent <TextureTerrainScript>();
 }
    void OnGUI()
    {
        GUILayout.Label("User Defined Generation", EditorStyles.centeredGreyMiniLabel);

        GUILayout.Label("Current Generation : " + generation, EditorStyles.centeredGreyMiniLabel);

        GUILayout.Label("Showing terrain " + terrainNumber + " / " + population.Count, EditorStyles.centeredGreyMiniLabel);

        GUILayout.Label("Parent's selected " + parents.Count + "(Minimal of 2)", EditorStyles.centeredGreyMiniLabel);

        if (GUILayout.Button("Approve"))
        {
            parents.Add(population[terrainNumber - 1]);

            terrainNumber = terrainNumber + 1;
            DestroyImmediate(GameObject.Find("Terrain"));
        }

        if (GUILayout.Button("Decline"))
        {
            DestroyImmediate(GameObject.Find("Terrain"));
            terrainNumber = terrainNumber + 1;
        }

        //This button causes the complete random generation of a terrain
        if (GUILayout.Button("Optimal Solution"))
        {
            this.Close();
        }

        //This button causes the complete random generation of a terrain
        if (GUILayout.Button("Cancel Generation"))
        {
            DestroyImmediate(GameObject.Find("Terrain"));
            this.Close();
        }

        if (evoType == "start")
        {
            try
            {
                Debug.Log("User defined terrain generation started");

                EvoGeneration evoGeneration = new EvoGeneration();

                population = evoGeneration.createPopulation(populationToCreate, worldSize);

                terrainNumber = 1;

                generation = 1;

                evoType = "next_gen";
            }

            catch (Exception exception)
            {
                this.Close();
                throw new ApplicationException("Terrain Generator has failed with the folloing exception : \n : ", exception);
            }
        }
        else if (evoType == "next_gen")
        {
            if (population.Count < terrainNumber)
            {
                population.Clear();

                generation = generation + 1;

                DestroyImmediate(GameObject.Find("Terrain"));

                GUILayout.Label("Showing terrain " + terrainNumber + " / " + population.Count, EditorStyles.centeredGreyMiniLabel);
                if (parents.Count < 2)
                {
                    Debug.LogError("At least 2 parents must be selected from the population, please run the tool again.");
                    if (GameObject.Find("Terrain") != null)
                    {
                        DestroyImmediate(GameObject.Find("Terrain"));
                        this.Close();
                    }
                }

                EvoGeneration evoGeneration = new EvoGeneration();

                population = evoGeneration.newGeneration(parents, populationToCreate, worldSize);

                parents.Clear();

                terrainNumber = 1;
            }

            else
            {
                if (GameObject.Find("Terrain") != null)
                {
                }
                else
                {
                    CreateTerrain createTerrain    = new CreateTerrain();
                    GameObject    generatedTerrain = Terrain.CreateTerrainGameObject(createTerrain.generateTerrain(population[terrainNumber - 1]));
                }
            }
        }
        else
        {
            this.Close();
        }
    }