What is the best way to decouple your code from Unity Classes like Input using Zenject?

Since a lot of unity systems require you to make static calls to methods like the Input system I wonder what would be a good way to decouple your code from those systems. The obvious and tedious way would be to wrap them inside classes that you can then inject with zenject. I wonder if there is an easier way to do so?

Posted Nov 16, 2017, 6:14 PM UTC

20
Zammy_bg•

No. Exactly what you want to do. If you want to unit test it will need to be through interfaces.

1
Luisoft•

You have no more option than wrap them and creating a nice interface. You can search for good looking interfaces for your systems such as Input. Anyway, I think is ok to couple your MonoBehaviours to Unity since MB itself is part of it. You may want to have every other class clean of the engine.

1