예제 #1
0
    //------------------------------------------------------------------

    private void CalculateCenterHeightmapColors2D()
    {
        _previewTextureUpdateInProgress = true;

        float   x, y, z;
        Vector3 point;

        EasyTerrain.TerrainSample terrainSample;

        float nTiles        = _nTiles;
        float tileSize      = _tileSize;
        float tileMaxHeight = _tileMaxHeight;

        for (int i = 0; i < _previewTexturePixelSize; i++)
        {
            for (int j = 0; j < _previewTexturePixelSize; j++)
            {
                x                           = nTiles * tileSize * (((float)i / (float)(_previewTexturePixelSize - 1)) - 0.5f);
                y                           = 0f;
                z                           = nTiles * tileSize * (((float)j / (float)(_previewTexturePixelSize - 1)) - 0.5f);
                point                       = new Vector3(x, y, z);
                terrainSample               = EasyTerrain.GetTerrainSample(point);
                terrainSample.height       /= tileMaxHeight;
                _previewTextureColors[i, j] = new Color(terrainSample.height, terrainSample.height, terrainSample.height);
            }
        }

        _previewTextureUpdateInProgress = false;
    }
    //------------------------------------------------------------------

    private bool GUI_Enabled()
    {
        bool tileUpdateInProgress = (EasyTerrain.GetUpdateStatusPercentage() < 100) ? true : false;

        GUI.enabled = !tileUpdateInProgress && !Application.isPlaying && (serializedObject.FindProperty("player").objectReferenceValue != null);
        return(GUI.enabled);
    }
예제 #3
0
 void Update()
 {
     if (Input.GetKeyDown(key))
     {
         EasyTerrain.DetachTreesFromTerrain(transform.position, radius);
     }
 }
예제 #4
0
    //------------------------------------------------------------------

    private void CalculateCenterGrassmapColors2D()
    {
        _previewTextureUpdateInProgress = true;

        float   x, y, z;
        Vector3 point;

        EasyTerrain.TerrainSample terrainSample;

        float nTiles        = _nTiles;
        float tileSize      = _tileSize;
        float tileMaxHeight = _tileMaxHeight;

        for (int i = 0; i < _previewTexturePixelSize; i++)
        {
            for (int j = 0; j < _previewTexturePixelSize; j++)
            {
                x                           = nTiles * tileSize * (((float)i / (float)(_previewTexturePixelSize - 1)) - 0.5f);
                y                           = 0f;
                z                           = nTiles * tileSize * (((float)j / (float)(_previewTexturePixelSize - 1)) - 0.5f);
                point                       = new Vector3(x, y, z);
                terrainSample               = EasyTerrain.GetTerrainSample(point);
                terrainSample.height       /= tileMaxHeight;
                _previewTextureColors[i, j] = Color.black;

                Color clr = Color.green;
                for (int index = 0; index < _splatmapPreviewBlendCurves.Length; index++)
                {
                    if (_applyToSplatTexture[index])
                    {
                        if (_splatmapPreviewBlendColors[index] != Color.white)
                        {
                            _previewTextureColors[i, j] += clr * _splatmapPreviewBlendCurves[index].Evaluate(terrainSample.height);
                        }
                        else
                        {
                            _previewTextureColors[i, j] += clr * _splatmapPreviewBlendCurves[index].Evaluate(terrainSample.steepness);
                        }
                    }
                }
            }
        }

        _previewTextureUpdateInProgress = false;
    }
예제 #5
0
    //------------------------------------------------------------------

    private void CalculateGameObjectsMapColors2D()
    {
        _previewTextureUpdateInProgress = true;

        float   x, y, z;
        Vector3 point;

        EasyTerrain.TerrainSample terrainSample;

        float nTiles        = _nTiles;
        float tileSize      = _tileSize;
        float tileMaxHeight = _tileMaxHeight;

        for (int i = 0; i < _previewTexturePixelSize; i++)
        {
            for (int j = 0; j < _previewTexturePixelSize; j++)
            {
                x                           = nTiles * tileSize * (((float)i / (float)(_previewTexturePixelSize - 1)) - 0.5f);
                y                           = 0f;
                z                           = nTiles * tileSize * (((float)j / (float)(_previewTexturePixelSize - 1)) - 0.5f);
                point                       = new Vector3(x, y, z);
                terrainSample               = EasyTerrain.GetTerrainSample(point);
                terrainSample.height       /= tileMaxHeight;
                _previewTextureColors[i, j] = Color.black;
                float noiseValue;
                Color clr = Color.green;

                for (int index = 0; index < _splatmapPreviewBlendCurves.Length; index++)
                {
                    if (_applyToSplatTexture[index])
                    {
                        if (_splatmapPreviewBlendColors[index] != Color.white)
                        {
                            _previewTextureColors[i, j] += clr * _splatmapPreviewBlendCurves[index].Evaluate(terrainSample.height);
                        }
                        else
                        {
                            _previewTextureColors[i, j] += clr * _splatmapPreviewBlendCurves[index].Evaluate(terrainSample.steepness);
                        }
                    }
                }

                if (_useNoiseLayer)
                {
                    point.x -= _noiseOffsetX;
                    point.y  = _noiseOffsetY;
                    point.z -= _noiseOffsetZ;

                    NoiseGenerator.NoiseSample noiseSample;
                    noiseSample = NoiseGenerator.Sum(
                        NoiseGenerator.methods[(int)NoiseGenerator.NoiseMethodType.Perlin3D],
                        point, _noiseFrequency, 1, 1f, 1f);
                    noiseValue = noiseSample.value;
                    noiseValue = (noiseValue + 1f) * 0.5f;

                    AnimationCurve animc = new AnimationCurve(
                        new Keyframe(0f, 0f, 0f, 0f),
                        new Keyframe(_threshold, 0f, 0f, 0f),
                        new Keyframe(Mathf.Lerp(_threshold, 1f, _falloff), 1f, 0f, 0f),
                        new Keyframe(1f, 1f, 0f, 0f));

                    _previewTextureColors[i, j] *= animc.Evaluate(noiseValue);
                }
            }
        }

        _previewTextureUpdateInProgress = false;
    }
    //------------------------------------------------------------------

    void UpdateButtons()
    {
        EditorGUILayout.BeginVertical("Box");
        {
            EditorGUILayout.Space();

            SerializedProperty tileList = serializedObject.FindProperty("tileList");
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.BeginVertical();
                {
                    {
                        //GUI_Enabled();

                        string buttonText = (tileList.arraySize == 0) ? "Create Terrain" : "Update Terrain";
                        if (deleteButtonEnabled)
                        {
                            buttonText = "Delete Terrain";
                        }

                        bool tileUpdateInProgress = (EasyTerrain.GetUpdateStatusPercentage() < 100) ? true : false;
                        if (tileUpdateInProgress)
                        {
                            buttonText = "Stop";
                        }

                        if (GUILayout.Button(buttonText, GUILayout.Width(EditorGUIUtility.currentViewWidth - 100)))
                        {
                            if (!tileUpdateInProgress)
                            {
                                if (!deleteButtonEnabled)
                                {
                                    script.GenerateTerrainTiles();
                                }
                                else
                                {
                                    script.DeleteTerrainTiles();
                                    deleteButtonEnabled = false;
                                }
                            }
                            else
                            {
                                script.StopUpdate();
                            }
                        }
                        GUI.enabled = true;
                    }
                    {
                        string updateStatusPercentageString = "" + Mathf.Round(EasyTerrain.GetUpdateStatusPercentage()) + "%";
                        EditorGUILayout.LabelField("", GUILayout.Width(EditorGUIUtility.currentViewWidth - 100));
                        EditorGUI.ProgressBar(GUILayoutUtility.GetLastRect(), EasyTerrain.GetUpdateStatusPercentage() * 0.01f, updateStatusPercentageString);
                    }
                }
                GUILayout.EndVertical();

                EditorGUILayout.BeginVertical();
                {
                    {
                        GUI_Enabled();
                        deleteButtonEnabled = GUILayout.Toggle(deleteButtonEnabled, "delete", GUILayout.Width(60));
                        GUI.enabled         = true;
                    }
                    {
                        string progressSecondsString = "(" + EasyTerrain.GetStopwatchElapsedSeconds().ToString("F") + " s)";
                        EditorGUILayout.LabelField(progressSecondsString, GUILayout.Width(60));
                    }
                }
                GUILayout.EndVertical();
            }
            EditorGUILayout.EndHorizontal();

            //TileList ();

            EditorGUILayout.Space();
        }
        GUILayout.EndVertical();
    }