mapbox / mapbox-sdk-cs

C# libraries for Mapbox API layer
https://mapbox.github.io/mapbox-sdk-cs/
Other
20 stars 11 forks source link

Implement non threaded HTTPRequest #74

Open wilhelmberg opened 7 years ago

wilhelmberg commented 7 years ago

To make the Location Search widget work when Unity Editor is not playing we might need a non-threaded implementation of HTTPRequest. Or, find a way how to get back to the main thread without the message pump being called via Update().

david-rhodes commented 7 years ago

I suspect this will need to be implemented in the Unity layer.

See:

IEnumerator ValidateToken(string token)
        {
            _lastAccessToken = token;

            // TODO: implement safer url formatting?
            var www = new WWW("https://api.mapbox.com/tokens/v2?access_token=" + token);
            while (!www.isDone)
            {
                yield return 0;
            }
            var json = www.text;
            if (!string.IsNullOrEmpty(json))
            {
                ParseTokenResponse(json);
            }
        }

In MapboxConfigurationWindow.cs for an example. This worked here because the url is hardcoded and not abstracted in the cs layer. That said, I think we can just use the old HTTPRequest for editor and decide which version to delegate to in MapboxAccess.

david-rhodes commented 7 years ago

Alternatively, you should be able to hook into the editor's update: http://answers.unity3d.com/questions/39313/how-do-i-get-a-callback-every-frame-in-edit-mode.html.