Mapbox V3 bricking non mobile builds, MapboxContext looks like the culprit
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 活跃
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- C#
- 星标
- 787
- 派生
- 228
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mapbox/mapbox-unity-sdk 的其他 Issue
-
What am I todo about UnityLocationProvider' is missing the class attribute 'ExtensionOfNativeClass'!未关闭
难度 4/5 3-5 天 新手友好度 25/100
mapbox/mapbox-unity-sdk#2002 · 8 条评论 ·
-
Traffic Data Mismatch Between Mapbox Traffic Tiles and Directions API Annotations可能重新可做 @brnkhy 于 151 天前认领,目前没有进行中的 PR。 未关闭
mapbox/mapbox-unity-sdk#1993 · 8 条评论 · 已指派 1 人 ·
-
I need to implement search functionality just like regular google maps.可能重新可做 @brnkhy 于 151 天前认领,目前没有进行中的 PR。 未关闭
mapbox/mapbox-unity-sdk#1992 · 1 条评论 · 已指派 1 人 ·
-
难度 3/5 1-2 天 新手友好度 48/100
mapbox/mapbox-unity-sdk#1990 · 9 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
mapbox/mapbox-unity-sdk#1986 · 10 条评论 ·
查看 mapbox/mapbox-unity-sdk 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 88/100
-
bug effort:S P3
难度 2/5 1-3 小时 新手友好度 62/100
nightscout/nocturne#4563 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
-
good first issue
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
KnifeLemon/Filee#1887 · 1 条评论 ·
维护者通常 1 天内回复