Can I add custom button to toolbar of Unity Editor?

I want to add a button / custom UI element in the space next to “Play” button. Is that doable? If so how?

Short answer: NO.

Long answer:

If you really want to do this you will have to hack UnityEditor.dll. You can do this using Mono.Cecil.
But first you need to find the code which draws this part of the interface. This is easy using ILSpy because Unity doesn’t obfuscate its DLLs.

The code is to be found in UnityEditor.Toolbar class DoPlayButtons method. Using Mono.Cecil you could inject your own code to draw custom UI elements after Play/Pause buttons and compile your own UnityEditor.dll. But this approach is not scalable. You will have to patch it every time Unity releases a new version and it will be hard to distribute.

@valyard 's answer is right, but, it can be scalable if you use cecil to dynamic inject the “UnityEditor.dll” replace static hack the dll

@Paulius-Liekis @valyard
Yes you can and it’s really easy