A simple loot table for Unity. It allows you to easily create loot table for your game and manage them in an intuitive UI. You can customize it easily to work with different data types as your drop. You can for example switch out the standard GameObjects to a custom item class or similar by following the steps below
- Easily drop a range of optional and guaranteed drops
- Drop items based on an assigned weight
- Preview drop chances, when editing your loot tables
- Customize the used drop class and use your own item class
- Adjust your loot tables on the fly in an intuitive and easiy to use inspector
You can add the package to your project in the following ways:
-
Get it on the Unity Asset Store
-
Downloading it via the package manager or manually add the dependency to your manifest.json:
"com.kellojo.simple-loot-table": "https://github.com/Kellojo/Unity-Simple-Loot-Table.git",
- Create a new loot table scriptable object using the create menu
Create/Kellojo/Loot Table/
- Setup your loot table with your loot
- Integrate the loot table into your codebase
using System.Collections.Generic;
using UnityEngine;
using SimpleLootTable;
public class OrePile : MonoBehaviour
{
public List<Transform> OreSlots;
public GameObjectLootTable LootTable;
private void Awake() {
// spawn guaranteed drops
var drops = LootTable.GetGuaranteedDrops();
drops.ForEach(drop => Instantiate(drop, transform.position, transform.rotation));
// spawn optional drops
var optionalDrops = LootTable.GetOptionalDrops(2);
optionalDrops.ForEach(drop => Instantiate(drop, transform.position, transform.rotation));
// spawn both at the same time
var combinedDrops = LootTable.GetGuaranteedAndOptionalDrops(2);
combinedDrops.ForEach(drop => Instantiate(drop, transform.position, transform.rotation));
}
}
- Create a new CS script with the following content:
using UnityEditor;
using UnityEngine;
using Kellojo.SimpleLootTable;
[CreateAssetMenu(menuName = "Kellojo/Loot Table/Game Object Loot Table")]
public class GameObjectLootTable : LootTableBase<GameObject> {}
[System.Serializable]
public class GameObjectDropConfig : DropConfig<GameObject> { }
- Replace
GameObject
with your custom type/class - Adjust the
menuName
to match your class name - Ensure your custom item class is serialized by Unity
- Create another script in your
Editor
folder which contains the editor for your custom loot table type:
using UnityEditor;
using UnityEngine;
using Kellojo.SimpleLootTable;
using Kellojo.SimpleLootTable.Editor;
[CustomEditor(typeof(GameObjectLootTable))]
public class GameObjectLootTableEditor : LootTableEditorBase<GameObject> { }
- Replace
GameObject
with your custom type/class - Rename the class to more closely match your custom type (i.e.
GameObjectLootTableEditor
->ItemLootTableEditor
) - Done! Your custom loot table can now be used.
This asset was inspired by an existing asset Loot Table - Universal Loot System. I had issues extending it and adding custom item classes to it, which is why this asset has been created.