Unity Harvesting

Introduction

The HarvesterObjectGenerator is a C# class that generates and stores objects that can be harvested by the Harvester class. The objects are stored in a HarvesterObjectsSystem array, which contains information such as the object’s tag, prefab, harvested prefab, mass, spawn probabilities, and other properties.

The class generates a networked instance of the objects when the player interacts with them, and can spawn harvest effects and explosion effects when the object is harvested. It can also generate non-harvestable objects for decoration or obstacles. The objects can be randomly rotated and positioned for variety.

The HarvesterObjectGenerator can be customized in Unity using the inspector window, allowing for easy configuration of the objects and their properties. The objects can be created manually, or generated procedurally based on various settings, such as the number of objects to generate, their placement density, and the shape of the terrain.

 

Overview page

The HarvesterObjectGenerator class is used to generate objects that can be harvested in the Unity game engine. It also includes settings for objects that will be destroyed after harvesting and objects that can be spawned around the harvest location. This script also contains the tools to remove harvestable objects from the game world.

Interface pages

None.

Constructor pages

None.

Method pages

Method Description
ProcessFolder() Searches a folder and builds all objects found in that folder.
AddItems() Adds the harvestable objects to the game world.
AddPlayerItems() Adds the items to the player’s inventory.
AddItemsProcessor(string thisItemPath) Adds the harvestable objects to the game world using the specified item path.
AddPlayerItemsProcessor(string thisItemPath) Adds the items to the player’s inventory using the specified item path.
RemoveItems() Removes the harvestable objects from the game world.
RemovePlayerItems() Removes the items from the player’s inventory.
RemovePlayerItemsProcessor(string thisItemPath) Removes the items from the player’s inventory using the specified item path.
RemoveItemsProcessor(string thisItemPath) Removes the harvestable objects from the game world using the specified item path.
CreateDropPrefab(bool processFolder = false) Creates a new drop prefab object and saves it to the specified folder. If true, processes all objects in the specified folder.

 

Property Name Type Description
networkedHarvestableObjectFolder string The folder containing harvestable objects
networkedNonHarvestableObjectFolder string The folder containing non-harvestable objects
harvestableScriptableObjectFolder string The folder containing scriptable objects
harvester Harvester The Harvester component associated with the object
FolderToProcess UnityEngine.Object The folder to process
ObjectToBuild GameObject The object to build
ItemNameCleanup string The string used to clean up item names
ItemName string The name of the object
enableHealthUI bool Whether the health UI is enabled
enableRegen bool Whether the object can regenerate health
harvestableHealth float The current health of the object
maxHealth float The maximum health of the object
healthBarLength float The length of the health bar
healTime float The time it takes to heal the object
lerp float The amount of health regeneration
smoothing float The amount of smoothing applied to the health flow
healthBar GameObject The health bar UI object
healthBarOffset Vector3 The offset of the health bar UI object
recoveryTickRate int The number of ticks required for the object to heal itself
recoveryPerTick float The amount of recovery per tick
terrainIndex int The index of the terrain
healthBarItem GameObject The health bar item
tagNames string The tag name associated with the object
HarvesterFx ParticleSystem The particle effect that plays when the object is harvested
HarvesterGameObjectFx GameObject The game object that is used when the object is harvested
harvestedPrefab GameObject The networked object that is dropped on the ground
harvestableObjectMass float The mass of the harvestable object
requireHarvesterTool bool Whether a harvesting tool is required
amountHarvestedSpawn int The number of harvested items to spawn
perHitHarvesting bool Whether one object should be spawned per hit
spawnPrefabOdds float The odds that an object will spawn
toolType List<string> The list of tool types that can damage the object
damageToolType List<string> The list of damage tool types
weakToolType List<string> The list of weak tool types
damageToTool int The amount of damage the object will do to the tool
damageToToolMultiplier int The multiplied amount of damage the object will do to the tool
successfulUseSound AudioClip The sound that is played when the object is successfully hit
successfulHarvestSound AudioClip The sound that is played when the object is successfully harvested