9 [AddComponentMenu(
"TrueSync/Physics/TerrainCollider", 0)]
10 [RequireComponent(typeof(Terrain))]
18 var terrain = GetComponent<Terrain>();
19 var data = terrain.terrainData;
20 int resolusion = data.heightmapResolution;
30 var terrain = GetComponent<Terrain>();
31 var data = terrain.terrainData;
40 var terrain = GetComponent<Terrain>();
41 var data = terrain.terrainData;
42 int resolusion = data.heightmapResolution;
43 var heightsFloat = data.GetHeights(0, 0, resolusion, resolusion);
44 FP[,] heights =
new FP[heightsFloat.GetLength(0), heightsFloat.GetLength(1)];
46 for (
int indexI = 0; indexI < heightsFloat.GetLength(0); indexI++) {
47 for (
int indexJ = 0; indexJ < heightsFloat.GetLength(1); indexJ++) {
48 heights[indexI, indexJ] = heightsFloat[indexI, indexJ];
52 FP verticalScale = data.size.y;
53 for (
int x = 0; x < resolusion; x++) {
54 for (
int z = 0; z < resolusion; z++)
55 heights[x, z] *= verticalScale;
57 for (
int x = 0; x < resolusion - 1; x++) {
58 for (
int z = x; z < resolusion; z++) {
59 FP h1 = heights[x, z];
60 FP h2 = heights[z, x];
66 var result =
new TerrainShape(heights, data.size.x / (resolusion - 1), data.size.z / (resolusion - 1));
Shape Shape
Shape used by a collider.
Collider with a terrain shape.
override void DrawGizmos()
Draws the specific gizmos of concrete collider (for example "Gizmos.DrawWireCube" for a TSBoxCollider...
Abstract collider for 3D shapes.
override Shape CreateShape()
Creates a terrain shape based on a Terrain component attached.
override Vector3 GetGizmosSize()
Returns the gizmos size.
Vector3 Size
Terrain's size.
int Resolution
Terrain's resolution.