public static void PlaceTrees(Terrain terrain, float xBase, float yBase)
{
int prototypeCount = TerrainInspectorUtil.GetPrototypeCount(terrain.terrainData);
if (((selectedTree != -1) && (selectedTree < prototypeCount)) && TerrainInspectorUtil.PrototypeIsRenderable(terrain.terrainData, selectedTree))
{
int num2 = 0;
TreeInstance instance = new TreeInstance {
position = new Vector3(xBase, 0f, yBase),
color = GetTreeColor(),
lightmapColor = Color.white,
prototypeIndex = selectedTree,
heightScale = GetTreeHeight()
};
instance.widthScale = !lockWidthToHeight ? GetTreeWidth() : instance.heightScale;
instance.rotation = GetTreeRotation();
if (((Event.current.type != EventType.MouseDrag) && (brushSize <= 1f)) || TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, instance.position, instance.prototypeIndex, spacing))
{
terrain.AddTreeInstance(instance);
num2++;
}
Vector3 prototypeExtent = TerrainInspectorUtil.GetPrototypeExtent(terrain.terrainData, selectedTree);
prototypeExtent.y = 0f;
float num3 = brushSize / ((prototypeExtent.magnitude * spacing) * 0.5f);
int num4 = (int) ((num3 * num3) * 0.5f);
num4 = Mathf.Clamp(num4, 0, 100);
for (int i = 1; (i < num4) && (num2 < num4); i++)
{
Vector2 insideUnitCircle = Random.insideUnitCircle;
insideUnitCircle.x *= brushSize / terrain.terrainData.size.x;
insideUnitCircle.y *= brushSize / terrain.terrainData.size.z;
Vector3 position = new Vector3(xBase + insideUnitCircle.x, 0f, yBase + insideUnitCircle.y);
if ((((position.x >= 0f) && (position.x <= 1f)) && ((position.z >= 0f) && (position.z <= 1f))) && TerrainInspectorUtil.CheckTreeDistance(terrain.terrainData, position, selectedTree, spacing * 0.5f))
{
instance = new TreeInstance {
position = position,
color = GetTreeColor(),
lightmapColor = Color.white,
prototypeIndex = selectedTree,
heightScale = GetTreeHeight()
};
instance.widthScale = !lockWidthToHeight ? GetTreeWidth() : instance.heightScale;
instance.rotation = GetTreeRotation();
terrain.AddTreeInstance(instance);
num2++;
}
}
}
}