Пример #1
0
    public static GenerationController CreateGenerationController()
    {
        GameObject           camObj = new GameObject("GenerationController");
        GenerationController camCon = camObj.AddComponent <GenerationController>();

        TerrainGenerator terGen = TerrainGenerationEditor.CreateTerrainGenerator();

        camCon.terrainGenerator = terGen;
        terGen.gameObject.transform.SetParent(camObj.transform);

        Selection.activeGameObject = camObj;
        return(camCon);
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();
        EditorGUILayout.PropertyField(_seed);
        EditorGUILayout.PropertyField(_terrainGen);
        if (!controller.terrainGenerator.CanGenerate())
        {
            TerrainGenerationEditor terEditor = (TerrainGenerationEditor)CreateEditor(controller.terrainGenerator);
            terEditor.ShowMissingGenRequirements();
        }

        EditorGUILayout.PropertyField(_cityGen);
        if (controller.cityGenerator == null)
        {
            cityGenTab = GUILayout.Toolbar(cityGenTab, cityGenNames);
            switch (cityGenTab)
            {
            case 1:
                CityBiomeGenerator gen = CityBiomeGeneratorEditor.CreateRecursiveDetailGenerator(controller);
                // CreateCityGenerator<CityBiomeGenerator>();
                //gen.terrain = controller.terrainGenerator.terrain;
                break;

            case 2:

                PerlinCityGenerator pGen = PerlinCityGeneratorEditor.CreatePerlinCityGenerator(controller);
                //pGen.terrainGenerator = controller.terrainGenerator;
                break;

            case 3:
                LSystemGeneration lGen = CreateCityGenerator <LSystemGeneration>();
                lGen.terrainGenerator = controller.terrainGenerator;
                break;
            }
        }
        else if (!controller.cityGenerator.CanGenerate())
        {
            GeneratorEditor cityEditor = (GeneratorEditor)CreateEditor(controller.cityGenerator);
            cityEditor.ShowMissingGenRequirements();
        }
        else if (controller.terrainGenerator.CanGenerate())
        {
            if (GUILayout.Button("Generate"))
            {
                controller.SetupAndGenerate();
            }
            if (GUILayout.Button("Clear Buildings"))
            {
                while (controller.cityGenerator.transform.childCount > 0)
                {
                    Transform child = controller.cityGenerator.transform.GetChild(0);
                    DestroyImmediate(child.gameObject);
                }
                if (controller.cityGenerator is LSystemGeneration)
                {
                    ((LSystemGeneration)controller.cityGenerator).clearBuildings();
                }
            }
        }
        serializedObject.ApplyModifiedProperties();

        /*
         * if (GUILayout.Button("Save Heightmap"))
         * {
         *  Texture2D tex = controller.terrainGenerator.biomeTexture;
         *  string fileName = Application.persistentDataPath + "/" + tex.name + ".png";
         *  File.WriteAllBytes(fileName, tex.EncodeToPNG());
         *  Debug.Log("Saved to " + fileName);
         * }
         */
    }