WhizToys SDK (Unity) Documentation
- SDK Version: TBD
- Supported Unity Version: TBD
- Android Minimum Version: TBD
- iOS Minimum Version: TBD
Installation
Download the SDK: Whiztoys_SDK.unitypackage (Google Drive)
Add the SDK to your Unity project:
- Import
Whiztoys_SDK.unitypackageinto your project.
Example Scenes
NormalDemo
The most basic example, including grid layout, pressure detection, color display, and more.
Muti_Demo
An example that supports connecting to multiple controllers.
Rotate_Demo (requires grid larger than 2x2)
Uses a 2x2 block as the play area, demonstrating rotation and designating specific blocks as the working area.
Quick Start
Initialization
To use the SDK, first create an instance of the WhizToys class and call the Initialize method to initialize the Bluetooth module:
WhizToys whizToys = new WhizToys();
whizToys.Initialize();
After initialization, you need to register callback functions for each event you want to use:
whizToys.OnInitSuccess = () => { print("Initialization successful"); };
whizToys.OnScanDevice = OnScanDevice;
whizToys.OnScanEnd = OnScanEnd;
whizToys.OnConnected = OnConnected;
whizToys.OnDisconnect = () => { print("Connection lost"); };
whizToys.OnReceiveSignal = OnReceiveSignal;
Scanning for Devices
Start scanning for available controllers:
whizToys.StartScan(5); // Scan for 5 seconds
Connecting to a Device
Connect to a discovered device:
whizToys.Connect(address); // Bluetooth address
When a device is found during scanning, the device information is sent as <string address, string deviceName>:
private void OnScanDevice(string address, string deviceName)
{
}
Grid Layout
After a successful connection, the SDK sends the layout to the user via OnConnected:
private void OnConnected(WhizToysMap whizToysMap)
{
// Use this to operate on the grid layout
}
Changing Colors
To change colors, use List<WhizToysSendModel>, and the colorIndex must correspond to the color table.
Below is an example of setting all tiles to a specific color:
public void WriteColor(int colorIndex)
{
List<WhizToysSendModel> sendModels = new List<WhizToysSendModel>();
int rows = _whizToysMap.Layout.Row;
int columns = _whizToysMap.Layout.Column;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
if (_whizToysMap.Blocks[i, j].Active)
{
WhizToysSendModel sendModel = new WhizToysSendModel();
sendModel.Layout.Row = i;
sendModel.Layout.Column = j;
sendModel.ColorIndex = colorIndex;
sendModel.LightMode = LightModeType.All;
sendModel.CommandMode = CommandModeType.Immediately;
sendModel.FeedBackMode = FeedBackModeType.Basic;
sendModel.ShowTimeMode = ShowTimeModeType.Short;
sendModels.Add(sendModel);
}
}
}
whizToys.WriteSignals(sendModels);
}
Receiving Pressure Signals
The SDK sends List<WhizToysSignal>, and the user needs to handle it with the corresponding callback function.
Pressure is divided into 3 levels and has 4 corners, where int[] represents top-left, bottom-left, bottom-right, and top-right respectively.
Below is an example:
private void OnReceiveSignal(List<WhizToysSignal> values)
{
for (int i = 0; i < values.Count; i++)
{
WhizToysSignal whizToysSignal = values[i];
int row = whizToysSignal.Layout.Row;
int column = whizToysSignal.Layout.Column;
PressBlock pressBlock = _pressBlocks[row, column];
int[] pressures = whizToysSignal.Pressures;
for (int j = 0; j < pressures.Length; j++)
pressBlock.blocks[j].color = ConvertColor(pressures[j]);
}
}
Data Structures
WhizToysLayout
Defines the position of a tile.
public struct WhizToysLayout
{
public int Row;
public int Column;
public bool Compare(WhizToysLayout layout) // Compares whether two positions are the same
}
WhizToysBlock
Defines the state of a tile.
public class WhizToysBlock
{
public readonly bool Active; // Whether it is active; if the tile is physically absent, this will be False
public bool IsPressure // Whether there is pressure (stepped on)
public bool AllPressure // All four corners are pressed simultaneously
public bool IsLeft // Top-left and bottom-left are pressed
public bool IsRight // Top-right and bottom-right are pressed
public bool IsUp // Top-left and top-right are pressed
public bool IsDown // Bottom-left and bottom-right are pressed
}
WhizToysMap
Defines the grid arrangement.
public class WhizToysMap
{
public WhizToysLayout Layout; // Row and Column here represent the total count
public WhizToysBlock[,] Blocks;
}
WhizToysSendModel
Format used for changing colors.
public class WhizToysSendModel
{
public WhizToysLayout Layout;
public int ColorIndex; // Color must correspond to the color table
public LightModeType LightMode = LightModeType.All; // See reference table below
public CommandModeType CommandMode = CommandModeType.Immediately; // See reference table below
public FeedBackModeType FeedBackMode = FeedBackModeType.Basic; // See reference table below
public ShowTimeModeType ShowTimeMode = ShowTimeModeType.Short; // See reference table below
}
WhizToysSignal
Format used for receiving pressure data.
public class WhizToysSignal
{
public WhizToysLayout Layout;
// Pressure order: 0: top-left, 1: bottom-left, 2: bottom-right, 3: top-right.
// Pressure has 4 levels: 0: no pressure, 1: light pressure, 2: medium pressure, 4: strong pressure
public int[] Pressures;
}
Available Events
OnInitSuccess
Triggered when initialization succeeds.
Usage:
public void OnInitSuccess(){}
whizToys.OnInitSuccess = OnInitSuccess;
OnScanDevice
Triggered when a device is detected during scanning.
Usage:
public void OnScanDevice(string address, string deviceName){}
whizToys.OnScanDevice = OnScanDevice;
OnScanEnd
Triggered when the scan duration has elapsed.
Usage:
public void OnScanEnd(){}
whizToys.OnScanEnd = OnScanEnd;
OnConnected
Triggered when successfully connected to a device.
Usage:
public void OnConnected(WhizToysMap whizToysMap){}
whizToys.OnConnected = OnConnected;
OnDisconnect
Triggered when the device disconnects.
Usage:
public void OnDisconnect(){}
whizToys.OnDisconnect = OnDisconnect;
OnReceiveSignal
Triggered when a pressure signal is received.
Usage:
public void OnReceiveSignal(List<WhizToysSignal>){}
whizToys.OnReceiveSignal = OnReceiveSignal;
Color Change Settings
LightModeType (enum)
Describes the LED lighting position. When set to "All", regardless of which sensor is stepped on, all 4 LEDs will light up together.
- All -> All LEDs light up
- LeftUp -> Top-left lights up individually
- LeftDown -> Bottom-left lights up individually
- RightUp -> Bottom-right lights up individually
- RightDown -> Top-right lights up individually
- Only -> All light up individually
CommandModeType
Describes the trigger mechanism -- whether to display feedback immediately when a command is issued.
- Immediately -> Trigger feedback immediately
- AfterClick -> Trigger after being stepped on
FeedBackModeType
Describes the feedback mode when stepped on. When not in feedback mode, issued commands will directly control the LED on/off state.
- None -> Not specified (indicates feedback mode is not currently being set)
- ClickNone -> No feedback on step
- Basic -> Basic
- Flash -> Flash
- Marquee -> Marquee
- Breathe -> Breathing light
- Neon -> Neon light
ShowTimeModeType
Describes the feedback duration. Applies to the duration of flash and marquee effects.
- Short -> Short
- Long -> Long
Color Table
| Red (R) | Green (G) | Blue (B) | Index | Color |
|---|---|---|---|---|
| 0 | 0 | 0 | 00 | |
| 255 | 0 | 0 | 01 | Red |
| 255 | 25 | 0 | 02 | |
| 255 | 50 | 0 | 03 | |
| 255 | 75 | 0 | 04 | |
| 255 | 100 | 0 | 05 | |
| 255 | 125 | 0 | 06 | |
| 255 | 150 | 0 | 07 | |
| 255 | 175 | 0 | 08 | |
| 255 | 200 | 0 | 09 | |
| 255 | 225 | 0 | 10 | |
| 255 | 255 | 0 | 11 | Yellow |
| 225 | 255 | 0 | 12 | |
| 200 | 255 | 0 | 13 | |
| 175 | 255 | 0 | 14 | |
| 150 | 255 | 0 | 15 | |
| 125 | 255 | 0 | 16 | |
| 100 | 255 | 0 | 17 | |
| 75 | 255 | 0 | 18 | |
| 50 | 255 | 0 | 19 | |
| 25 | 255 | 0 | 20 | |
| 0 | 255 | 0 | 21 | Green |
| 0 | 255 | 25 | 22 | |
| 0 | 255 | 50 | 23 | |
| 0 | 255 | 75 | 24 | |
| 0 | 255 | 100 | 25 | |
| 0 | 255 | 125 | 26 | |
| 0 | 255 | 150 | 27 | |
| 0 | 255 | 175 | 28 | |
| 0 | 255 | 200 | 29 | |
| 0 | 255 | 225 | 30 | |
| 0 | 255 | 255 | 31 | Cyan |
| 0 | 225 | 255 | 32 | |
| 0 | 200 | 255 | 33 | |
| 0 | 175 | 255 | 34 | |
| 0 | 150 | 255 | 35 | |
| 0 | 125 | 255 | 36 | |
| 0 | 100 | 255 | 37 | |
| 0 | 75 | 255 | 38 | |
| 0 | 50 | 255 | 39 | |
| 0 | 25 | 255 | 40 | |
| 0 | 0 | 255 | 41 | Blue |
| 25 | 0 | 255 | 42 | |
| 50 | 0 | 255 | 43 | |
| 75 | 0 | 255 | 44 | |
| 100 | 0 | 255 | 45 | |
| 125 | 0 | 255 | 46 | |
| 150 | 0 | 255 | 47 | |
| 175 | 0 | 255 | 48 | |
| 200 | 0 | 255 | 49 | |
| 225 | 0 | 255 | 50 | |
| 255 | 0 | 255 | 51 | Purple |
| 255 | 0 | 225 | 52 | |
| 255 | 0 | 200 | 53 | |
| 255 | 0 | 175 | 54 | |
| 255 | 0 | 150 | 55 | |
| 255 | 0 | 125 | 56 | |
| 255 | 0 | 100 | 57 | |
| 255 | 0 | 75 | 58 | |
| 255 | 0 | 50 | 59 | |
| 255 | 0 | 25 | 60 | |
| 255 | 255 | 255 | 61 | White |