# Item Spawner

## 🎁 ItemSpawner Class

Gives item drop functionality to any `GameObject`.

> **Namespace:** `Esper.Inventool.Items`\
> **Access:** `public`\
> **Type:** `class`\
> **Inherits:** `MonoBehaviour`

***

### 📦 Fields

| Access   | Field             | Type          | Description                                                                                                   |
| -------- | ----------------- | ------------- | ------------------------------------------------------------------------------------------------------------- |
| `public` | `spawnMethod`     | `SpawnMethod` | The spawn method type.                                                                                        |
| `public` | `spawnTarget`     | `SpawnTarget` | The target object type used to spawn items.                                                                   |
| `public` | `afterSpawn`      | `AfterSpawn`  | What to do when items are spawned.                                                                            |
| `public` | `itemStack`       | `ItemStack`   | The item stack to spawn. Used when spawn target is set to **Single**.                                         |
| `public` | `itemPouch`       | `ItemPouch`   | The item pouch used to spawn items. Used when spawn target is set to **Pouch**.                               |
| `public` | `lootBox`         | `LootBox`     | The loot box used to spawn items. Used when spawn target is set to **LootBox**.                               |
| `public` | `collisionTarget` | `GameObject`  | The collision target used when the spawn method is set to any collision type.                                 |
| `public` | `spawnRange`      | `float`       | The item drop spawn range.                                                                                    |
| `public` | `spawnDelay`      | `float`       | The length of time passed before the item(s) are spawned.                                                     |
| `public` | `useTimeout`      | `bool`        | If timeout should be enabled for dropped items.                                                               |
| `public` | `canSpawn`        | `bool`        | If spawning should be possible. Automatically set to false after spawn if `afterSpawn` is set to **Disable**. |

***

### 🧰 Methods

| Access   | Method    | Returns | Description                                                                |
| -------- | --------- | ------- | -------------------------------------------------------------------------- |
| `public` | `Spawn()` | `void`  | Spawns items based on the set properties. The spawn delay will be applied. |

***

### 🧩 Nested Types

#### `public enum SpawnTarget`

Defines the target object type that the `ItemSpawner` uses to spawn items.

| Name      | Description                                                      |
| --------- | ---------------------------------------------------------------- |
| `Single`  | Spawn a single item.                                             |
| `Pouch`   | Spawn all items from an item pouch.                              |
| `LootBox` | Spawn a random number of random items, as defined in a loot box. |

***

#### `public enum SpawnMethod`

Defines when the `ItemSpawner` will spawn items.

| Name               | Description                                                                 |
| ------------------ | --------------------------------------------------------------------------- |
| `OnDisable`        | Spawn items when the object is disabled.                                    |
| `OnEnable`         | Spawn items when the object is enabled.                                     |
| `OnDestroy`        | Spawn items when the object is destroyed.                                   |
| `OnCollisionEnter` | Spawn items when a specific target collides with the object.                |
| `OnTriggerEnter`   | Spawn items when a specific target collides with the object (trigger).      |
| `OnCollisionExit`  | Spawn items when a specific target exits collision with the object.         |
| `OnTriggerExit`    | Spawn items when a specific target exits trigger collision with the object. |
| `OnCall`           | Spawn items when the `Spawn` method is manually called.                     |

***

#### `public enum AfterSpawn`

Defines what should happen after `Spawn()` is called.

| Name                | Description               |
| ------------------- | ------------------------- |
| `DoNothing`         | Do nothing.               |
| `Disable`           | Disable the component.    |
| `DisableGameObject` | Disable the `GameObject`. |
| `DestroyGameObject` | Destroy the `GameObject`. |

## Spawn

Use the `Spawn` method to spawn item drops based on the set fields.

```csharp
myItemSpawner.Spawn();
```
