8 [AddComponentMenu(
"TrueSync/Physics/TerrainCollider", 0)]
9 [RequireComponent(typeof(Terrain))]
17 var terrain = GetComponent<Terrain>();
18 var data = terrain.terrainData;
19 int resolusion = data.heightmapResolution;
29 var terrain = GetComponent<Terrain>();
30 var data = terrain.terrainData;
39 var terrain = GetComponent<Terrain>();
40 var data = terrain.terrainData;
41 int resolusion = data.heightmapResolution;
42 var heightsFloat = data.GetHeights(0, 0, resolusion, resolusion);
43 FP[,] heights =
new FP[heightsFloat.GetLength(0), heightsFloat.GetLength(1)];
45 for (
int indexI = 0; indexI < heightsFloat.GetLength(0); indexI++) {
46 for (
int indexJ = 0; indexJ < heightsFloat.GetLength(1); indexJ++) {
47 heights[indexI, indexJ] = heightsFloat[indexI, indexJ];
51 FP verticalScale = data.size.y;
52 for (
int x = 0; x < resolusion; x++) {
53 for (
int z = 0; z < resolusion; z++)
54 heights[x, z] *= verticalScale;
56 for (
int x = 0; x < resolusion - 1; x++) {
57 for (
int z = x; z < resolusion; z++) {
58 FP h1 = heights[x, z];
59 FP h2 = heights[z, x];
65 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.