Пример #1
0
        public static bool getNormal(Vector3 position, out Vector3 normal)
        {
            LandscapeCoord coord = new LandscapeCoord(position);
            LandscapeTile  tile  = Landscape.getTile(coord);

            if (tile != null)
            {
                normal = tile.data.GetInterpolatedNormal((position.x - (float)coord.x * Landscape.TILE_SIZE) / Landscape.TILE_SIZE, (position.z - (float)coord.y * Landscape.TILE_SIZE) / Landscape.TILE_SIZE);
                return(true);
            }
            normal = Vector3.up;
            return(false);
        }
Пример #2
0
        // Token: 0x06000DEF RID: 3567 RVA: 0x00061B04 File Offset: 0x0005FF04
        public static bool getHeight01(Vector3 position, out float height)
        {
            LandscapeCoord coord = new LandscapeCoord(position);
            LandscapeTile  tile  = Landscape.getTile(coord);

            if (tile != null)
            {
                height = tile.terrain.SampleHeight(position) / Landscape.TILE_HEIGHT;
                return(true);
            }
            height = 0f;
            return(false);
        }
Пример #3
0
        public static bool removeTile(LandscapeCoord coord)
        {
            LandscapeTile landscapeTile;

            if (!Landscape.tiles.TryGetValue(coord, out landscapeTile))
            {
                return(false);
            }
            landscapeTile.disable();
            Object.Destroy(landscapeTile.gameObject);
            Landscape.tiles.Remove(coord);
            return(true);
        }
Пример #4
0
        // Token: 0x06000DFC RID: 3580 RVA: 0x00061E20 File Offset: 0x00060220
        public static Vector3 getWorldPosition(LandscapeCoord tileCoord, SplatmapCoord splatmapCoord)
        {
            float num = (float)tileCoord.x * Landscape.TILE_SIZE + (float)splatmapCoord.y / (float)Landscape.SPLATMAP_RESOLUTION * Landscape.TILE_SIZE;

            num = (float)Mathf.RoundToInt(num) + Landscape.HALF_SPLATMAP_WORLD_UNIT;
            float num2 = (float)tileCoord.y * Landscape.TILE_SIZE + (float)splatmapCoord.x / (float)Landscape.SPLATMAP_RESOLUTION * Landscape.TILE_SIZE;

            num2 = (float)Mathf.RoundToInt(num2) + Landscape.HALF_SPLATMAP_WORLD_UNIT;
            Vector3 vector = new Vector3(num, 0f, num2);
            float   y;

            Landscape.getWorldHeight(vector, out y);
            vector.y = y;
            return(vector);
        }
Пример #5
0
        // Token: 0x06000E06 RID: 3590 RVA: 0x00062A48 File Offset: 0x00060E48
        public static LandscapeTile addTile(LandscapeCoord coord)
        {
            if (Landscape.instance == null)
            {
                return(null);
            }
            if (Landscape.tiles.ContainsKey(coord))
            {
                return(null);
            }
            LandscapeTile landscapeTile = new LandscapeTile(coord);

            landscapeTile.enable();
            landscapeTile.applyGraphicsSettings();
            Landscape.tiles.Add(coord, landscapeTile);
            return(landscapeTile);
        }
Пример #6
0
        // Token: 0x06000E00 RID: 3584 RVA: 0x00062290 File Offset: 0x00060690
        public static void writeSplatmap(Bounds worldBounds, Landscape.LandscapeWriteSplatmapHandler callback)
        {
            if (callback == null)
            {
                return;
            }
            LandscapeBounds landscapeBounds = new LandscapeBounds(worldBounds);

            for (int i = landscapeBounds.min.x; i <= landscapeBounds.max.x; i++)
            {
                for (int j = landscapeBounds.min.y; j <= landscapeBounds.max.y; j++)
                {
                    LandscapeCoord landscapeCoord = new LandscapeCoord(i, j);
                    LandscapeTile  tile           = Landscape.getTile(landscapeCoord);
                    if (tile != null)
                    {
                        if (!Landscape.splatmapTransactions.ContainsKey(landscapeCoord))
                        {
                            LandscapeSplatmapTransaction landscapeSplatmapTransaction = new LandscapeSplatmapTransaction(tile);
                            DevkitTransactionManager.recordTransaction(landscapeSplatmapTransaction);
                            Landscape.splatmapTransactions.Add(landscapeCoord, landscapeSplatmapTransaction);
                        }
                        SplatmapBounds splatmapBounds = new SplatmapBounds(landscapeCoord, worldBounds);
                        for (int k = splatmapBounds.min.x; k <= splatmapBounds.max.x; k++)
                        {
                            for (int l = splatmapBounds.min.y; l <= splatmapBounds.max.y; l++)
                            {
                                SplatmapCoord splatmapCoord = new SplatmapCoord(k, l);
                                for (int m = 0; m < Landscape.SPLATMAP_LAYERS; m++)
                                {
                                    Landscape.SPLATMAP_LAYER_BUFFER[m] = tile.sourceSplatmap[k, l, m];
                                }
                                Vector3 worldPosition = Landscape.getWorldPosition(landscapeCoord, splatmapCoord);
                                callback(landscapeCoord, splatmapCoord, worldPosition, Landscape.SPLATMAP_LAYER_BUFFER);
                                for (int n = 0; n < Landscape.SPLATMAP_LAYERS; n++)
                                {
                                    tile.sourceSplatmap[k, l, n] = Mathf.Clamp01(Landscape.SPLATMAP_LAYER_BUFFER[n]);
                                }
                            }
                        }
                        tile.data.SetAlphamaps(0, 0, tile.sourceSplatmap);
                    }
                }
            }
        }
Пример #7
0
        // Token: 0x06000DFF RID: 3583 RVA: 0x00062118 File Offset: 0x00060518
        public static void writeHeightmap(Bounds worldBounds, Landscape.LandscapeWriteHeightmapHandler callback)
        {
            if (callback == null)
            {
                return;
            }
            LandscapeBounds landscapeBounds = new LandscapeBounds(worldBounds);

            for (int i = landscapeBounds.min.x; i <= landscapeBounds.max.x; i++)
            {
                for (int j = landscapeBounds.min.y; j <= landscapeBounds.max.y; j++)
                {
                    LandscapeCoord landscapeCoord = new LandscapeCoord(i, j);
                    LandscapeTile  tile           = Landscape.getTile(landscapeCoord);
                    if (tile != null)
                    {
                        if (!Landscape.heightmapTransactions.ContainsKey(landscapeCoord))
                        {
                            LandscapeHeightmapTransaction landscapeHeightmapTransaction = new LandscapeHeightmapTransaction(tile);
                            DevkitTransactionManager.recordTransaction(landscapeHeightmapTransaction);
                            Landscape.heightmapTransactions.Add(landscapeCoord, landscapeHeightmapTransaction);
                        }
                        HeightmapBounds heightmapBounds = new HeightmapBounds(landscapeCoord, worldBounds);
                        for (int k = heightmapBounds.min.x; k <= heightmapBounds.max.x; k++)
                        {
                            for (int l = heightmapBounds.min.y; l <= heightmapBounds.max.y; l++)
                            {
                                HeightmapCoord heightmapCoord = new HeightmapCoord(k, l);
                                float          num            = tile.sourceHeightmap[k, l];
                                Vector3        worldPosition  = Landscape.getWorldPosition(landscapeCoord, heightmapCoord, num);
                                tile.sourceHeightmap[k, l] = Mathf.Clamp01(callback(landscapeCoord, heightmapCoord, worldPosition, num));
                            }
                        }
                        tile.data.SetHeightsDelayLOD(0, 0, tile.sourceHeightmap);
                    }
                }
            }
        }
 // Token: 0x06000EA7 RID: 3751 RVA: 0x0006508C File Offset: 0x0006348C
 public static void cleanHeightmapCoord(ref LandscapeCoord tileCoord, ref HeightmapCoord heightmapCoord)
 {
     if (heightmapCoord.x < 0)
     {
         tileCoord.y--;
         heightmapCoord.x += Landscape.HEIGHTMAP_RESOLUTION;
     }
     if (heightmapCoord.y < 0)
     {
         tileCoord.x--;
         heightmapCoord.y += Landscape.HEIGHTMAP_RESOLUTION;
     }
     if (heightmapCoord.x >= Landscape.HEIGHTMAP_RESOLUTION)
     {
         tileCoord.y++;
         heightmapCoord.x -= Landscape.HEIGHTMAP_RESOLUTION;
     }
     if (heightmapCoord.y >= Landscape.HEIGHTMAP_RESOLUTION)
     {
         tileCoord.x++;
         heightmapCoord.y -= Landscape.HEIGHTMAP_RESOLUTION;
     }
 }
 // Token: 0x06000EA8 RID: 3752 RVA: 0x00065154 File Offset: 0x00063554
 public static void cleanSplatmapCoord(ref LandscapeCoord tileCoord, ref SplatmapCoord splatmapCoord)
 {
     if (splatmapCoord.x < 0)
     {
         tileCoord.y--;
         splatmapCoord.x += Landscape.SPLATMAP_RESOLUTION;
     }
     if (splatmapCoord.y < 0)
     {
         tileCoord.x--;
         splatmapCoord.y += Landscape.SPLATMAP_RESOLUTION;
     }
     if (splatmapCoord.x >= Landscape.SPLATMAP_RESOLUTION)
     {
         tileCoord.y++;
         splatmapCoord.x -= Landscape.SPLATMAP_RESOLUTION;
     }
     if (splatmapCoord.y >= Landscape.SPLATMAP_RESOLUTION)
     {
         tileCoord.x++;
         splatmapCoord.y -= Landscape.SPLATMAP_RESOLUTION;
     }
 }
Пример #10
0
        // Token: 0x06000E66 RID: 3686 RVA: 0x00063A64 File Offset: 0x00061E64
        protected void findTerrainColliders()
        {
            this.terrainColliders.Clear();
            Bounds          bounds          = base.box.bounds;
            LandscapeBounds landscapeBounds = new LandscapeBounds(bounds);

            for (int i = landscapeBounds.min.x; i <= landscapeBounds.max.x; i++)
            {
                for (int j = landscapeBounds.min.y; j <= landscapeBounds.max.y; j++)
                {
                    LandscapeCoord coord = new LandscapeCoord(i, j);
                    LandscapeTile  tile  = Landscape.getTile(coord);
                    if (tile != null)
                    {
                        this.terrainColliders.Add(tile.collider);
                    }
                }
            }
            if (LevelGround.terrain != null)
            {
                this.terrainColliders.Add(LevelGround.terrain.transform.GetComponent <TerrainCollider>());
            }
        }
Пример #11
0
 public SplatmapCoord(LandscapeCoord tileCoord, Vector3 worldPosition)
 {
     this.x = Mathf.Clamp(Mathf.FloorToInt((worldPosition.z - (float)tileCoord.y * Landscape.TILE_SIZE) / Landscape.TILE_SIZE * (float)Landscape.SPLATMAP_RESOLUTION), 0, Landscape.SPLATMAP_RESOLUTION_MINUS_ONE);
     this.y = Mathf.Clamp(Mathf.FloorToInt((worldPosition.x - (float)tileCoord.x * Landscape.TILE_SIZE) / Landscape.TILE_SIZE * (float)Landscape.SPLATMAP_RESOLUTION), 0, Landscape.SPLATMAP_RESOLUTION_MINUS_ONE);
 }
Пример #12
0
 // Token: 0x06000DDA RID: 3546 RVA: 0x00061860 File Offset: 0x0005FC60
 public HeightmapCoord(LandscapeCoord tileCoord, Vector3 worldPosition)
 {
     this.x = Mathf.Clamp(Mathf.RoundToInt((worldPosition.z - (float)tileCoord.y * Landscape.TILE_SIZE) / Landscape.TILE_SIZE * (float)Landscape.HEIGHTMAP_RESOLUTION_MINUS_ONE), 0, Landscape.HEIGHTMAP_RESOLUTION_MINUS_ONE);
     this.y = Mathf.Clamp(Mathf.RoundToInt((worldPosition.x - (float)tileCoord.x * Landscape.TILE_SIZE) / Landscape.TILE_SIZE * (float)Landscape.HEIGHTMAP_RESOLUTION_MINUS_ONE), 0, Landscape.HEIGHTMAP_RESOLUTION_MINUS_ONE);
 }
Пример #13
0
 public LandscapeBounds(LandscapeCoord newMin, LandscapeCoord newMax)
 {
     this.min = newMin;
     this.max = newMax;
 }
Пример #14
0
        // Token: 0x06000E09 RID: 3593 RVA: 0x00062B24 File Offset: 0x00060F24
        public static LandscapeTile getTile(Vector3 worldPosition)
        {
            LandscapeCoord coord = new LandscapeCoord(worldPosition);

            return(Landscape.getTile(coord));
        }
Пример #15
0
 public LandscapeTile(LandscapeCoord newCoord)
 {
     this.gameObject                      = new GameObject();
     this.gameObject.name                 = "Tile";
     this.gameObject.tag                  = "Ground";
     this.gameObject.layer                = LayerMasks.GROUND;
     this.gameObject.transform.parent     = Landscape.instance.transform;
     this.gameObject.transform.rotation   = MathUtility.IDENTITY_QUATERNION;
     this.gameObject.transform.localScale = Vector3.one;
     this.coord           = newCoord;
     this.sourceHeightmap = new float[Landscape.HEIGHTMAP_RESOLUTION, Landscape.HEIGHTMAP_RESOLUTION];
     this.sourceSplatmap  = new float[Landscape.SPLATMAP_RESOLUTION, Landscape.SPLATMAP_RESOLUTION, Landscape.SPLATMAP_LAYERS];
     for (int i = 0; i < Landscape.HEIGHTMAP_RESOLUTION; i++)
     {
         for (int j = 0; j < Landscape.HEIGHTMAP_RESOLUTION; j++)
         {
             this.sourceHeightmap[i, j] = 0.5f;
         }
     }
     for (int k = 0; k < Landscape.SPLATMAP_RESOLUTION; k++)
     {
         for (int l = 0; l < Landscape.SPLATMAP_RESOLUTION; l++)
         {
             this.sourceSplatmap[k, l, 0] = 1f;
         }
     }
     this.materials = new InspectableList <AssetReference <LandscapeMaterialAsset> >(Landscape.SPLATMAP_LAYERS);
     for (int m = 0; m < Landscape.SPLATMAP_LAYERS; m++)
     {
         this.materials.Add(AssetReference <LandscapeMaterialAsset> .invalid);
     }
     this.materials.canInspectorAdd    = false;
     this.materials.canInspectorRemove = false;
     this.materials.inspectorChanged  += this.handleMaterialsInspectorChanged;
     this.prototypes = new SplatPrototype[Landscape.SPLATMAP_LAYERS];
     for (int n = 0; n < this.prototypes.Length; n++)
     {
         SplatPrototype splatPrototype = new SplatPrototype();
         splatPrototype.texture = Texture2D.blackTexture;
         this.prototypes[n]     = splatPrototype;
     }
     this.data = new TerrainData();
     this.data.splatPrototypes     = this.prototypes;
     this.data.heightmapResolution = Landscape.HEIGHTMAP_RESOLUTION;
     this.data.alphamapResolution  = Landscape.SPLATMAP_RESOLUTION;
     this.data.baseMapResolution   = Landscape.BASEMAP_RESOLUTION;
     this.data.size = new Vector3(Landscape.TILE_SIZE, Landscape.TILE_HEIGHT, Landscape.TILE_SIZE);
     this.data.SetHeightsDelayLOD(0, 0, this.sourceHeightmap);
     this.data.SetAlphamaps(0, 0, this.sourceSplatmap);
     this.data.wavingGrassTint = Color.white;
     this.terrain                      = this.gameObject.AddComponent <Terrain>();
     this.terrain.terrainData          = this.data;
     this.terrain.heightmapPixelError  = 200f;
     this.terrain.materialType         = 3;
     this.terrain.reflectionProbeUsage = 0;
     this.terrain.castShadows          = false;
     this.terrain.drawHeightmap        = !Dedicator.isDedicated;
     this.terrain.drawTreesAndFoliage  = false;
     this.terrain.collectDetailPatches = false;
     this.terrain.Flush();
     this.collider             = this.gameObject.AddComponent <TerrainCollider>();
     this.collider.terrainData = this.data;
 }