Corgi Engine  v9.1
MoreMountains.CorgiEngine.Loot Class Reference

A class meant to spawn objects (usually item pickers, but not necessarily) The spawn can be triggered by any script, at any time, and comes with automatic hooks to trigger loot on damage or death More...

Inheritance diagram for MoreMountains.CorgiEngine.Loot:
MoreMountains.CorgiEngine.CorgiMonoBehaviour

Public Types

enum  LootModes { LootModes.Unique, LootModes.LootTable, LootModes.LootTableScriptableObject }
 the possible modes by which loot can be defined More...
 

Public Member Functions

virtual void ResetRemainingQuantity ()
 Resets the remaining quantity to the maximum quantity More...
 
virtual void InitializeLootTable ()
 Computes the associated loot table's weights More...
 
virtual void SpawnLoot ()
 This method spawns the specified loot after applying a delay (if there's one) More...
 
virtual void SpawnOneLoot ()
 Spawns a single loot object, without delay, and regardless of the defined quantities More...
 

Public Attributes

LootModes LootMode = LootModes.Unique
 
GameObject GameObjectToLoot
 the object to loot, when in LootMode More...
 
MMLootTableGameObject LootTable
 a loot table defining what objects to spawn More...
 
MMLootTableGameObjectSO LootTableSO
 a loot table scriptable object defining what objects to spawn More...
 
bool SpawnLootOnDeath = true
 if this is true, loot will happen when this object dies More...
 
bool SpawnLootOnDamage = false
 if this is true, loot will happen when this object takes damage More...
 
bool PoolLoot = false
 if this is true, lootables will be pooled More...
 
int PoolSize = 20
 determines the size of the pool for each object in the loot table More...
 
string MutualizedPoolName = ""
 a unique name for this pool, has to be common between all Loot objects sharing the same loot table if you want to mutualize their pools More...
 
float Delay = 0f
 a delay (in seconds) to wait for before spawning loot More...
 
Vector2 Quantity = Vector2.one
 the minimum and maximum quantity of objects to spawn More...
 
MMSpawnAroundProperties SpawnProperties
 the position, rotation and scale objects should spawn at More...
 
bool LimitedLootQuantity = true
 if this is true, loot will be limited to MaximumQuantity, any new loot attempt beyond that will have no outcome. If this is false, loot is unlimited and can happen forever. More...
 
int MaximumQuantity = 100
 The maximum quantity of objects that can be looted from this Loot object. More...
 
int RemainingQuantity = 100
 The remaining quantity of objects that can be looted from this Loot object, displayed for debug purposes. More...
 
bool AvoidObstacles = false
 Whether or not spawned objects should try and avoid obstacles. More...
 
LayerMask AvoidObstaclesLayerMask = LayerManager.ObstaclesLayerMask
 the layer mask containing layers the spawned objects shouldn't collide with More...
 
float AvoidRadius = 0.25f
 the radius around the object within which no obstacle should be found More...
 
int MaxAvoidAttempts = 5
 the amount of times the script should try finding another position for the loot if the last one was within an obstacle. More attempts : better results, higher cost More...
 
MMFeedbacks LootFeedback
 A MMFeedbacks to play when spawning loot. Only one feedback will play. If you want one per item, it's best to place it on the item itself, and have it play when the object gets instantiated. More...
 
bool DrawGizmos = false
 if this is true, gizmos will be drawn to show the shape within which loot will spawn More...
 
int GizmosQuantity = 1000
 the amount of gizmos to draw More...
 
Color GizmosColor = MMColors.LightGray
 the color the gizmos should be drawn with More...
 
float GimosSize = 1f
 the size at which to draw the gizmos More...
 
bool SpawnLootButton
 a debug button used to trigger a loot More...
 

Static Public Attributes

static List< MMSimpleObjectPoolerSimplePoolers = new List<MMSimpleObjectPooler>()
 
static List< MMMultipleObjectPoolerMultiplePoolers = new List<MMMultipleObjectPooler>()
 

Protected Member Functions

virtual void Awake ()
 On Awake we grab the health component if there's one, and initialize our loot table More...
 
virtual void InitializePools ()
 
virtual MMSimpleObjectPooler FindSimplePooler ()
 
virtual MMMultipleObjectPooler FindMultiplePooler ()
 
virtual void Spawn (GameObject gameObjectToSpawn)
 
virtual void SpawnLootDebug ()
 A debug method called by the inspector button More...
 
virtual IEnumerator SpawnLootCo ()
 A coroutine used to spawn loot after a delay More...
 
virtual GameObject GetObject ()
 Gets the object that should be spawned More...
 
virtual void OnHit ()
 On hit, we spawn loot if needed More...
 
virtual void OnDeath ()
 On death, we spawn loot if needed More...
 
virtual void OnEnable ()
 OnEnable we start listening for death and hit if needed More...
 
virtual void OnDisable ()
 OnDisable we stop listening for death and hit if needed More...
 
virtual void OnDrawGizmos ()
 OnDrawGizmos, we display the shape at which objects will spawn when looted More...
 

Static Protected Member Functions

static void InitializeStatics ()
 

Protected Attributes

Health _health
 
GameObject _objectToSpawn
 
GameObject _spawnedObject
 
Vector3 _raycastOrigin
 
RaycastHit2D _raycastHit2D
 
Collider[] _overlapBox
 
MMSimpleObjectPooler _simplePooler
 
MMMultipleObjectPooler _multipleObjectPooler
 

Detailed Description

A class meant to spawn objects (usually item pickers, but not necessarily) The spawn can be triggered by any script, at any time, and comes with automatic hooks to trigger loot on damage or death

Member Enumeration Documentation

◆ LootModes

the possible modes by which loot can be defined

Enumerator
Unique 
LootTable 
LootTableScriptableObject 

Member Function Documentation

◆ Awake()

virtual void MoreMountains.CorgiEngine.Loot.Awake ( )
protectedvirtual

On Awake we grab the health component if there's one, and initialize our loot table

◆ FindMultiplePooler()

virtual MMMultipleObjectPooler MoreMountains.CorgiEngine.Loot.FindMultiplePooler ( )
protectedvirtual

◆ FindSimplePooler()

virtual MMSimpleObjectPooler MoreMountains.CorgiEngine.Loot.FindSimplePooler ( )
protectedvirtual

◆ GetObject()

virtual GameObject MoreMountains.CorgiEngine.Loot.GetObject ( )
protectedvirtual

Gets the object that should be spawned

Returns

◆ InitializeLootTable()

virtual void MoreMountains.CorgiEngine.Loot.InitializeLootTable ( )
virtual

Computes the associated loot table's weights

◆ InitializePools()

virtual void MoreMountains.CorgiEngine.Loot.InitializePools ( )
protectedvirtual

◆ InitializeStatics()

static void MoreMountains.CorgiEngine.Loot.InitializeStatics ( )
staticprotected

◆ OnDeath()

virtual void MoreMountains.CorgiEngine.Loot.OnDeath ( )
protectedvirtual

On death, we spawn loot if needed

◆ OnDisable()

virtual void MoreMountains.CorgiEngine.Loot.OnDisable ( )
protectedvirtual

OnDisable we stop listening for death and hit if needed

◆ OnDrawGizmos()

virtual void MoreMountains.CorgiEngine.Loot.OnDrawGizmos ( )
protectedvirtual

OnDrawGizmos, we display the shape at which objects will spawn when looted

◆ OnEnable()

virtual void MoreMountains.CorgiEngine.Loot.OnEnable ( )
protectedvirtual

OnEnable we start listening for death and hit if needed

◆ OnHit()

virtual void MoreMountains.CorgiEngine.Loot.OnHit ( )
protectedvirtual

On hit, we spawn loot if needed

◆ ResetRemainingQuantity()

virtual void MoreMountains.CorgiEngine.Loot.ResetRemainingQuantity ( )
virtual

Resets the remaining quantity to the maximum quantity

◆ Spawn()

virtual void MoreMountains.CorgiEngine.Loot.Spawn ( GameObject  gameObjectToSpawn)
protectedvirtual

◆ SpawnLoot()

virtual void MoreMountains.CorgiEngine.Loot.SpawnLoot ( )
virtual

This method spawns the specified loot after applying a delay (if there's one)

◆ SpawnLootCo()

virtual IEnumerator MoreMountains.CorgiEngine.Loot.SpawnLootCo ( )
protectedvirtual

A coroutine used to spawn loot after a delay

Returns

◆ SpawnLootDebug()

virtual void MoreMountains.CorgiEngine.Loot.SpawnLootDebug ( )
protectedvirtual

A debug method called by the inspector button

◆ SpawnOneLoot()

virtual void MoreMountains.CorgiEngine.Loot.SpawnOneLoot ( )
virtual

Spawns a single loot object, without delay, and regardless of the defined quantities

Member Data Documentation

◆ _health

Health MoreMountains.CorgiEngine.Loot._health
protected

◆ _multipleObjectPooler

MMMultipleObjectPooler MoreMountains.CorgiEngine.Loot._multipleObjectPooler
protected

◆ _objectToSpawn

GameObject MoreMountains.CorgiEngine.Loot._objectToSpawn
protected

◆ _overlapBox

Collider [] MoreMountains.CorgiEngine.Loot._overlapBox
protected

◆ _raycastHit2D

RaycastHit2D MoreMountains.CorgiEngine.Loot._raycastHit2D
protected

◆ _raycastOrigin

Vector3 MoreMountains.CorgiEngine.Loot._raycastOrigin
protected

◆ _simplePooler

MMSimpleObjectPooler MoreMountains.CorgiEngine.Loot._simplePooler
protected

◆ _spawnedObject

GameObject MoreMountains.CorgiEngine.Loot._spawnedObject
protected

◆ AvoidObstacles

bool MoreMountains.CorgiEngine.Loot.AvoidObstacles = false

Whether or not spawned objects should try and avoid obstacles.

◆ AvoidObstaclesLayerMask

LayerMask MoreMountains.CorgiEngine.Loot.AvoidObstaclesLayerMask = LayerManager.ObstaclesLayerMask

the layer mask containing layers the spawned objects shouldn't collide with

◆ AvoidRadius

float MoreMountains.CorgiEngine.Loot.AvoidRadius = 0.25f

the radius around the object within which no obstacle should be found

◆ Delay

float MoreMountains.CorgiEngine.Loot.Delay = 0f

a delay (in seconds) to wait for before spawning loot

◆ DrawGizmos

bool MoreMountains.CorgiEngine.Loot.DrawGizmos = false

if this is true, gizmos will be drawn to show the shape within which loot will spawn

◆ GameObjectToLoot

GameObject MoreMountains.CorgiEngine.Loot.GameObjectToLoot

the object to loot, when in LootMode

◆ GimosSize

float MoreMountains.CorgiEngine.Loot.GimosSize = 1f

the size at which to draw the gizmos

◆ GizmosColor

Color MoreMountains.CorgiEngine.Loot.GizmosColor = MMColors.LightGray

the color the gizmos should be drawn with

◆ GizmosQuantity

int MoreMountains.CorgiEngine.Loot.GizmosQuantity = 1000

the amount of gizmos to draw

◆ LimitedLootQuantity

bool MoreMountains.CorgiEngine.Loot.LimitedLootQuantity = true

if this is true, loot will be limited to MaximumQuantity, any new loot attempt beyond that will have no outcome. If this is false, loot is unlimited and can happen forever.

◆ LootFeedback

MMFeedbacks MoreMountains.CorgiEngine.Loot.LootFeedback

A MMFeedbacks to play when spawning loot. Only one feedback will play. If you want one per item, it's best to place it on the item itself, and have it play when the object gets instantiated.

◆ LootMode

LootModes MoreMountains.CorgiEngine.Loot.LootMode = LootModes.Unique

the selected loot mode :

  • unique : a simple object
  • loot table : a LootTable specific to this Loot object
  • loot definition : a LootTable scriptable object (created by right click > Create > MoreMountains > Corgi Engine > Loot Definition This loot definition can then be reused in other Loot objects.

◆ LootTable

MMLootTableGameObject MoreMountains.CorgiEngine.Loot.LootTable

a loot table defining what objects to spawn

◆ LootTableSO

MMLootTableGameObjectSO MoreMountains.CorgiEngine.Loot.LootTableSO

a loot table scriptable object defining what objects to spawn

◆ MaxAvoidAttempts

int MoreMountains.CorgiEngine.Loot.MaxAvoidAttempts = 5

the amount of times the script should try finding another position for the loot if the last one was within an obstacle. More attempts : better results, higher cost

◆ MaximumQuantity

int MoreMountains.CorgiEngine.Loot.MaximumQuantity = 100

The maximum quantity of objects that can be looted from this Loot object.

◆ MultiplePoolers

List<MMMultipleObjectPooler> MoreMountains.CorgiEngine.Loot.MultiplePoolers = new List<MMMultipleObjectPooler>()
static

◆ MutualizedPoolName

string MoreMountains.CorgiEngine.Loot.MutualizedPoolName = ""

a unique name for this pool, has to be common between all Loot objects sharing the same loot table if you want to mutualize their pools

◆ PoolLoot

bool MoreMountains.CorgiEngine.Loot.PoolLoot = false

if this is true, lootables will be pooled

◆ PoolSize

int MoreMountains.CorgiEngine.Loot.PoolSize = 20

determines the size of the pool for each object in the loot table

◆ Quantity

Vector2 MoreMountains.CorgiEngine.Loot.Quantity = Vector2.one

the minimum and maximum quantity of objects to spawn

◆ RemainingQuantity

int MoreMountains.CorgiEngine.Loot.RemainingQuantity = 100

The remaining quantity of objects that can be looted from this Loot object, displayed for debug purposes.

◆ SimplePoolers

List<MMSimpleObjectPooler> MoreMountains.CorgiEngine.Loot.SimplePoolers = new List<MMSimpleObjectPooler>()
static

◆ SpawnLootButton

bool MoreMountains.CorgiEngine.Loot.SpawnLootButton

a debug button used to trigger a loot

◆ SpawnLootOnDamage

bool MoreMountains.CorgiEngine.Loot.SpawnLootOnDamage = false

if this is true, loot will happen when this object takes damage

◆ SpawnLootOnDeath

bool MoreMountains.CorgiEngine.Loot.SpawnLootOnDeath = true

if this is true, loot will happen when this object dies

◆ SpawnProperties

MMSpawnAroundProperties MoreMountains.CorgiEngine.Loot.SpawnProperties

the position, rotation and scale objects should spawn at


The documentation for this class was generated from the following file: