GithubHelp home page GithubHelp logo

kellojo / unity-simple-loot-table Goto Github PK

View Code? Open in Web Editor NEW
10.0 1.0 1.0 341 KB

A simple loot table for Unity. It's easily customizable and allows you to bring your own item classes and types.

License: MIT License

C# 100.00%
customizable developer-tools drops extendable library loot loot-tables package unity unity3d

unity-simple-loot-table's Introduction

Unity-Simple-Loot-Table

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

Features

  • 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

Installation

You can add the package to your project in the following ways:

  1. Get it on the Unity Asset Store

  2. 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",

Using a loot table

  1. Create a new loot table scriptable object using the create menu Create/Kellojo/Loot Table/
  2. Setup your loot table with your loot
  3. 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));
        
    }

}

Using a custom item class/type

  1. 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> { }
  1. Replace GameObject with your custom type/class
  2. Adjust the menuName to match your class name
  3. Ensure your custom item class is serialized by Unity
  4. 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> { }
  1. Replace GameObject with your custom type/class
  2. Rename the class to more closely match your custom type (i.e. GameObjectLootTableEditor -> ItemLootTableEditor)
  3. Done! Your custom loot table can now be used.

Credits

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.

unity-simple-loot-table's People

Contributors

kellojo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

r2d2m

unity-simple-loot-table's Issues

Does not support Interfaces of ScriptableObjects

Trying to add an interface which is inherited by a Scriptable Objects in a custom Loot Table does not work since it

must be convertible to 'UnityEngine.Object' in order to use it as parameter

This would be useful for games which have multiple type of loot which all inherit the same interface

Weight 1 is Never Rolled

With the following setup, the item with weight 1 will never be rolled despite saying it should be 33% of the time here, an easy workaround is to use weight 20 and 10 instead of 2 and 1 for example.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.