© vrchewal

Dartboard Manager Documentation

version 1.0                                                                        for Unity

Documentation: Online Documentation

Support: vrchewal.com/unity/dartboard-manager

Asset Store: http://u3d.as/17vp

Jump To:

Introduction

How To

API

Troubleshooting

Support

Introduction

The Dartboard Manager for Unity is a complete dart game system that includes many popular dart games. The system is extendible, allowing you to create your own games or even create your own style of dartboard. Each section of the board is independently configurable.

Some of the features include: fully configurable dartboard, a dart model and dart script, full event driven API, 10 popular dart games, full online and pdf documentation, email support and more.

The included demo gives you a foundation to create your own games and see how simple building your own dart game can truly be. The manager includes 10 popular games and a template to create more dart games for the system. The 10 games are: Baseball, Cricket, 301 / 501 / 701 / 901, Golf, HighScore, Round The Clock, Shanghai.

How To

First, look at the demo scene for a working version of the system and the main scripts. The example script in the demo scene has the relevant functions for tapping into the API. The Dartboard Manager is setup so that you can have multiple running in the same scene. You should use the manager by direct reference as much as possible.

Get Started

From Prefab: Drag in the DartboardManager prefab into your hierarchy from the Assets/Dartboard Manager/Prefabs/ folder. This will bring in the structure of games and the dartboard itself.

From Scratch: Create an empty gameobject, rename it “DartboardManager” and attach the DartboardManager script. Drag in the Dartboard prefab as a child object of the DartboardManager. Create a new empty child object of the Manager and rename it Games. Create children objects under Games for each dart game you want to add.

You will now need a script (GameManager?) to handle event notifications from the Dartboard Manager. Check out DartboardDemo.cs for a full example. Register your callback method with the manager. The Runtime Code Flow section below goes into detail on this process.

Next, you will need to setup your darts. We provide a dart prefab with modifiable materials and dart settings. If you have your own dart models, just add the Dart script onto the dart. If you have your own dart flight mechanics, take a look at the Dart script for the relevant function calls for the dartboard interaction and determining hits/misses. Once your Dart is setup, you can remove it from the scene and instantiate the prefab when you want to give control to the player.

Finally, you will need to create a scoreboard so the player knows the status of the game. See the demo for the example scripts and check the API section below for details on each public method available. There are some scoreboard prefabs available for your use to alter as you see fit. Check out the demo for its general usage.

Runtime Code Flow

A summary of the flow of the system is as follows:

  1. In your game manager script, register your event callback with the DartboardManager (DartboardDemo.cs line 70) The DartboardManager will call this function when an event is triggered.

70. DartboardManager.Subscribe(DartManagerCallback);

...

83. public void DartManagerCallback(DartGameEvents GameEvent)

  1. Start a new dart game (DartboardDemo.cs see Update()) based on player selection from your UI.

158. DartboardManager.StartGame("Cricket", PlayerCount);

  1. Activate your darts, give the player control and do the magic of your game throwing mechanics. In the demo, we use a power meter and simple line renderer for aiming. The Dart.cs script uses Unity Rigidbody physics to determine flight. Upon impact, the relevant DartboardSection is Hit or the dart registers a miss with the DartboardManager.
  2. The dart game script runs its unique code and triggers events to determine scoring and game specific logic.
  3. The DartboardManager calls your function from step 1, passing the relevant event data. (DartboardDemo.cs line 83)
  4. Update the UI, retrieving scoring and player data from the manager API.
  5. Repeat step 3 through 6 until the game is over.

How To Create New Dart Games

Inherit from the DartGame script when creating new games. It automatically registers with the Manager and handles basic responses from the Manager. It is recommended that you follow the format and style of the existing games to limit the chance of redundancy.

All relevant functions are overridable. As you will see when reviewing the code of the included games, not all functions are needed to run your custom game. Just override the relevant ones and add your game specific logic. The game Highscore is a very basic game and a good place to start reviewing the concepts. The Cricket script is an example of a more advanced functionality and game logic implementation.

The API is event driven, so it is important that when creating new games that you include event triggers. For example, when the player wins the game, trigger the “GameOver” event and set the winning player. See the API section below for more information.

API

The following methods are open via the Dartboard Manager API. All indexes are a zero based number. Player numbers, non index, are 1 for player 1, 2 for player 2, etc. All functions are available, yet some are best used by game scripts only.

Main Functions

StartGame

bool

StartGame(string game, int players);

StartGame(DartGame game, int players);

Starts a new game by passing the name of a game and optionally the number of players. Returns true if the game is started and ready.

GetPlayerScore

int

GetPlayerScore(int playerIndex);

Returns the score of the current player or of the optional player index that is passed.

GetHighestScoringPlayer

int

GetHighestScoringPlayer();

Returns the player number with the highest score.

hasSingleHighestScoringPlayer

bool

hasSingleHighestScoringPlayer();

Returns true if there is no tie for highest score.

GetLowestScoringPlayer

int

GetLowestScoringPlayer();

Returns the player number with the lowest score.

hasSingleLowestScoringPlayer

bool

hasSingleLowestScoringPlayer();

Returns true if there is no tie for lowest score.

GetTotalThrowCount

int

GetTotalThrowCount();

Returns the total throws across all players.

GetTotalTurnCount

int

GetTotalTurnCount();

Returns the total turns across all players.

GetCurrentPlayer

int

GetCurrentPlayer();

Returns the current player number.

GetCurrentThrow

int

GetCurrentThrow();

Returns the current throw number.

GetGameState

DartGameStates

GetGameState();

Returns the current game state.

GetWinningPlayer

int

GetWinningPlayer();

Returns the player number who won the game. Set by game script right before the GameOver event is triggered.

Subscribe

void

Subscribe(DartGameDelegateEvent callback)

Used by your scripts to receive event notifications from the Dartboard Manager. Can be used for UI and game logic management. See demo.

Unsubscribe

void

Unsubscribe(DartGameDelegateEvent callback)

Unsubscribes from event notifications from the Dartboard Manager.

Game Script Functions

EndGame

void

EndGame(int winningPlayer);

Sets the winning player and ends the game. The winning player int is optional. If winning player is not set, the game is considered a tie.

StartTurn

void

StartTurn();

Starts the turn for the current player.

EndTurn

void

EndTurn();

Ends the current turn and advances the player.

StartThrow

void

StartThrow();

Starts the current throw.

EndThrow

void

EndThrow();

Ends the current throw and advances the throw/player.

SetLastHitPoints

void

SetLastHitPoints();

Sets the point value for the last throw for the current player. This is done automatically by the manager, but can be set manually from the game script if needed.

GetLastHitPoints

int

GetLastHitPoints(int playerIndex);

Gets the last score for a player, if player index is omitted, returns the last hit for the current player.

SetPlayerScore

void

SetPlayerScore(int score, int playerIndex);

Sets the score for a player, if the player index is omitted, sets the score for the current player.

SetThrowsPerTurn

void

SetThrowsPerTurn(int throws);

Sets the number of throws per player per turn.

SetWinningPlayer

void

SetWinningPlayer(int player);

Sets the player number who won the game. If 0, game is a tie.

TriggerGameEvent

void

TriggerGameEvent(DartGameEvents gameEvent);

Triggers a callback for game events.

GetLastThrowInfo

DartboardThrowInfo

GetLastThrowInfo(int playerIndex)

Gets the last throw info for a player.

RegisterGame

void

RegisterGame(DartGame game)

Registers the game with the Dartboard Manager.

UnregisterGame

void

UnregisterGame(DartGame game)

Unregisters the game with the Dartboard Manager.

GetDartboardManager

DartboardManager

DartboardManager.GetDartboardManager()

Returns the Dartboard Manager. Use only if one Dartboard Manager is in the scene otherwise conflicts will arise. Static function.

Dart Functions

RegisterHit

void

RegisterHit(DartBoardThrowInfo hitInfo);

Informs the manager of a hit on the dartboard.

RegisterMiss

void

RegisterMiss();

Informs the manager of a miss on the dartboard.

Troubleshooting

Oops, something went wrong. You have come to the right place.

1

Problem 

The player throws a dart and misses, but the system does not register the miss.

Answer

Make sure your dart registers a miss automatically if it does not connect with a valid dartboard section. See the API sections on RegisterHit and RegisterMiss and the Dart script.

Support

You can get your question answered by emailing support@vrchewal.com

Thank you for your purchase of Dartboard Manager!