Created by: justonia
This PR is a working implementation of a library plugin for the csharp-netcore client generator that utilizes UnityWebRequest
as the request backend.
Why, when RestSharp and HttpClient work in Unity? Cross-platform nightmares -- especially consoles.
Limitations (as specific as I can be due to NDA):
- Console A - Anything except UnityWebRequest doesn't support access to the platform's SSL certificate store. You have to embed certificates at build time and apply for a special waiver to use them. This then becomes a ticking time bomb because your root certs can expire while your game is in the wild.
- Console B - With no exception, requires you to use UnityWebRequest since it integrates natively with the platform's custom version of libcurl that all games must use.
- Console C - Use whatever you want! Villagers rejoice.
- File parameters cannot be supported everywhere. Some consoles and tvOS do not support either
Application.persistentDataPath
or will refuse to compile/link if you even referenceGetTempPath
as well. - Setting cookies are not supported in WebGL platform
- UnityWebRequest also offers native performance with much less garbage usage. It's worth noting that the current Unity GC is still a very old one and even with incremental GC support it's still problematic on min-spec devices.
I am genuinely not sure how to proceed with this as a PR that could be considered for integration. First off, unit tests would require a Unity project, and secondly, I'm sure some of the changes I've made might be controversial.
The backend I've written also adds better result handling and provides additional exceptions that let you know when an API call failure is due to a connection error. The latter is a must-have distinction because console cert processes will fail you if your error messages are not exactly specific as to what happened (e.g. no "something went wrong" when you have no internet).
This backend only has one C# dependency that isn't default in Unity (or available via package manager like JSON.net): System.ComponentModel.DataAnnotations.dll
.