Пример #1
0
        // Start is called just before any of the Update methods is called the first time
        public void Start( )
        {
            // 初始化栅格
            Rect border = new Rect(Vector2.zero, mapSize);

            _squareSize = border.size.x / m;
            n           = (uint)(border.size.y / _squareSize);
            _raster     = new Raster(border, m, 0.5f);

            float minSize = Mathf.Min(mapSize.x, mapSize.y) * 0.48f;

            radius           = Mathf.Min(minSize, radius);
            normalizedRadius = radius / minSize;

            // 默认整个栅格的中心
            _centerIndex = new RasterIndex(m / 2, n / 2);
            _centerPoint = _raster.GetSquareCenter(_centerIndex);

            _setElevationMethods = new Dictionary <byte, SetElevationDelegate>();
            _setElevationMethods.Add((byte)ElevationType.kFlat, _FlatElevation);
            _setElevationMethods.Add((byte)ElevationType.kRise, _LandRiseElevation);

            _setIsIslandMethods = new Dictionary <byte, SetIsIslandDelegate>();
            _setIsIslandMethods.Add((byte)IslandType.kCircle, _IsInsideCircleIsland);
            _setIsIslandMethods.Add((byte)IslandType.kPerlin, _IsInsidePerlinIsland);

            float maxHeight = 0;

            if (islandType == IslandType.kCircle)
            {
                _noise1D = new PerlinNoise1D(ampl: 100, count: 8, freq: 10);
                _SetCoastPoint();
                maxHeight = _setElevationMethods[(byte)elevationType]();
                _SetHeight(terrain.terrainData, maxHeight);
            }
            else if (islandType == IslandType.kPerlin)
            {
                _noise2D = new PerlinNoise2D((uint)mapSize.x, (uint)mapSize.y);
                _SetCoastPoint();
                maxHeight = _setElevationMethods[(byte)elevationType]();
                _SetHeight(terrain.terrainData, maxHeight);
            }

            //Test();
        }
Пример #2
0
        // Start is called just before any of the Update methods is called the first time
        public void Start( )
        {
            // 初始化栅格
            Rect border = new Rect(Vector2.zero, mapSize);
            _squareSize = border.size.x / m;
            n = (uint)(border.size.y / _squareSize);
            _raster = new Raster(border, m, 0.5f);

            float minSize = Mathf.Min(mapSize.x, mapSize.y) * 0.48f;
            radius = Mathf.Min(minSize, radius);
            normalizedRadius = radius / minSize;

            // 默认整个栅格的中心
            _centerIndex = new RasterIndex(m / 2, n / 2);
            _centerPoint = _raster.GetSquareCenter(_centerIndex);

            _setElevationMethods = new Dictionary<byte, SetElevationDelegate>();
            _setElevationMethods.Add((byte)ElevationType.kFlat, _FlatElevation);
            _setElevationMethods.Add((byte)ElevationType.kRise, _LandRiseElevation);

            _setIsIslandMethods = new Dictionary<byte, SetIsIslandDelegate>();
            _setIsIslandMethods.Add((byte)IslandType.kCircle, _IsInsideCircleIsland);
            _setIsIslandMethods.Add((byte)IslandType.kPerlin, _IsInsidePerlinIsland);

            float maxHeight = 0;

            if (islandType == IslandType.kCircle)
            {
                _noise1D = new PerlinNoise1D(ampl: 100, count: 8, freq: 10);
                _SetCoastPoint();
                maxHeight = _setElevationMethods[(byte)elevationType]();
                _SetHeight(terrain.terrainData, maxHeight);
            }
            else if (islandType == IslandType.kPerlin)
            {
                _noise2D = new PerlinNoise2D((uint)mapSize.x, (uint)mapSize.y);
                _SetCoastPoint();
                maxHeight = _setElevationMethods[(byte)elevationType]();
                _SetHeight(terrain.terrainData, maxHeight);
            }

            //Test();
        }