Esempio n. 1
0
        // build a layer on top of the given source
        public void BuildHeightMap( IHeightMap2D source, float deltaHeight )
        {
            // copy the source x pos and width
            heightMap.X = source.X;
            heightMap.Width = source.Width;

            int len = source.Heights.Length;

            // copy the heights adding the deltaheight to create a difference
            heightMap.heights = new Vector2[len];

            for ( int i = 0; i < len; ++i )
            {
                heightMap.heights[ i ] = new Vector2( source.Heights[ i ].x, source.Heights[ i ].y + deltaHeight );
            }

            // build a physics collider stopping any rigidbody trying to pass it. Unless it's not...
            // For whatever reason. Then it falls straight through.
            if ( buildCollider )
            {
                EdgeCollider2D topCollider = GetComponent<EdgeCollider2D>();

                if ( topCollider == null )
                {
                    topCollider = gameObject.AddComponent<EdgeCollider2D>();
                }

                topCollider.points = heightMap.heights;
            }

            heightMap.BuildHeightMap( GetComponent<MeshFilter>(), source.Heights, offset );

            // mark that a heightmap has been made
            _hasBuildHeightMap = true;
            _heightMapHash = heightMap.heights.GetHashCode();
            _groundGenerationObjectHash = source.Heights.GetHashCode();
        }
 public void AddHeightMap( IHeightMap2D heightmap )
 {
     _heightmaps.Add( heightmap );
 }