ParticulaCode / GoDiceUnityDemo

GoDice Unity Demo
Other
12 stars 5 forks source link

GoDice Demo

This is a demo project on how you can communicate with GoDice. Use it as a reference or starting point for your own application.

Here you can find a tutorial video of how to build the project in Unity for Android: https://youtu.be/SjlsfxbiFwc

External dependencies

  1. Bluetooth plugin is not included in this repository due to legal issues. We strongly recommend using this plugin Bluetooth LE for iOS, tvOS and Android.

    To add the Plugin to the project, do the following:

    • Make sure your current platform in Unity is either Android or iOS
    • Import the BLE plugin to the project.
    • Feel free to reorder plugin's content as you like, but make sure to create an Assembly Definition (BLE in our case) for these scripts:

    • Go to the directory "Assets\Scripts\GoDice\App\Modules\Bluetooth", click the assembly refernece file GoDice.App.Modules.Bluetooth and the reference to BLE assembly definition (from the previous step) to the Assembly Definition Reference list (by dragging it to the end of the list), click Apply. Now everything supposed to compile.
    • Enter the "Project Setting" and add the USE_BLE_PLUGIN definition to the "Scripting Define Symbols" section. Click Apply. If you want to use another plugin for bluetooth communication, you have to make your own implementation of IBluetoothBridge and disable USE_BLE_PLUGIN define.
  2. FrostLib is an in-house set of scripts.

  3. We encourage you to also add Odin Inspector to the project. It will provide you with a better inspector for simulated dice. And this is an awesome plugin in general. By default demo project has OdinMockup assembly to keep the code compiled, but you if you add Odin Inspector and disable USE_ODIN_MOCKUP

  4. Whatever plugin you'll decide to use for Bluetooth - don't forget to reference its assembly definition in GoDice.App.Modules.Bluetooth

Architecture

Project is based on an event-handler approach with a custom DI and ServiceLocator pattern. If you are looking for an entry point - look at Bootstrapper classes and Bootstapper game objects on the scene.Demo.Bootstrapper is an entry point to the project. Some code in the project is unused, but kept for demonstration sake. Some design decisions may seems redundant or overengineered, but keep in mind that all this code is transferred from GoDice companion project and part of much bigger and complex codebase.

Modules

Project contains following modules:

Here is a quick look at all c# projects in the solution

Demo module

Contains very basic UI classes, starts common services and initializes other modules. Demonstrates how to connect to multiple dice and exchange messages.

Bluetooth module

Generally this is an abstraction and wrapper over bluetooth plugin. Module is responsible for:

Dice module

Module is responsible for:

Simulation module

Module is responsible for:

Simulation module is not 100% correct to the firmware of GoDice. Yet they are reasonably similar and allow reliable playtest dice in editor. In Editor simulated dice are always loaded by default in runtime. But you can have them instantiated on scene before entering play mode, if you want to have a persistent custom setup of dice.

Shared

Contains classes that are supposed to be shared across different modules. Kept for compatibility sake with the GoDice companion application.

Editor module

Contains useful commands and hotkeys to work with dice in editor.