//We do the actual interpolation in FixedUpdate(), since we're dealing with a rigidbody
        private void LateUpdate()
        {
            if (_isMapInitialized && _isLerping)
            {
                //We want percentage = 0.0 when Time.time = _timeStartedLerping
                //and percentage = 1.0 when Time.time = _timeStartedLerping + timeTakenDuringLerp
                //In other words, we want to know what percentage of "timeTakenDuringLerp" the value
                //"Time.time - _timeStartedLerping" is.
                float timeSinceStarted   = Time.time - _timeStartedLerping;
                float percentageComplete = timeSinceStarted / timeTakenDuringLerp;

                //Perform the actual lerping.  Notice that the first two parameters will always be the same
                //throughout a single lerp-processs (ie. they won't change until we hit the space-bar again
                //to start another lerp)
                _startPosition = _map.GeoToWorldPosition(_startLatLong, false);
                _endPosition   = _map.GeoToWorldPosition(_endLatlong, false);
                var position = Vector3.Lerp(_startPosition, _endPosition, percentageComplete);
                var latLong  = _map.WorldToGeoPosition(position);
                _map.UpdateMap(latLong, _map.Zoom);

                //When we've completed the lerp, we set _isLerping to false
                if (percentageComplete >= 1.0f)
                {
                    _isLerping = false;
                }
            }
        }
 private void LateUpdate()
 {
     if (_isMapInitialized)
     {
         var currentPosition = _map.GeoToWorldPosition(_map.CenterLatitudeLongitude, false);
         var position        = Vector3.Lerp(currentPosition, _targetPosition, Time.deltaTime);
         var latLong         = _map.WorldToGeoPosition(position);
         _map.UpdateMap(latLong, _map.Zoom);
     }
 }
示例#3
0
        private void Update()
        {
            if (!_initialized)
            {
                return;
            }

            _currentTile = TileCover.CoordinateToTileId(_basicMap.WorldToGeoPosition(_targetTransform.position), (int)_map.Zoom);

            if (!_currentTile.Equals(_cachedTile))
            {
                for (int x = _currentTile.X - _visibleBuffer; x <= (_currentTile.X + _visibleBuffer); x++)
                {
                    for (int y = _currentTile.Y - _visibleBuffer; y <= (_currentTile.Y + _visibleBuffer); y++)
                    {
                        AddTile(new UnwrappedTileId((int)_map.Zoom, x, y));
                    }
                }
                _cachedTile = _currentTile;
                Cleanup(_currentTile);
            }
        }