BrainBit for developers Subscribe for updates Visit website

Unity

Samples - GitLab

The latest version is `1.0.7`.

Available for iOS, Android, Windows, MacOS platforms

1. Open Package Manager
2. Click "Add" menu and choose "Add package from GIT url...". A text box and an Add button appear.
3. Enter a "https://github.com/BrainbitLLC/unity_neurosdk2.git" in the text box and click Add.

 

If Unity was able to install the package successfully, the package now appears in the package list with the tag. If Unity was not able to install the package, the Unity Console displays an error message.

 

For Android platform ask for Bluetooth and Location permission before use:

    
#if UNITY_ANDROID
            if (SystemInfo.operatingSystem.Contains("31") ||
                SystemInfo.operatingSystem.Contains("32") ||
                SystemInfo.operatingSystem.Contains("33"))
            {
                Permission.RequestUserPermission("android.permission.BLUETOOTH_SCAN");
                Permission.RequestUserPermission("android.permission.BLUETOOTH_CONNECT");
            }
            else
            {
                Permission.RequestUserPermission("android.permission.ACCESS_FINE_LOCATION");
                Permission.RequestUserPermission("android.permission.ACCESS_COARSE_LOCATION");
            }
#endif
    

 

For Android you need to add permissions to use geolocation and bluetooth to the manifest. You can read more about this on AndroidDeveloper.

Firstly, enable custom `AndroidManifest`:
1. Go to `PlayerSettings`
2. Open `Android` tab, then find `PublishingSettings`, then find `Build` part
3. Enable `Custom Main Manifest` option
4. Add permissions into it:

    
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" tools:targetApi="31" android:usesPermissionFlags="neverForLocation" />
    

 

For iOS/MacOs you need to add a key to `Info.plist` because it uses Bluetooth too:

    
public sealed class BuilderPostProcessor
{
    [PostProcessBuild(1)]
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
#if UNITY_IOS
        if (target == BuildTarget.iOS)
        {
            var infoPlist = new PlistDocument();
            var infoPlistPath = path + "/Info.plist";
            infoPlist.ReadFromFile(infoPlistPath);

            PlistElementDict dict = infoPlist.root.AsDict();
            dict.SetString("NSBluetoothAlwaysUsageDescription", "App requires access to Bluetooth to allow you connect to device");
            dict.SetString("NSBluetoothPeripheralUsageDescription", "App uses Bluetooth to connect with your Brainbit device");
            infoPlist.WriteToFile(infoPlistPath);
        }
#endif
    }
}
    

 

After build you need to change Embed type to `neurosdk2.framework` from `Embed Without Signing` to `Embed & Sign` into `Unity-iPhone` module.