コード例 #1
0
    private async void Start()
    {
        client = new ButtplugUnityClient("Test Client");
        Log("Trying to create client");

        // Set up client event handlers before we connect.
        client.DeviceAdded      += AddDevice;
        client.DeviceRemoved    += RemoveDevice;
        client.ScanningFinished += ScanFinished;

        // Try to create the client.
        try {
            await ButtplugUnityHelper.StartProcessAndCreateClient(client, new ButtplugUnityOptions {
                // Since this is an example, we'll have the unity class output everything its doing to the logs.
                OutputDebugMessages = true,
            });
        }
        catch (ApplicationException e) {
            Log("Got an error while starting client");
            Log(e);
            return;
        }

        await client.StartScanningAsync();
    }
コード例 #2
0
    private async void OnDestroy()
    {
        Devices.Clear();

        // On object shutdown, disconnect the client and just kill the server
        // process. Server process shutdown will be cleaner in future builds.
        if (client != null)
        {
            client.DeviceAdded      -= AddDevice;
            client.DeviceRemoved    -= RemoveDevice;
            client.ScanningFinished -= ScanFinished;
            await client.DisconnectAsync();

            client.Dispose();
            client = null;
        }

        ButtplugUnityHelper.StopServer();
        Log("I am destroyed now");
    }