Mapbox V3 bricking non mobile builds, MapboxContext looks like the culprit
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 38/100
- Type d'issue
- Bug
- Clarté
- À clarifier
- Activité
- Active
- Domaine
- build-system, game-dev, mobile-dev
Piste de recherche
Start with the MapboxContext entry points named in the issue, especially Initialize(), GetSkuToken(), LoadAndParseConfig(), and LoadConfigurationCoroutine(). Reproduce both the non-mobile server build failure and the iOS loading-screen failure, then inspect the platform directives and configuration flow. Done means Mapbox V3 supports the server build while maps and geolocation still load on iOS.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
So I have been building a game with both a multiplayer component and an online multiplayer component.
I have a server build that I have to create and as is it would refuse to build for non mobile builds with Mapbox V3 installed.
It points to the following methods in MapboxContext when building:
Initialize()
GetSkuToken()
LoadAndParseConfig()
HandleTokenResponse(MapboxConfiguration config, MapboxToken response)
LoadConfigurationCoroutine(bool validateToken = true)
So I had a bright idea, why don't I use a #if with the relevant platforms that use it and turn it off these method with the platforms that don't.
So I went through the script and used the #if for each platform.
This is the modified MapboxContext script:
using System;
using System.Collections;
using System.IO;
using Mapbox.BaseModule;
using Mapbox.BaseModule.Telemetry;
using Mapbox.BaseModule.Utilities;
using UnityEngine;
namespace Mapbox.BaseModule.Map
{
public class MapboxContext : IMapboxContext
{
public MapboxConfiguration Configuration;
private ITelemetryLibrary _telemetryLibrary;
private MapboxToken _mapboxToken;
private string _tokenNotSetErrorMessage = "No configuration file found! Configure your access token from the Mapbox > Setup menu.";
public MapboxContext()
{
}
public IEnumerator Initialize()
{
#if UNITY_ANDROID
yield return LoadConfigurationCoroutine();
#elif Unity_IOS
yield return LoadConfigurationCoroutine();
#elif UNITY_EDITOR
yield return LoadConfigurationCoroutine();
#else
#endif
yield return null;
}
public string GetAccessToken()
{
return Configuration.AccessToken;
}
public string GetSkuToken()
{
#if UNITY_ANDROID
return Configuration.GetMapsSkuToken();
#elif Unity_IOS
return Configuration.GetMapsSkuToken();
//Debug.LogError("this is apple");
#elif UNITY_EDITOR
return Configuration.GetMapsSkuToken();
#endif
return "bums";
}
public MapboxTokenStatus TokenStatus()
{
if (_mapboxToken == null)
return MapboxTokenStatus.StatusNotYetSet;
return _mapboxToken.Status;
}
private MapboxConfiguration LoadAndParseConfig()
{
#if UNITY_ANDROID
TextAsset configurationTextAsset = Resources.Load<TextAsset>(Constants.Path.MAPBOX_RESOURCES_RELATIVE);
if (null == configurationTextAsset)
{
Debug.LogError("Need Mapbox Access Token");
throw new Exception();
}
var config = JsonUtility.FromJson<MapboxConfiguration>(configurationTextAsset.text);
config.Initialize();
return config;
#elif Unity_IOS
TextAsset configurationTextAsset = Resources.Load<TextAsset>(Constants.Path.MAPBOX_RESOURCES_RELATIVE);
if (null == configurationTextAsset)
{
Debug.LogError("Need Mapbox Access Token");
throw new Exception();
}
var config = JsonUtility.FromJson<MapboxConfiguration>(configurationTextAsset.text);
config.Initialize();
return config;
#elif UNITY_EDITOR
TextAsset configurationTextAsset = Resources.Load<TextAsset>(Constants.Path.MAPBOX_RESOURCES_RELATIVE);
if (null == configurationTextAsset)
{
Debug.LogError("Need Mapbox Access Token");
throw new Exception();
}
var config = JsonUtility.FromJson<MapboxConfiguration>(configurationTextAsset.text);
config.Initialize();
return config;
#endif
return null;
}
private void HandleTokenResponse(MapboxConfiguration config, MapboxToken response)
{
#if UNITY_ANDROID
_mapboxToken = response;
Configuration = config;
if (_mapboxToken.Status != MapboxTokenStatus.TokenValid)
{
config.AccessToken = string.Empty;
Debug.LogError("Invalid Token");
}
else
{
ConfigureTelemetry();
}
#elif Unity_IOS
_mapboxToken = response;
Configuration = config;
if (_mapboxToken.Status != MapboxTokenStatus.TokenValid)
{
config.AccessToken = string.Empty;
Debug.LogError("Invalid Token");
}
else
{
ConfigureTelemetry();
}
#elif UNITY_EDITOR
_mapboxToken = response;
Configuration = config;
if (_mapboxToken.Status != MapboxTokenStatus.TokenValid)
{
config.AccessToken = string.Empty;
Debug.LogError("Invalid Token");
}
else
{
ConfigureTelemetry();
}
#endif
}
private const float TokenValidationTimeoutSeconds = 10f;
public IEnumerator LoadConfigurationCoroutine(bool validateToken = true)
{
#if UNITY_ANDROID
var config = LoadAndParseConfig();
if (validateToken)
{
var tokenValidator = new MapboxTokenApi();
var configLoaded = false;
tokenValidator.Retrieve(config.GetMapsSkuToken, config.AccessToken, (response) =>
{
HandleTokenResponse(config, response);
configLoaded = true;
});
var elapsed = 0f;
while (!configLoaded)
{
elapsed += Time.deltaTime;
if (elapsed >= TokenValidationTimeoutSeconds)
{
Debug.LogError("Token validation timed out. Proceeding with unvalidated configuration.");
Configuration = config;
break;
}
yield return null;
}
}
else
{
Configuration = config;
}
#elif Unity_IOS
var config = LoadAndParseConfig();
if (validateToken)
{
var tokenValidator = new MapboxTokenApi();
var configLoaded = false;
tokenValidator.Retrieve(config.GetMapsSkuToken, config.AccessToken, (response) =>
{
HandleTokenResponse(config, response);
configLoaded = true;
});
var elapsed = 0f;
while (!configLoaded)
{
elapsed += Time.deltaTime;
if (elapsed >= TokenValidationTimeoutSeconds)
{
Debug.LogError("Token validation timed out. Proceeding with unvalidated configuration.");
Configuration = config;
break;
}
yield return null;
}
}
else
{
Configuration = config;
}
#elif UNITY_EDITOR
var config = LoadAndParseConfig();
if (validateToken)
{
var tokenValidator = new MapboxTokenApi();
var configLoaded = false;
tokenValidator.Retrieve(config.GetMapsSkuToken, config.AccessToken, (response) =>
{
HandleTokenResponse(config, response);
configLoaded = true;
});
var elapsed = 0f;
while (!configLoaded)
{
elapsed += Time.deltaTime;
if (elapsed >= TokenValidationTimeoutSeconds)
{
Debug.LogError("Token validation timed out. Proceeding with unvalidated configuration.");
Configuration = config;
break;
}
yield return null;
}
}
else
{
Configuration = config;
}
#endif
yield return null;
}
private void ConfigureTelemetry()
{
//TODO: enable after token validation has been made async
if (
null == Configuration ||
string.IsNullOrEmpty(Configuration.AccessToken) ||
_mapboxToken.Status != MapboxTokenStatus.TokenValid
)
{
Debug.LogError(_tokenNotSetErrorMessage);
return;
}
try
{
_telemetryLibrary = TelemetryFactory.GetTelemetryInstance();
_telemetryLibrary.Initialize(Configuration.AccessToken);
_telemetryLibrary.SetLocationCollectionState(Configuration.TelemetryEnabled);
_telemetryLibrary.SendTurnstile();
_telemetryLibrary.SendSdkEvent();
}
catch (Exception ex)
{
Debug.LogErrorFormat("Error initializing telemetry: {0}", ex);
}
}
public void ValidateToken(Action callback = null)
{
var tokenValidator = new MapboxTokenApi();
tokenValidator.Retrieve(GetSkuToken, GetAccessToken(), (response) =>
{
_mapboxToken = response;
if (_mapboxToken.Status != MapboxTokenStatus.TokenValid)
{
Debug.LogError("Invalid Token");
}
callback?.Invoke();
});
}
public bool GetTelemetryCollectiongState()
{
return Configuration.TelemetryEnabled;
}
public bool SetTelemetryCollectionState(bool state)
{
Configuration.TelemetryEnabled = state;
_telemetryLibrary.SetLocationCollectionState(Configuration.TelemetryEnabled);
try
{
var configurationFilePath = Constants.Path.MAPBOX_CONFIG_ABSOLUTE;
var json = JsonUtility.ToJson(Configuration);
File.WriteAllText(configurationFilePath, json);
Debug.Log("Successfully set telemetry collection state to " + state);
return true;
}
catch (Exception e)
{
Console.WriteLine(e);
return false;
}
}
}
public interface IMapboxContext
{
public string GetAccessToken();
public string GetSkuToken();
}
}
And it worked, I could make a server build now, but there is a side effect: when I switched to make an IOS build and got it on my phone, it refused to make a map and got stuck on the loading screen.
I dunno why geo-location is not working on that IOS build, it should be running anything with #if Unity_IOS which runs the script as it was before.
I cannot use Mapbox V3 without having both a server build and a geo location feature so this is very important to me.
I use to use a Unity Asset Store package called Go Map that could add a geo location feature without any effect on other builds, but I would prefer Mapbox V3 because GoMaps bills on the amount of Vector Tiles used while Mapbox to bill me per user.
I bring this up because I want Mapbox V3 to overcome this hurdle and use it instead of GoMaps so what I am trying to suggest is if you guys could look into GoMaps and see what they are doing that avoids these issues and what you guys could learn from them.
This is the Unity Asset Store page:
https://assetstore.unity.com/packages/tools/integration/go-map-3d-map-for-ar-gaming-68889
My best case scenario is that Mapbox V3 figures out a solution, but if nothing changes I have to use Maps Go instead to keep my essential features.
Double posted this on the discord to make sure its heard.
- Langage dominant
- C#
- Étoiles
- 787
- Forks
- 228
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de mapbox/mapbox-unity-sdk
-
What am I todo about UnityLocationProvider' is missing the class attribute 'ExtensionOfNativeClass'!Ouverte
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
mapbox/mapbox-unity-sdk#2002 · 8 commentaires ·
-
Traffic Data Mismatch Between Mapbox Traffic Tiles and Directions API AnnotationsPeut-être à nouveau libre @brnkhy l’a pris il y a 151 jours, et aucune pull request n’est ouverte. Ouverte
mapbox/mapbox-unity-sdk#1993 · 8 commentaires · 1 personne assignée ·
-
I need to implement search functionality just like regular google maps.Peut-être à nouveau libre @brnkhy l’a pris il y a 151 jours, et aucune pull request n’est ouverte. Ouverte
mapbox/mapbox-unity-sdk#1992 · 1 commentaire · 1 personne assignée ·
-
Difficulté 3/5 1-2 jours Accessibilité débutants 48/100
mapbox/mapbox-unity-sdk#1990 · 9 commentaires ·
-
16KB Page Size UnsupportedOuverte
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
mapbox/mapbox-unity-sdk#1986 · 10 commentaires ·
Toutes les issues de mapbox/mapbox-unity-sdk
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
SixLabors/ImageSharp.Drawing#438 · 1 commentaire ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 92/100
NetSparkleUpdater/NetSparkle#762 ·
-
ANSIInitializer.Enabled getterOuverte
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
-
bug effort:S P3
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
nightscout/nocturne#4563 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Tyrrrz/YoutubeDownloader#925 ·