To understand how you can use Uduino with existing libraries, two tutorials on this website explains the basic concept.

Send commands from Unity to Arduino

Advanced write tutorial

Use library that reads the value of a complex sensor

Advanced read tutorial

Use Uduino with custom libraries

The process to use Uduino with custom libraries is fairly simple:

  1. Get the library working without Uduino
  2. Use the minimal and empty Uduino template
  3. Copy / paste the sketch that works your new Uduino sketch
  4. Replace Serial.print by uduino.print and the delay() by uduino.delay
  5. Remove any Serial.available() and use the uduino.addCommand() functions

If you need inspiration, have a look at the projects!

Important note on the use of delay() and Serial.print()

TLDR; Remove the Serial.print and delay from your code !

If you use delay() in your sketch, it will pause your sketch for some ms. Hence the connection between Unity and Arduino will not work smoothly; for instance, a message sent will be waiting in your serial buffer.
If you want to use delay, you should use the function uduino.delay(), that works similarly to the Arduino delay function but maintain the Uduino connection open.

Similarly, you should know that every Serial.print() that you use in your loop is susceptible to be read by Unity. hence I recommend to remove unnecessary print and only use uduino.print()when you want to send a variable.