Description:
This Unity plug-in can be applied to the Android platform to realize the function of connecting Lovense toys and sending control commands.
Compatibility:
Unity version >= 2018.4.0
Scripting Backend: Mono
Api Compatibility Level: *For .Net 4.x the import name is “*_Net4.x*.unitypackage”.
Api Compatibility Level: *For .NetFramework the imported package name is “*.NetFramework*.unitypackage”.
Api Compatibility Level: *For .NetStandard2.1 the imported package name is “*.NetStandard2.1*.unitypackage”
Api Compatibility Level: *For .NetStandard2.0 the imported package name is “*.NetStandard2.0*.unitypackage”
Steps to integrate the plugin:
- Import the appropriate package based on your project’s Api Compatibility Level*.
- After successfully importing the plugin, a new Tools->LovenseAndroidDeveloper menu item will be added to the Unity menu bar. Click to enter and set the developer token, then click Save to save the token. Clicking the “Copy and modify AndroidManifest.xml and gradle file” button will generate the packaged configuration.
At this point, you can quickly start developing using the Android SDK. The LovenseDemo folder is an example, and deleting it does not affect your project. (Because the target API of the Android sdk is 28, be sure to set the Target API Level to 28)
Guide:
1. Search toys
onSearchToyListener = new OnSearchToyListener();
onSearchToyListener.initCallback(onSearchErrorFunc, onSearchToysFunc, onFinishFunc); //Initialize scan callback interface
LovenseAndroidSDK.GetInstance().SearchToys(onSearchToyListener);
2. Stop searching
LovenseAndroidSDK.GetInstance().stopSearching();
3. Connect Toys
OnConnectListener onConnectListener = new OnConnectListener();
onConnectListener.initCallBack(onConnectFunc, onConnectErrorFunc); //Initialize connection callback interface
LovenseAndroidSDK.GetInstance().connectToy(toyId, onConnectListener);
4. Battery monitoring
onCallBackBatteryListener = new OnCallBackBatteryListener();
onCallBackBatteryListener.initCallBack(onCallBackBatteryListenerFunc); //Initialize the callback function
LovenseAndroidSDK.GetInstance().addListener(toyId, onCallBackBatteryListener);
Send query:
LovenseAndroidSDK.GetInstance().SendFunctionWithoutValue(toyId, LovenseCommandType.GET_BATTERY);
5. Get type
onCallBackDeviceType = new OnCallBackDeviceTypListener();
onCallBackDeviceType.initCallBack(onCallBackDeviceTypeListenerFunc); //initialize the callback function
LovenseAndroidSDK.GetInstance().addListener(toyId, onCallBackDeviceType);
Send query:
LovenseAndroidSDK.GetInstance().SendFunctionWithoutValue(toyId, LovenseCommandType.GET_BATTERY);
6. Send Function
Single Function: LovenseAndroidSDK.GetInstance().SendFunction(toyId, command, timeSec, loopRunning, loopPause);
Multiple Functions: LovenseAndroidSDK.GetInstance().SendFunction(toyId, commands, timeSec, loopRunning, loopPause);
command: the type is LovenseAndroidCommand
commands: the type is List
timeSec: total running time
loopRunning: Running time. Use in conjunction with loopPause to control and stop the device.
loopPause: Suspend time. Use in conjunction with the above loopRunning to control and stop the device.
7. Send Pattern
LovenseAndroidSDK.GetInstance().SendPattern(string toyId, List typeList, List valueList, int timeMs, int timeSec);
typeList: the type of command, the type is List
valueList: a list of intensity changes, the type is List
timeMs: how often to change the intensity, time unit: milliseconds
timeSec: total running time, time unit: seconds
8. Send Preset
LovenseAndroidSDK.GetInstance().SendPreset(string toyId, int mode, int timeSec);
There are currently four presets:
mode=0 earthquake mode
mode=1 fireworks mode
mode=2 pulse mode
mode=3 wave mode
timeSec: total running time, time unit: seconds
9. Stop Toys
LovenseAndroidSDK.GetInstance().StopAll(string toyId);