-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGridBrush2.cs
49 lines (42 loc) · 1.58 KB
/
GridBrush2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class GridBrush2 : InstanceBrush
{
public int spacing = 20;
public new int radius = 20;
public int idx = 0;
private TreeInstance[] trees;
private float terrainHeight;
private float terrainWidth;
private bool isOccupied;
public override void draw(float x, float z) {
int test_x;
int test_z;
float test_radius;
trees = terrain.terrain_data.treeInstances;
terrainWidth = terrain.terrain_data.heightmapResolution;
terrainHeight = terrain.terrain_data.heightmapResolution;
for (int zi = -radius; zi <= radius; zi++) {
for (int xi = -radius; xi <= radius; xi++) {
test_x = (int) x + xi;
test_z = (int) z + zi;
isOccupied = false;
test_radius = spacing/3;
if (test_x % spacing == 0) {
if (test_z % spacing == 0){
for (int i=0; i<trees.Length; i++){
if ((Math.Abs(trees[i].position.x * terrainWidth - (x+xi)) < test_radius) & (Math.Abs(trees[i].position.z * terrainHeight - (z+zi)) < test_radius)){
isOccupied = true;
}
}
if (!isOccupied){
mySpawnObject(x+xi, z+zi, 3f, idx);
}
}
}
}
}
}
}