コード例 #1
0
        public static void CreateVoxelTerrain()
        {
            GameObject terrainGo = new GameObject();

            terrainGo.name = newTerrainName;
            terrainGo.transform.position = new Vector3(0, 0, 0);
            MarchingCubesTerrain terrain = terrainGo.AddComponent <MarchingCubesTerrain>();

            EditorUtility.SetDirty(terrain.gameObject);
            terrain.AddChunk(new Vector3Int(0, 0, 0));

            Selection.activeObject = terrainGo;

            terrain.Generate();
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            selectedOption = GUILayout.Toolbar(selectedOption, textures, GUILayout.Width(40 * textures.Length), GUILayout.Height(40));

            if (selectedOption == TOOLS_MESH_ID)
            {
                //mesh tools
                mct.surfaceLevel = EditorGUILayout.Slider("Surface Level", mct.surfaceLevel, 0, 1);
                if (prevSurfLevel != mct.surfaceLevel)
                {
                    prevSurfLevel = mct.surfaceLevel;
                    mct.Generate();
                }
                mct.density = EditorGUILayout.Slider("Density", mct.density, 1, mct.density + 1);

                //brush Tools
                selectedBrush = (BrushType)EditorGUILayout.EnumPopup("Brush Type", selectedBrush);
                if (selectedBrush == BrushType.color)
                {
                    brushColor = EditorGUILayout.ColorField("Brush Color", brushColor);
                }
                brushSize     = EditorGUILayout.FloatField("Brush Size", brushSize);
                brushDistance = EditorGUILayout.FloatField("Brush Distance", brushDistance);
                brushOpacity  = EditorGUILayout.FloatField("Brush Opacity", brushOpacity);

                generateWhileEditing = EditorGUILayout.Toggle("Generate Mesh while editing", generateWhileEditing);

                //mesh buttons
                if (GUILayout.Button("Generate Mesh"))
                {
                    mct.Generate();
                }
                if (GUILayout.Button("Clear Mesh"))
                {
                    mct.ClearMesh();
                }
            }
            else if (selectedOption == TOOLS_FOLIAGE_ID)
            {
                //Foliage tools
                currFoliageObj = (GameObject)EditorGUILayout.ObjectField("", currFoliageObj, typeof(GameObject));
                randomRotation = GUILayout.Toggle(randomRotation, "random rotation");
            }
            else if (selectedOption == TOOLS_CHUNK_ID)
            {
                //chunk tools
                addChunkPosition = EditorGUILayout.Vector3IntField("add chunk position", addChunkPosition);
                if (GUILayout.Button("Add Chunk"))
                {
                    mct.AddChunk(addChunkPosition);
                }
                if (GUILayout.Button("Remove Chunk"))
                {
                    mct.EradicateChunk(addChunkPosition);
                }
            }
            else if (selectedOption == TOOLS_SAVELOAD_ID)
            {
                //save load
                mct.saveFile = EditorGUILayout.TextField("File path", mct.saveFile);
                if (GUILayout.Button("Save"))
                {
                    mct.Save(mct.saveFile);
                }
                if (GUILayout.Button("Load"))
                {
                    mct.Load(mct.saveFile);
                }
            }
            else if (selectedOption == TOOLS_SETTINGS_ID)
            {
                //terrain settings
                drawDebugField = EditorGUILayout.Toggle("Draw Debug points", drawDebugField);
                if (drawDebugField != prevDrawDebugField)
                {
                    EditorWindow.GetWindow <SceneView>().Repaint();
                    prevDrawDebugField = drawDebugField;
                }
            }
        }