Dice Master - The complete solution for your rolling needs [Unity5]

News

  • The asset has now been updated to version 1.1.0, with the new major feature of dynamic dice. Check the latest post!

Asset store
Website
Features video
WebGL demo
HTML documentation

Dice Master is the complete solution for dice creation, spawning, throwing, and runtime handling. This tool will allow you to create custom dice from scratch, no coding required. It also allows you to control the behaviour of any dice at runtime: throw and spin dice, spawn them, and check their result.

Here is a feature list:

  • A complete editor for creating your custom dice without a single line of code
  • Numbers, pips, colors, and special sprites to create custom dice out of the box
  • Uses PBR materials to create realistic dice
  • Automatic and optimized number detection on rest, with an event-based inspector hook
  • Spawner, thrower, and spinner mechanisms included
  • Optimized textures or dynamic faces: your choice
  • Visual gizmos for dice, spawner, thrower, and spinner
  • Physics materials and masses that mimic real dice
  • 7 dice types (from D2 to D20) with default prefabs provided, plus several custom dice
  • High- and low- poly meshes for all 7 dice types
  • Test scenes for throwing, rolling, and using the runtime checking system
  • Complete HTML documentation
  • Optimized for mobile use
  • Full source code
  • Weighted dice, sound effects on hit, different gravity, and more!

Any question, comment, suggestion, or general feedback is welcome!

1 Like

Hello! I prepared a feature demo video, take a look at it!

Dice Master is out now!

I just released the package as a beta version, discounted by 30% on the final price!
The tool will remain in beta till I deem it stable enough to be released, so expect minor issues that will nonetheless be fixed as soon as possible.

Check out the package’s website with documentation links: Dice Master

And here is the package: Unity Asset Store - The Best Assets for Game Making

Roll on!

2343982--158586--weightedDice_b.gif
Weighted dice in action :wink:

What would be great is if there were also classes to parse dice throw strings in to integer values and then also into on the spur objects/animations. Then this asset would sit well with any inventory system

Hi Duffer123, thanks for the suggestion! However, I am not sure I understood what you meant by dice throw strings and parsuing them into spur objects, could you please elaborate on that?

So if I had a string value of “2D4 + 5” you could both either (a) provide an introduction value of the result of that throw (having accurately parsed the above string) or (b) generate the relevant models and animation etc. ?

I see, I like the idea, I can create a spawner that takes as input the string and then throws the dice as needed. Models should be provided beforehand, as they do not change from one throw to the next.

I think I will add something similar in the next update, thanks for the tip!

To be honest, try and do a and b separately. If you can do a really good job of a, perhaps using regular expressions, people will buy the Asset just for that…

Yep, that’s my idea as well, the parser is a nice idea. regexps are a bit overkill for the purpose, however, as the strings are quite simple!

Is it possible to get the results of dice that are spawned? I’ve been going over the examples (that all appear to use dice already in the scene) and following those, I can only seem to get the results of test dice in the scene.

The Dice segment "On Show Number (Int32) only gives me the options of “no function” and monoscript if I try to use a prefab of a nice that has not yet spawned.

I tried aiming at the clones that came up during Play but those results obviously did not stick.

Hi TomaTantrum. Yes, it is possible! However, it’s true I did not provide an example for this in the scripts.
I’ll show you how to do that.

You are going in the right direction, as you do need to attach to the spawned dice’s onShowNumber event.

We could do that in two ways:

  • iterate over the dice in the scene, keep a reference to them, and then react when a new dice is met.
  • wait for a dice to be spawned and then react to a spawn event.

We will use the second approach as it is better. It requires us however to modify the Spawner class to add a new event, onSpawnDice. This is triggered whenever a new dice is spawned and it returns the dice itself.
You will find the updated Spawner class as an attachment here. I will make sure to add this to the next version, since it’s a very useful feature.

We now can use something similar to the script TestDiceRegister.cs to check the results of dice that are spawned.

using UnityEngine;
using DiceMaster;

/// <summary>
/// Registers to spawned dice and logs their result
/// </summary>
public class TestSpawnRegister : MonoBehaviour {

    Spawner spawner;

    void Start () {
        spawner = GetComponent<Spawner>();

        spawner.onSpawnDice.AddListener(this.OnNewDiceSpawned);
    }

    void OnNewDiceSpawned(Dice dice)
    {
        dice.onShowNumber.AddListener(RegisterNumber);
    }

    public void RegisterNumber(int number)
    {
        Debug.Log("Got " + number);
    }
}

And that’s it. Attach this script to a Spawner and it will detect when a new Dice is spawned, attach to its onShowNumber event, and let you do whatever you want with the resturned numbers!

Thank you for your report and I hope you find the asset useful!

2382390–162152–Spawner.cs (3.5 KB)

Thanks, Catman! Those worked perfectly!

I’ve been working to tally up the number of time each result occurs (one occurrence of 3, five occurrences of 1, etc) So that I can trigger events based on those results. Is that in line with the features discussed earlier with Duffer123? Or am I way off base?

Also this asset has been super awesome. A lot of time and confusion saved over here, and the asset is still in beta. Awesome stuff.

Glad I could be of help!

I’m not really sure I understood what you are trying to do. Are you just counting the results? If that’s the case, it’s outside of the scope of the tool (you could do anything with the returned number, just by creating something similar to TestDiceRegister, which for example just sums the totals).

Duffer123 is talking instead about creating a spawner that directly gets dice strings such as “3D6” and throws three six-sided dice at once!

I’m working on some code that counts the results this week myself. It’s been a while since I did some coding last, but I’m almost at the results I want. I’ll post some results here in case anyone comes by interested in the same result print out.

I read too far in to the spawner discussion I think. I understand now, thanks.

Let me know if you find any more trouble!

I guess what you would need is just something like:

int counters[] = new int[6];
public void RegisterNumber(int number)
{
   // Increase the i-1 counter (0 for 1, 1 for 2, ..., 5 for 6)
   counters[number]++;
}

Hey Catman;

I’ve been learning to code + working on my code all week. I’ve gotten close to the results I’ve been wanting but I’m suck on 2 final items for now.

with the help of a friend and some internet goers plus your initial code, I made a list that maintains count of the 6 different possible results from my 6-sided test dice.

When I press ‘Play’ the dice roll and the result of each die is tallied and added up properly. I added some if statements for each result so that new logs appear based on how many times each result occurs. After some tweaks, those now work properly as well.

The 2 final issues have are:

  • I can’t seem to keep the roll results between plays. Every time I run the game, the result counts all start back at 0 (I think I need to figure out serialization to fix this).

  • My current code is locked to 6 sided dice. I’m trying to find a way to make the list flexible so I can use the code for any size dice.

I’ll be working these two items this weekend and if I get either desired result, I’ll update here.

Thanks again for Dice Master.

Code with notes thus far attached.

2390602–162871–TestSpawnRegister.cs (3.56 KB)

Unity serialization is a complex topic. Note that any MonoBehaviour value, regardless of serialization, will be reset to the initial values each time you exit play mode.
To save your state, you should look at the PlayerPrefs class (to keep things simple), or use some additional hand-made XML serialization.

That’s because you are using separate variables for each number (resultOne, resultTwo, etc.).
I see you also have the ResultCount dictionary, tho, and you could just use that. Instead of looping over 6 values when creating the dictionary, you can generalize that to N values, where N is the number of faces.

Cheers,
Michele

Yeah, after spending the past week or so looking at serialization and Scriptable Objects and not really making a dent it surely looks like its time to go to PlayerPrefs. Maybe I can look at serializing and SOs again after getting the ground works implemented set the way I want before optimizing.

I tried pulling the numberOfFaces from the prefab the script was connected to over the weekend, but that’s probably another case of aiming to high for a first trial set up. I’ll see about making some less complicated changes tonight.

Thanks for the feedback Michele!

Yep, that’s the correct way of doing it: the Dice prefab you spawn will have a DiceDefinition you can access through its ‘definition’ variable, and that has the numberOfFaces variable.

Glad I could be of help, I hope the tool will be useful for you!
If you want to help back I’d really appreciate if you took the time to write a short review on the asset store!

Dice Master is now out of beta. Thanks to all the beta testers for their feedback and support!

Here is the changelog:

v 1.0.3

  • better default sound effect
  • added complete instructions in the documentation
  • added a complete set of warnings to the code
  • out of BETA!

v 1.0.2

  • added spawning event to the Spawner class. Added a new spawn test register scene and script.
  • fixed bug with asset store paths being wrong

v 1.0.1

  • fixed bug with spawner and trigger-on-start
  • made coin less susceptible to falling by cut