HarvesterTerrainMask
Introduction
The HarvesterTerrainMask
is a C# script in a Unity game development project that represents a component of the Harvester
class. This script generates a TerrainMask
which is used to mask out areas of a terrain in a game where the harvester cannot operate.
The HarvesterTerrainMask
class creates a Texture2D
and a RenderTexture
that are used to create the TerrainMask
. It also uses a shader to render the mask on the terrain.
The HarvesterTerrainMask
provides methods to create and update the TerrainMask
based on the size of the terrain, the position of the camera, and the radius of the harvester’s detection range. It also provides methods to apply and remove the TerrainMask
on the terrain.
This component is crucial to the Harvester
class as it allows the harvester to operate only on areas of the terrain that are harvestable. By masking out non-harvestable areas, it prevents the harvester from accidentally destroying objects that should not be harvested, thus preventing game-breaking bugs and enhancing the user experience.
Overview
HarvesterTerrainMask is a class that removes trees on a terrain that are within a specified box collider.
Interface pages:
None
Constructor pages:
None
Method pages:
Method Name | Return Type | Description |
---|---|---|
Start() | void | The Start method is called before the first frame update. It initializes the class variables, backs up the original terrain trees, and removes trees that are within the box collider. |
removeTree(Terrain thisTerrain, TreeInstance treeInstance) | void | The removeTree method removes the specified tree from the terrain. |
GetTerrainFromName(string terrainName) | Terrain | The GetTerrainFromName method returns the terrain instance with the specified name. |
OnDisable() | void | The OnDisable method is called when the game object is disabled. It restores the original terrain trees. |
OnDestroy() | void | The OnDestroy method is called when the game object is destroyed. It restores the original terrain trees. |
Property pages:
Property Name | Type | Description |
---|---|---|
boxCollider | BoxCollider | The box collider that defines the area to search for trees to remove. |
vegetationDetectionDistance | float | The distance from the terrain at which trees are detected. |
harvestableObject | HarvestableObject | The harvestable object. |
harvestableCollider | HarvestableCollider | The collider for the harvestable object. |
Trees_On_Terrain | TreeInstance[] | The array of tree instances on the terrain. |
thisObjectsTerrain | Terrain | The terrain that this object is on. |
originalTrees | TreeInstance[] | The array of original trees on the terrain. |
NewTrees_On_Terrain | List<TreeInstance> | The list of new tree instances on the terrain. |
Event pages:
None
Concept/guide pages:
None
Examples:
None