HarvesterTerrainBackup
Introduction
HarvesterTerrainBackup is a class that handles terrain backup for the Harvester system. It is responsible for creating a backup of terrain data in a given area and restoring it when needed.
When the Harvester is initialized, the HarvesterTerrainBackup class creates a backup of the terrain data within the specified range. It does this by creating a new Texture2D object and copying the relevant terrain data into it. The class also stores the original terrain heights in an array for later use.
During the harvesting process, the HarvesterTerrainBackup class is responsible for updating the terrain data to reflect the changes caused by the harvesting. It does this by modifying the original terrain heights array, which allows the system to restore the terrain to its original state when the harvesting is complete.
The HarvesterTerrainBackup class also provides a method to restore the terrain to its original state. This is used when the Harvester is disabled, or when the terrain needs to be restored for some other reason.
Overall, the HarvesterTerrainBackup class is a crucial component of the Harvester system, ensuring that the terrain can be modified and restored as needed during the harvesting process.
Overview
The HarvesterTerrainBackup
class is responsible for generating colliders for harvestable objects on a terrain, which allows players to interact with them. It is also used to backup and restore the original state of the terrain’s tree instances.
Property Pages
Property Name | Data Type | Description |
---|---|---|
terrain | Terrain |
The terrain object that this script is attached to. |
originalTrees | TreeInstance[] |
The tree objects on the terrain, this is used to restore the original trees back to the terrain if the application quits or crashes. |
detailProtypes | DetailPrototype[] |
The detail objects on the terrain, this is used to restore the original details back to the terrain if the application quits or crashes. |
useMeshCollider | bool |
Use the alternative method to create your trees? This allows you to not have colliders on trees attached to the tree. The other method might potentially leave a tree collider in place or allow the player to fall through the terrain, but is the default method. |
colliderOptions | ObjectColliderOptions[] |
An array of ObjectColliderOptions that specifies which object tags should be used and whether mesh colliders should be enabled for each harvestable object. |
enableDebugOptions | bool |
Do you want to enable the visual debug settings that show various objects in addition to the harvestable objects. This can be used to test collision deletion and more. |
Unity Usage
To use this class, add it as a component to a game object in your scene. Then, specify the terrain that this script should apply to. You can also customize the behavior of the colliders that are generated by configuring the colliderOptions
property.
If you want to back up and restore the original state of the terrain’s tree instances, simply leave the originalTrees
property empty. Otherwise, populate it with the current state of the terrain’s tree instances during Awake()
.
If you want to disable this script during runtime, it will restore the original trees.
Note that this script is expensive and generates colliders on start, which can cause significant performance issues on large terrains.