unity3d TransformTileProvider:未指定位置标记转换Unity错误

gdrx4gfi  于 2022-11-25  发布在  其他
关注(0)|答案(1)|浏览(104)

当我尝试使用Mapbox预制件运行游戏时,出现此错误:转换磁贴提供程序:未指定位置标记转换。UnityEngine。调试:LogError(对象)Map框。Unity。Map。切片提供程序。RangeAroundTransformTileProvider:OnInitialized()
如果我将OnInitialized更改为public,我会得到一大堆其他错误。
代码如下:

using System.Collections.Generic;
using Mapbox.Map;
using UnityEngine;

namespace Mapbox.Unity.Map.TileProviders
{
    public class RangeAroundTransformTileProvider : AbstractTileProvider
    {
        [SerializeField] private RangeAroundTransformTileProviderOptions _rangeTileProviderOptions;

        private bool _initialized = false;
        private UnwrappedTileId _currentTile;
        private bool _waitingForTargetTransform = false;

        public override void OnInitialized()
        {
            if (Options != null)
            {
                _rangeTileProviderOptions = (RangeAroundTransformTileProviderOptions)Options;
            }
            else if (_rangeTileProviderOptions == null)
            {
                _rangeTileProviderOptions = new RangeAroundTransformTileProviderOptions();
            }

            if (_rangeTileProviderOptions.targetTransform == null)
            {
                Debug.LogError("TransformTileProvider: No location marker transform specified.");
                _waitingForTargetTransform = true;
            }
            else
            {
                _initialized = true;
            }
            _currentExtent.activeTiles = new HashSet<UnwrappedTileId>();
            _map.OnInitialized += UpdateTileExtent;
            _map.OnUpdated += UpdateTileExtent;
        }

        public override void UpdateTileExtent()
        {
            if (!_initialized) return;

            _currentExtent.activeTiles.Clear();
            _currentTile = TileCover.CoordinateToTileId(_map.WorldToGeoPosition(_rangeTileProviderOptions.targetTransform.localPosition), _map.AbsoluteZoom);

            for (int x = _currentTile.X - _rangeTileProviderOptions.visibleBuffer; x <= (_currentTile.X + _rangeTileProviderOptions.visibleBuffer); x++)
            {
                for (int y = _currentTile.Y - _rangeTileProviderOptions.visibleBuffer; y <= (_currentTile.Y + _rangeTileProviderOptions.visibleBuffer); y++)
                {
                    _currentExtent.activeTiles.Add(new UnwrappedTileId(_map.AbsoluteZoom, x, y));
                }
            }
            OnExtentChanged();
        }

        public override void UpdateTileProvider()
        {
            if (_waitingForTargetTransform && !_initialized)
            {
                if (_rangeTileProviderOptions.targetTransform != null)
                {
                    _initialized = true;
                }
            }

            if (_rangeTileProviderOptions != null && _rangeTileProviderOptions.targetTransform != null && _rangeTileProviderOptions.targetTransform.hasChanged)
            {
                UpdateTileExtent();
                _rangeTileProviderOptions.targetTransform.hasChanged = false;
            }
        }

        public override bool Cleanup(UnwrappedTileId tile)
        {
            bool dispose = false;
            dispose = tile.X > _currentTile.X + _rangeTileProviderOptions.disposeBuffer || tile.X < _currentTile.X - _rangeTileProviderOptions.disposeBuffer;
            dispose = dispose || tile.Y > _currentTile.Y + _rangeTileProviderOptions.disposeBuffer || tile.Y < _currentTile.Y - _rangeTileProviderOptions.disposeBuffer;

            return (dispose);
        }
    }
}
gab6jxml

gab6jxml1#

"摄像机一定在看什么”
第一步:抽象Map:常规/扩展选项:“变换周围的范围”。
第二步:抽象Map:常规/扩展选项/目标变换:“播放器目标(转换)”
来源:https://answers.unity.com/questions/1592263/how-can-i-solve-this-problem-using-mapbox-in-unity.html

相关问题