Unity Plugin - iOS SDK
Introduction
This Unity plug-in can be applied to iOS platform for connecting Lovense toys and sending control commands.
Compatibility
Unity version: >= 2019.4.0
Api Compatibility Level:
- For
.Net 4.x
, the import package name isiOSPlugin_.Net4.x.unitypackage
. - For
.Net Framework
, the import package name isiOSPlugin_.NetFramework.unitypackage
. - For
.Net Standard 2.0
, the import package name isiOSPlugin_.NetStandard2.0.unitypackage
. - For
.Net Standard 2.1
, the import package name isiOSPlugin_.NetStandard2.1.unitypackage
.
Import the plugin
Download the plugin package from here. The latest version of the current plugin is V1.2 click to view version records
iOSPlugin_.Net4.x.unitypackage
iOSPlugin_.NetFramework.unitypackage
Import the appropriate package based on your project's Api Compatibility Level.
Select all options and click import.
After importing, you need to click Tools ->LovenseiOSDevelopment on the toolbar, enter the developer token, click "Save"
The file Assets/StreamingAssets/LovenseToySupportConfig.json is the configuration file for the toy support directive, and the version field represents the version of the information.
The current latest version is 1.3
. If it is older than this version, it is recommended to download and replace the file.
Dowload: LovenseToySupportConfig.json
The LovenseDemo folder is an example that you can refer to. Removing it won't affect the functionality.
You need to add NSBluetoothAlwaysUsageDescription and NSBluetoothPeripheralUsageDescription to the xcode project yourself.
Guide
1. Search toys.
public class YourLovenseToyUI: MonoBehaviour {
// do search
private void DoSearch() {
LovenseiOSSDK.GetInstance().SearchToys();
}
//call back Function,parames is LovenseiOSToy
private void OnGetToysEvent(LovenseiOSToy newToy){
//do something when get a new toy
}
void Awake(){
// Add listener
LovenseiOSSDK.oniOSGetToysEvent.AddListener(OnGetToysEvent);
}
void OnDestory() {
// Remove listener
LovenseiOSSDK.oniOSGetToysEvent.RemoveListener(OnGetToysEvent);
}
}
2. Stop searching for toys
public class YourLovenseToyUI: MonoBehaviour {
// do stop search
private void Dostop() {
LovenseiOSSDK.GetInstance().StopSearch();
}
}
3. Connect or DisConnect Toys
public class YourLovenseToyUI: MonoBehaviour {
// do connect
private void Connect(List<string> toyIds) {
LovenseiOSSDK.GetInstance().ConnectToys(toyIds)();
}
//do disconnect
private void DisConnect(List<string> toyIds) {
LovenseiOSSDK.GetInstance().DisConnectToys(toyIds)();
}
//call back function,
private void OnToysConnectEvent(string toyId, int status, string msg){
//do something
}
void Awake(){
// Add listener
LovenseiOSSDK.oniOSConnectEvent.AddListener(OnToysConnectEvent);
}
void OnDestory() {
// Remove listener
LovenseiOSSDK.oniOSConnectEvent.RemoveListener(OnToysConnectEvent);
}
}
4. Battery monitoring
public class YourLovenseToyUI: MonoBehaviour {
//do get a toy's battery
private void GetBattery(string toyId) {
LovenseiOSSDK.GetInstance().SendFunctionWithoutValue(toyId,LovenseCommandType.GET_BATTERY );
}
//call back Function,parameters type is (string,int)
private void onCallBackBatteryListenerFunc(string toyId, int battery){
//do something
}
void Awake(){
// Add listener
LovenseiOSSDK.oniOSGetBatteryEvent.AddListener(onCallBackBatteryListenerFunc);
}
void OnDestory() {
// Remove listener
LovenseiOSSDK.oniOSGetBatteryEvent.RemoveListener(onCallBackBatteryListenerFunc);
}
}
5. Obtain parameters such as device type
public class YourLovenseToyUI: MonoBehaviour {
//do obtain parameters
private void GetToyType(string toyId) {
LovenseiOSSDK.GetInstance().SendFunctionWithoutValue(toyId,LovenseCommandType.GET_DEVICETYPE );
}
//callback function,parameters type is (string,string)
public void onCallBackDeviceTypListenerFunc(string toyId, string type){
}
void Awake(){
// Add listener
LovenseiOSSDK.oniOSGetTypeEvent.AddListener(onCallBackDeviceTypListenerFunc);
}
void OnDestory() {
// Remove listener
LovenseiOSSDK.oniOSGetTypeEvent.RemoveListener(onCallBackDeviceTypListenerFunc);
}
}
6. Send functions commands
public class YourLovenseToyUI: MonoBehaviour {
//do obtain parameters
private void SendFunctions(List<string> toyIds, List<LovenseCommand> commands, float timeSec, float loopRunningSec, float loopPauseSec) {
LovenseiOSSDK.GetInstance().SendFunctions(toyIds, commands, timeSec, loopRunningSec, loopPauseSec);
}
//callback function
private void OnToysCommandEvent(string toyId, int status, string msg){
}
void Awake(){
// Add listener
LovenseiOSSDK.oniOSCommandEvent.AddListener(OnToysCommandEvent);
}
void OnDestory() {
// Remove listener
LovenseiOSSDK.oniOSCommandEvent.RemoveListener(OnToysCommandEvent);
}
}
7. Send patterns commands
public class YourLovenseToyUI: MonoBehaviour {
//do
private void SendPattern(List<string> toyIds, List<LovenseCommandType> typeList, List<int> strengthValues, float timeSec, int intervalsMs) {
LovenseiOSSDK.GetInstance().SendPattern(toyIds, typeList, strengthValues, timeSec, intervalsMs);
}
//callback function,
private void OnToysCommandEvent(string toyId, int status, string msg){
}
void Awake(){
// Add listener
LovenseiOSSDK.oniOSCommandEvent.AddListener(OnToysCommandEvent);
}
void OnDestory() {
// Remove listener
LovenseiOSSDK.oniOSCommandEvent.RemoveListener(OnToysCommandEvent);
}
}
8. Send preset commands
public class YourLovenseToyUI: MonoBehaviour {
//do obtain parameters
private void List<string> toyIds, int mode, float timeSec) {
LovenseiOSSDK.GetInstance().SendPreset(toyId, mode, timeSec);
}
//callback function,
private void OnToysCommandEvent(string toyId, int status, string msg){
}
void Awake(){
// Add listener
LovenseiOSSDK.oniOSCommandEvent.AddListener(OnToysCommandEvent);
}
void OnDestory() {
// Remove listener
LovenseiOSSDK.oniOSCommandEvent.RemoveListener(OnToysCommandEvent);
}
}
9. Stop toys
//do
private void StopToys(List<string> toyIds) {
LovenseiOSSDK.GetInstance().StopAll(toyIds);
}
//callback function,
private void OnToysCommandEvent(string toyId, int status, string msg){
}
void Awake(){
// Add listener
LovenseiOSSDK.oniOSCommandEvent.AddListener(OnToysCommandEvent);
}
void OnDestory() {
// Remove listener
LovenseiOSSDK.oniOSCommandEvent.RemoveListener(OnToysCommandEvent);
}
Interface
LovenseiOSSDK
Method
GetInstance
Description:
Get the singleton instance of LovenseiOSSDK
Parameters: None
Return:
LovenseiOSSDK instance
SearchToys
Description:
Search for the toys, when a toy is discovered, the oniOSGetToysEvent event will be triggered.
Parameters: None
Return: None
ConnectToys
Description:
Connect the toys, when a toy's Connection status is changed, the oniOSConnectEvent event will be triggered.???
Parameters:
Name Type Default Required Description toyIds List<string> yes The toys you want to connect Return: None
SendFunctions
Description:
Send Function commands to the toys.
Parameters:
Name Type Default Required Description toyIds List<string> yes The toys you want to control commands List<LovenseCommand> yes See LovenseCommand timeSec float yes The total runtime in second, "0" = indefinite time length. loopRunningSec float 0
no time running for each command loop in second loopPauseSec float 0
no time gap for each command loop in second Return: None
SendPattern
Description:
Send a series of Functions to the toys, they will execute all the Functions in
types
according to the order of the level invalues
with the interval ofintervalsMs
.Parameters:
Name Type Default Required Description toyIds List<string> yes The toys you want to control types List<LovenseCommandType> yes See LovenseCommandType strengthValues List<int> yes The order of the levels timeSec float yes The total runtime in second, "0" = indefinite time length. intervalsMs int 150 no The level interval in milliseconds, should be greater than 100, default 150 Return: None
SendPreset
Description:
Send a preset command to the toys.
Parameters:
Name Type Default Required Description toyIds List<string> yes The toys you want to control mode int yes The preset name to send, we provide four preset patterns : 0: earthquake
,1:fireworks
,2:pulse
,3:wave
timeSec float yes The total runtime in second, "0" = indefinite time length Return: None
StopAll
Description:
Stop Toy's action.
Parameters:
Name Type Description toyIds List<string> The toys you want to stop Return: None
GetSupportCommandsByType(string type)
Description:
Obtain Command types supported by toys through their types
Parameters:
Name Type Description type string the type of toy Return: List<LovenseCommandType>
Event
oniOSGetToysEvent
Description:
Triggered when the toys is discovered.
Callback Parameters:
Name Type Description newToy LovenseiOSToy The new toy which is recently discovered
oniOSGetBatteryEvent
Description:
Triggered when a toy's battery is obtained.
Callback Parameters:
Name Type Description toyId string The toy's id battery int battery
oniOSGetTypeEvent
Description:
Triggered when a toy's type is obtained.
Callback Parameters:
Name Type Description toyId string The toy's id type string The toy's type
oniOSConnectEvent
Description:
Triggered when the toy's connection status has changed.
Callback Parameters:
Name Type Description toyId string The toy's id status int The toy's connection status,If equals to 1, it represents successful connection status, while others represent not connected msg string prompt for not currently connected
oniOSCommandEvent
Description:
Triggered when sending commands is complete.
Callback Parameters:
Name Type Description toyId string The toy's id status int If equal to 1, it represents successful execution, while others represent unsuccessful execution msg string prompt for not executed
LovenseiOSToy
Description:
The connection information and status of the Toy
Properties:
Name Type Description name bool The name of the toy identifier string The identifier of the toy type int The type of the toy version int The version of the toy isConnected bool The connection status of the toy rssi int The rssi of the toy battery int The battery of the toy
LovenseCommand
Description:
The toy control command
Properties:
Name Type Description type LovenseCommandType See below value int Function level
Function Level:
Type | Range |
---|---|
VIBRATE | 0 - 20 |
VIBRATE1 | 0 - 20 |
VIBRATE2 | 0 - 20 |
VIBRATE3 | 0 - 20 |
ROTATE | 0 - 20 |
PUMP | 0 - 3 |
FINGERING | 0 - 20 |
DEPTH | 0 - 3 |
THRUSTRING | 0 - 20 |
GET_DEVICETYPE | |
GET_BATTERY |
LovenseCommandType
Description:
The enum of the toy function type.
Enum:
Value VIBRATE VIBRATE1 VIBRATE2 VIBRATE3 ROTATE PUMP THRUSTRING FINGERING DEPTH GET_DEVICETYPE GET_BATTERY
The DEPTH command is a setting command that requires the THRUSTRING command to take effect.
Version Records
[Version1.2] - 2023-11-15
1.Add Vibrate3 and Depth commands.
2.Command sending optimization.
3.Update the configuration file to version1.3.
[Version1.1] - 2023-09-12
1.Add a function that can query toy support instructions
2.Change type of 'strengthValues' int[] to List<int> in pattern function
3.Change time type int to float.
[Version1.0] - 2023-08-20
1.Functions
2.Pattern
3.Preset
4.Connect/DisConnect
5.Type/Battery