UnityEditor.ExportRawHeightmap.WriteRaw C# (CSharp) Method

WriteRaw() private method

private WriteRaw ( string path ) : void
path string
return void
        private void WriteRaw(string path)
        {
            int heightmapWidth = base.terrainData.heightmapWidth;
            int heightmapHeight = base.terrainData.heightmapHeight;
            float[,] numArray = base.terrainData.GetHeights(0, 0, heightmapWidth, heightmapHeight);
            byte[] array = new byte[(heightmapWidth * heightmapHeight) * this.m_Depth];
            if (this.m_Depth == Depth.Bit16)
            {
                float num3 = 65536f;
                for (int i = 0; i < heightmapHeight; i++)
                {
                    for (int j = 0; j < heightmapWidth; j++)
                    {
                        int num6 = j + (i * heightmapWidth);
                        int num7 = !this.m_FlipVertically ? i : ((heightmapHeight - 1) - i);
                        ushort num9 = (ushort) Mathf.Clamp(Mathf.RoundToInt(numArray[num7, j] * num3), 0, 0xffff);
                        byte[] bytes = BitConverter.GetBytes(num9);
                        if ((this.m_ByteOrder == ByteOrder.Mac) == BitConverter.IsLittleEndian)
                        {
                            array[num6 * 2] = bytes[1];
                            array[(num6 * 2) + 1] = bytes[0];
                        }
                        else
                        {
                            array[num6 * 2] = bytes[0];
                            array[(num6 * 2) + 1] = bytes[1];
                        }
                    }
                }
            }
            else
            {
                float num10 = 256f;
                for (int k = 0; k < heightmapHeight; k++)
                {
                    for (int m = 0; m < heightmapWidth; m++)
                    {
                        int index = m + (k * heightmapWidth);
                        int num14 = !this.m_FlipVertically ? k : ((heightmapHeight - 1) - k);
                        array[index] = (byte) Mathf.Clamp(Mathf.RoundToInt(numArray[num14, m] * num10), 0, 0xff);
                    }
                }
            }
            FileStream stream = new FileStream(path, System.IO.FileMode.Create);
            stream.Write(array, 0, array.Length);
            stream.Close();
        }