/* ----------------------------- * Drawing methods *-----------------------------*/ protected void DrawTiles(Rect area) { // Download and draw tiles var tile = GM.MetersToTile(GM.LatLonToMeters(Center.x, Center.y), Zoom); Vector2d topLeftCorner = GM.PixelsToTile(centerPixel - new Vector2d(area.width / 2f, area.height / 2f)), bottomRightCorner = GM.PixelsToTile(centerPixel + new Vector2d(area.width / 2f, area.height / 2f)); for (double x = topLeftCorner.x; x <= bottomRightCorner.x; x++) { for (double y = topLeftCorner.y; y <= bottomRightCorner.y; y++) { var tp = TileProvider.GetTile(new Vector3d(x, y, Zoom), (texture) => { if (Repaint != null) { Repaint(); } }); var tileBounds = GM.TileBounds(new Vector2d(x, y), Zoom); var tileRect = ExtensionRect.FromCorners( GM.MetersToPixels(tileBounds.Min, Zoom).ToVector2(), GM.MetersToPixels(tileBounds.Min + tileBounds.Size, Zoom).ToVector2()); var windowRect = new Rect(tileRect.position + PATR.ToVector2(), tileRect.size); var areaRect = windowRect.Intersection(area); if (areaRect.width < 0 || areaRect.height < 0) { continue; } GUI.DrawTextureWithTexCoords(areaRect, tp.Texture, windowRect.ToTexCoords(areaRect)); } } }
private void SetTileProvider() { if (_options.extentOptions.extentType != MapExtentType.Custom) { ITileProviderOptions tileProviderOptions = _options.extentOptions.GetTileProviderOptions(); // Setup tileprovider based on type. switch (_options.extentOptions.extentType) { case MapExtentType.CameraBounds: TileProvider = gameObject.AddComponent <QuadTreeTileProvider>(); break; case MapExtentType.RangeAroundCenter: TileProvider = gameObject.AddComponent <RangeTileProvider>(); break; case MapExtentType.RangeAroundTransform: TileProvider = gameObject.AddComponent <RangeAroundTransformTileProvider>(); break; default: break; } TileProvider.SetOptions(tileProviderOptions); } else { TileProvider = _tileProvider; } }
protected virtual void preSetup() { map = GetComponent <MapModule>(); tp = GameObject.Find("TileProvider").GetComponent <TileProvider>(); tilemap = gameObject.transform.Find("Tilemap").GetComponent <Tilemap>(); FGTilemap = gameObject.transform.Find("Foreground").GetComponent <Tilemap>(); FullFGTilemap = gameObject.transform.Find("FullFG").GetComponent <Tilemap>(); }
private void LoadProviderCtrl(TileProvider provider) { var ctrl = MakeProviderCtrl(provider); ctrl.Dock = DockStyle.Fill; grpSettings.Controls.Clear(); grpSettings.Controls.Add(ctrl); }
public GenericProviderCtrl(TileProvider provider, ITileSetDefinition tsd, Action resourceChangeHandler) : this() { Check.ArgumentNotNull(provider, nameof(provider)); Check.ArgumentNotNull(tsd, nameof(tsd)); _tsd = tsd; _provider = provider; _resourceChangeHandler = resourceChangeHandler; }
private void TriggerTileRedrawForExtent(ExtentArgs currentExtent) { var _activeTiles = _mapVisualizer.ActiveTiles; _currentExtent = new HashSet <UnwrappedTileId>(currentExtent.activeTiles); if (tilesToProcess == null) { tilesToProcess = new List <UnwrappedTileId>(); } else { tilesToProcess.Clear(); } foreach (var item in _activeTiles) { if (TileProvider.Cleanup(item.Key)) { tilesToProcess.Add(item.Key); } } if (tilesToProcess.Count > 0) { OnTilesDisposing(tilesToProcess); foreach (var t2r in tilesToProcess) { TileProvider_OnTileRemoved(t2r); } } foreach (var tile in _activeTiles) { // Reposition tiles in case we panned. TileProvider_OnTileRepositioned(tile.Key); } tilesToProcess.Clear(); foreach (var tile in _currentExtent) { if (!_activeTiles.ContainsKey(tile)) { tilesToProcess.Add(tile); } } if (tilesToProcess.Count > 0) { OnTilesStarting(tilesToProcess); foreach (var tileId in tilesToProcess) { _mapVisualizer.State = ModuleState.Working; TileProvider_OnTileAdded(tileId); } } }
public DefaultWebLayerConfig(string name, string urlPattern) { TileCache = new FileSystemTileCache(); _tiler = new DefaultWebTiler(); TileLoader = new DefaultWebTileLoader(TileCache, _tiler); TileProvider = new TileProvider(_tiler, TileLoader); UrlPattern = urlPattern; LayerName = name; }
/// <param name="texture">Spritesheet</param> /// <param name="provider">Accesor to tilemap data</param> /// <param name="tileSize">Size of one tile</param> public MapRenderer(Texture texture, TileProvider provider, float tileSize = 32) { _provider = provider; _tileSize = tileSize; _vertices = new Vertex[0]; _texture = texture; }
/// <summary> /// Updates the map. /// Use this method to update the location of the map. /// Update method should be used when panning, zooming or changing location of the map. /// This method avoid startup delays that might occur on re-initializing the map. /// </summary> /// <param name="latLon">LatitudeLongitude.</param> /// <param name="zoom">Zoom level.</param> public virtual void UpdateMap(Vector2d latLon, float zoom) { if (Application.isEditor && !Application.isPlaying && !IsEditorPreviewEnabled) { return; } StartCoroutine(CalculateDistance.Instance.FindAllBinsInMap(2)); //so map will be snapped to zero using next new tile loaded _worldHeightFixed = false; float differenceInZoom = 0.0f; bool isAtInitialZoom = false; // Update map zoom, if it has changed. if (Math.Abs(Zoom - zoom) > Constants.EpsilonFloatingPoint) { SetZoom(zoom); } // Compute difference in zoom. Will be used to calculate correct scale of the map. differenceInZoom = Zoom - InitialZoom; isAtInitialZoom = (differenceInZoom - 0.0 < Constants.EpsilonFloatingPoint); //Update center latitude longitude var centerLatitudeLongitude = latLon; double xDelta = centerLatitudeLongitude.x; double zDelta = centerLatitudeLongitude.y; xDelta = xDelta > 0 ? Mathd.Min(xDelta, Mapbox.Utils.Constants.LatitudeMax) : Mathd.Max(xDelta, -Mapbox.Utils.Constants.LatitudeMax); zDelta = zDelta > 0 ? Mathd.Min(zDelta, Mapbox.Utils.Constants.LongitudeMax) : Mathd.Max(zDelta, -Mapbox.Utils.Constants.LongitudeMax); //Set Center in Latitude Longitude and Mercator. SetCenterLatitudeLongitude(new Vector2d(xDelta, zDelta)); Options.scalingOptions.scalingStrategy.SetUpScaling(this); Options.placementOptions.placementStrategy.SetUpPlacement(this); //Scale the map accordingly. if (Math.Abs(differenceInZoom) > Constants.EpsilonFloatingPoint || isAtInitialZoom) { _mapScaleFactor = Vector3.one * Mathf.Pow(2, differenceInZoom); Root.localScale = _mapScaleFactor; } //Update Tile extent. if (TileProvider != null) { TileProvider.UpdateTileExtent(); } if (OnUpdated != null) { OnUpdated(); } }
private void PrepareTiles() { var tiles = _map.Tiles; _oldTilesVisible = tiles.Visible; _oldTileProvider = tiles.Provider; tiles.UseServer = false; tiles.Visible = _drawTiles; tiles.Provider = _tileProvider; }
protected virtual void Update() { if (Application.isEditor && !Application.isPlaying && IsEditorPreviewEnabled == false) { return; } if (TileProvider != null) { TileProvider.UpdateTileProvider(); } }
public SwissTopoLayerConfig(string name, string licenseKey) { TileCache = new FileSystemTileCache(); ITiler tiler = new SwissTopoTiler(); _tileLoader = new SwissGridTileLoader(TileCache, tiler); TileProvider = new TileProvider(tiler, _tileLoader); LicenseKey = licenseKey; LayerName = name; }
protected override IEnumerable <LowerTileInfo> GetLoadedLowerTiles(IEnumerable <VisibleTileInfo> visibleTiles) { var memoryCache = (LRUMemoryCache)TileSystem.MemoryServer; var sourceServer = TileSystem.SourceServer; var actualVisibleTiles = visibleTiles.Where(tile => sourceServer.Contains(tile.Tile)).ToList(); var currLevel = TileProvider.Level; var upperLevel = GetAvailableUpperLevel(currLevel); var cache = (ICollection <TileIndex>)memoryCache.GetCachedIndexes(); var region = GetRegion(actualVisibleTiles); var server = TileSystem; var lowerTiles = TileProvider.GetTilesForRegion(region, upperLevel).Where(tile => server.IsLoaded(tile)); var plotterTransform = Plotter.Transform; var lowerTileList = new List <LowerTileInfo>(); foreach (var lowerTile in lowerTiles) { bool addToLowerTiles = false; var bounds = TileProvider.GetTileBounds(lowerTile); var shiftedScreenBounds = bounds.ViewportToScreen(plotterTransform); Geometry clip = new RectangleGeometry(shiftedScreenBounds); foreach (var tile in actualVisibleTiles) { if (tile.VisibleBounds.IntersectsWith(bounds)) { if (!cache.Contains(tile.Tile)) { addToLowerTiles = true; } else { var screenBounds = tile.VisibleBounds.ViewportToScreen(plotterTransform); clip = new CombinedGeometry(GeometryCombineMode.Exclude, clip, new RectangleGeometry(screenBounds)); } } } if (addToLowerTiles) { lowerTileList.Add(new LowerTileInfo { Id = lowerTile, Clip = clip }); } } return(lowerTileList); }
public DungeonRoomLoader(string name, GameObject prefab) { this.name = name; this.prefab = prefab; rerollChance = prefab.GetComponent <DungeonRoom>().rerollChance; origin = Vector2Int.FloorToInt(prefab.transform.position); tp = GameObject.Find("TileProvider").GetComponent <TileProvider>(); doors = this.prefab.GetComponentsInChildren <DungeonDoorMarker>().ToList(); doors.ForEach(t => t.pos = Vector2Int.FloorToInt(new Vector2(t.transform.localPosition.x, t.transform.localPosition.y))); using (var sr = new StreamReader(name)) { string s; var bottomLeft = getv2(sr.ReadLine(), 0); var topRight = getv2(sr.ReadLine(), 16); bounds = new BoundsInt(bottomLeft, topRight - bottomLeft); tiles = new Tile[bounds.size.x * bounds.size.y * 16]; fgTiles = new Tile[bounds.size.x * bounds.size.y * 16]; fullFgTiles = new Tile[bounds.size.x * bounds.size.y * 16]; int c = 0; for (int i = 0; i < bounds.size.x; i++) { for (int j = 0; j < bounds.size.y; j++) { for (int k = 0; k < 16; k++) { s = sr.ReadLine(); c = k + i * 16 + j * bounds.size.x * 16; if (!string.IsNullOrEmpty(s)) { tiles[c] = tp.tiles[s]; } s = sr.ReadLine(); if (!string.IsNullOrEmpty(s)) { fgTiles[c] = tp.tiles[s]; } s = sr.ReadLine(); if (!string.IsNullOrEmpty(s)) { fullFgTiles[c] = tp.tiles[s]; } } } } } }
/// <summary> /// Should initialize all private data members which aren't set by deserialization. /// </summary> protected override void SetDefaults() { _extentChanged = false; _isMain = false; Name = "Map"; PrintQuality = PrintQuality.High; TilesLoaded = false; Guid = Guid.NewGuid(); ResizeStyle = ResizeStyle.NoScaling; _lastScale = -1; _tileProvider = TileProvider.OpenStreetMap; _oldTileProvider = TileProvider.OpenStreetMap; }
/// <param name="texture">Spritesheet</param> /// <param name="provider">Accesor to tilemap data</param> /// <param name="tileSize">Size of one tile</param> /// <param name="layers">Numbers of layers</param> public LayerRenderer(Texture texture, TileProvider provider, float tileSize = 16, int layers = 1) { if (provider == null || layers <= 0) { throw new ArgumentException(); } this.provider = provider; TileSize = tileSize; Layers = layers; vertices = new Vertex[0]; this.texture = texture; }
private void OnTileProviderChanged() { if (Application.isEditor && !Application.isPlaying && IsEditorPreviewEnabled == false) { Debug.Log("extentOptions"); return; } SetTileProvider(); TileProvider.Initialize(this); if (IsEditorPreviewEnabled) { TileProvider.UpdateTileExtent(); } }
public async Task ShouldReadTiles() { // Arrange var reader = new FileReader("TestData/input.txt"); var provider = new TileProvider(reader); // Act var result = await provider.ReadTiles(); // Assert var tiles = result.ToList(); tiles[0].Id.Should().Be(3001); tiles[1].Id.Should().Be(2069); tiles.Count().Should().Be(2); }
public void SetTileType(Vector2 position, TileType type) { if (!Tiles.ContainsKey(position)) { Tiles[position] = TileProvider.GetTile(type); Tiles[position].transform.parent = transform; Tiles[position].transform.position = GetPositionForCoordinate(position); Tiles[position].Position = position; Tiles[position].Height = baseHeight; } else { Tiles[position].Type = type; TileProvider.SetTileMaterial(Tiles[position]); } Tiles[position].name = "Tile [" + position.x + "," + position.y + "] " + type; // Check the fields around and create VOID tiles, if needed. if (type != TileType.Void) { foreach (NeighbourIndex idx in Enum.GetValues(typeof(NeighbourIndex))) { var ypos = GetNeighbourPosition(position, idx); if (!Tiles.ContainsKey(ypos)) { SetTileType(ypos, TileType.Void); } } } /* * // TODO: Path End, Path Start * if (type == TileType.Path) * { * if (!Waypoints.ContainsKey(position)) * { * Waypoints[position] = Instantiate(Resources.Load<WaypointBehaviour>(waypointPrefabPath)); * Waypoints[position].transform.SetParent(Tiles[position].transform); * Waypoints[position].transform.position = Tiles[position].transform.position + new Vector3(0, 4, 0); * } * } * //*/ CleanupTilesAroundPosition(position); }
// Start is called before the first frame update public TilemapLoader(string name) { assetName = name; tp = GameObject.Find("TileProvider").GetComponent <TileProvider>(); using (var sr = new StreamReader(assetName)) { string s = sr.ReadLine(); bounds = new BoundsInt(0, 0, 0, int.Parse(s.Split(' ')[0]), int.Parse(s.Split(' ')[1]), int.Parse(s.Split(' ')[2])); tiles = new Tile[bounds.size.x * bounds.size.y * bounds.size.z]; fgTiles = new Tile[bounds.size.x * bounds.size.y * bounds.size.z]; int c = 0; for (int i = 0; i < bounds.size.x; i++) { for (int j = 0; j < bounds.size.y; j++) { for (int k = 0; k < bounds.size.z; k++) { s = sr.ReadLine(); if (!string.IsNullOrEmpty(s)) { var tile = tp.tiles[s]; if (k > 10) { fgTiles[c] = tile; } else { tiles[c] = tile; } } c++; } } } } }
private void SetTileProvider() { if (_options.extentOptions.extentType != MapExtentType.Custom) { ITileProviderOptions tileProviderOptions = _options.extentOptions.GetTileProviderOptions(); string tileProviderName = "TileProvider"; // Setup tileprovider based on type. switch (_options.extentOptions.extentType) { case MapExtentType.CameraBounds: { if (TileProvider != null) { if (!(TileProvider is QuadTreeTileProvider)) { TileProvider.gameObject.Destroy(); var go = new GameObject(tileProviderName); go.transform.parent = transform; TileProvider = go.AddComponent <QuadTreeTileProvider>(); } } else { var go = new GameObject(tileProviderName); go.transform.parent = transform; TileProvider = go.AddComponent <QuadTreeTileProvider>(); } break; } case MapExtentType.RangeAroundCenter: { if (TileProvider != null) { TileProvider.gameObject.Destroy(); var go = new GameObject(tileProviderName); go.transform.parent = transform; TileProvider = go.AddComponent <RangeTileProvider>(); } else { var go = new GameObject(tileProviderName); go.transform.parent = transform; TileProvider = go.AddComponent <RangeTileProvider>(); } break; } case MapExtentType.RangeAroundTransform: { if (TileProvider != null) { if (!(TileProvider is RangeAroundTransformTileProvider)) { TileProvider.gameObject.Destroy(); var go = new GameObject(tileProviderName); go.transform.parent = transform; TileProvider = go.AddComponent <RangeAroundTransformTileProvider>(); } } else { var go = new GameObject(tileProviderName); go.transform.parent = transform; TileProvider = go.AddComponent <RangeAroundTransformTileProvider>(); } break; } default: break; } TileProvider.SetOptions(tileProviderOptions); } else { TileProvider = _tileProvider; } }
/// <summary> /// Initializes the map using the mapOptions. /// </summary> /// <param name="options">Options.</param> protected virtual void InitializeMap(MapOptions options) { Options = options; _worldHeightFixed = false; _fileSource = MapboxAccess.Instance; _centerLatitudeLongitude = Conversions.StringToLatLon(options.locationOptions.latitudeLongitude); _initialZoom = (int)options.locationOptions.zoom; options.scalingOptions.scalingStrategy.SetUpScaling(this); options.placementOptions.placementStrategy.SetUpPlacement(this); //Set up events for changes. _imagery.UpdateLayer += OnImageOrTerrainUpdateLayer; _terrain.UpdateLayer += OnImageOrTerrainUpdateLayer; _vectorData.SubLayerRemoved += OnVectorDataSubLayerRemoved; _vectorData.SubLayerAdded += OnVectorDataSubLayerAdded; _vectorData.UpdateLayer += OnVectorDataUpdateLayer; _options.locationOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { UpdateMap(); }; _options.extentOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { OnTileProviderChanged(); }; _options.extentOptions.defaultExtents.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { if (Application.isEditor && !Application.isPlaying && IsEditorPreviewEnabled == false) { Debug.Log("defaultExtents"); return; } if (TileProvider != null) { TileProvider.UpdateTileExtent(); } }; _options.placementOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { SetPlacementStrategy(); UpdateMap(); }; _options.scalingOptions.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { SetScalingStrategy(); UpdateMap(); }; _mapVisualizer.Initialize(this, _fileSource); TileProvider.Initialize(this); SendInitialized(); TileProvider.UpdateTileExtent(); }
public int get_IndexByProvider(TileProvider provider) { return(_providers.IndexByProvider[(tkTileProvider)provider]); }
private void SetTileProvider() { //TileProvider = GetComponent<AbstractTileProvider>(); if (_options.extentOptions.extentType != MapExtentType.Custom) { ITileProviderOptions tileProviderOptions = _options.extentOptions.GetTileProviderOptions(); // Setup tileprovider based on type. switch (_options.extentOptions.extentType) { case MapExtentType.CameraBounds: { if (TileProvider != null) { if (!(TileProvider is QuadTreeTileProvider)) { TileProvider = new QuadTreeTileProvider(); } } else { TileProvider = new QuadTreeTileProvider(); } break; } case MapExtentType.RangeAroundCenter: { if (TileProvider != null) { if (!(TileProvider is RangeTileProvider)) { TileProvider = new RangeTileProvider(); } } else { TileProvider = new RangeTileProvider(); } break; } case MapExtentType.RangeAroundTransform: { if (TileProvider != null) { if (!(TileProvider is RangeAroundTransformTileProvider)) { TileProvider = new RangeAroundTransformTileProvider(); } } else { TileProvider = new RangeAroundTransformTileProvider(); } break; } default: break; } TileProvider.SetOptions(tileProviderOptions); } else { TileProvider = _tileProvider; } }
private Control MakeProviderCtrl(TileProvider provider) { return(new GenericProviderCtrl(provider, _tsd, OnResourceChanged)); }
public bool FindPath(int x, int y, int minimumLength, bool debugMode = false) { TrackGenerator.TrackHistory[] trackHistory = this._historyCache; int num = 0; TileProvider tileArray = Main.tile; bool flag = true; int num1 = ((new Random()).Next(2) == 0 ? 1 : -1); if (debugMode) { num1 = Main.player[Main.myPlayer].direction; } int yDirection = 1; int num2 = 0; int num3 = 400; bool flag1 = false; int num4 = 150; int num5 = 0; int num6 = 1000000; while (num6 > 0 && flag && num < (int)trackHistory.Length - 1) { num6--; trackHistory[num] = new TrackGenerator.TrackHistory(x, y, yDirection); bool flag2 = false; int num7 = 1; if (num > minimumLength >> 1) { num7 = -1; } else if (num > (minimumLength >> 1) - 5) { num7 = 0; } if (!flag1) { int num8 = Math.Min(1, yDirection + 1); while (num8 >= Math.Max(-1, yDirection - 1)) { if (!this.IsLocationEmpty(x + num1, y + num8 * num7)) { num8--; } else { yDirection = num8; flag2 = true; x = x + num1; y = y + yDirection * num7; num2 = num + 1; break; } } if (!flag2) { while (num > num5 && y == trackHistory[num].Y) { num--; } x = trackHistory[num].X; y = trackHistory[num].Y; yDirection = trackHistory[num].YDirection - 1; num3--; if (num3 <= 0) { num = num2; x = trackHistory[num].X; y = trackHistory[num].Y; yDirection = trackHistory[num].YDirection; flag1 = true; num3 = 200; } num--; } } else { int num9 = 0; int num10 = num4; bool flag3 = false; for (int i = Math.Min(1, yDirection + 1); i >= Math.Max(-1, yDirection - 1); i--) { int num11 = 0; while (num11 <= num4) { if (!this.IsLocationEmpty(x + (num11 + 1) * num1, y + (num11 + 1) * i * num7)) { num11++; } else { flag3 = true; break; } } if (num11 < num10) { num10 = num11; num9 = i; } } if (flag3) { yDirection = num9; for (int j = 0; j < num10 - 1; j++) { num++; x = x + num1; y = y + yDirection * num7; trackHistory[num] = new TrackGenerator.TrackHistory(x, y, yDirection); num5 = num; } x = x + num1; y = y + yDirection * num7; num2 = num + 1; flag1 = false; } num4 = num4 - num10; if (num4 < 0) { flag = false; } } num++; } if (num2 <= minimumLength && !debugMode) { return(false); } this.SmoothTrack(trackHistory, num2); if (!debugMode) { for (int k = 0; k < num2; k++) { for (int l = -1; l < 7; l++) { if (!this.CanTrackBePlaced(trackHistory[k].X, trackHistory[k].Y - l)) { return(false); } } } } for (int m = 0; m < num2; m++) { TrackGenerator.TrackHistory trackHistory1 = trackHistory[m]; for (int n = 0; n < 6; n++) { Main.tile[trackHistory1.X, trackHistory1.Y - n].active(false); } } for (int o = 0; o < num2; o++) { TrackGenerator.TrackHistory trackHistory2 = trackHistory[o]; Tile.SmoothSlope(trackHistory2.X, trackHistory2.Y + 1, true); Tile.SmoothSlope(trackHistory2.X, trackHistory2.Y - 6, true); Main.tile[trackHistory2.X, trackHistory2.Y].ResetToType(314); if (o != 0) { for (int p = 0; p < 6; p++) { WorldUtils.TileFrame(trackHistory[o - 1].X, trackHistory[o - 1].Y - p, true); } if (o == num2 - 1) { for (int q = 0; q < 6; q++) { WorldUtils.TileFrame(trackHistory2.X, trackHistory2.Y - q, true); } } } } return(true); }
/// <summary> /// Sets up map. /// This method uses the mapOptions and layer properties to setup the map to be rendered. /// Override <c>SetUpMap</c> to write custom behavior to map setup. /// </summary> protected virtual void SetUpMap() { switch (_options.placementOptions.placementType) { case MapPlacementType.AtTileCenter: _options.placementOptions.placementStrategy = new MapPlacementAtTileCenterStrategy(); break; case MapPlacementType.AtLocationCenter: _options.placementOptions.placementStrategy = new MapPlacementAtLocationCenterStrategy(); break; default: _options.placementOptions.placementStrategy = new MapPlacementAtTileCenterStrategy(); break; } switch (_options.scalingOptions.scalingType) { case MapScalingType.WorldScale: _options.scalingOptions.scalingStrategy = new MapScalingAtWorldScaleStrategy(); break; case MapScalingType.Custom: _options.scalingOptions.scalingStrategy = new MapScalingAtUnityScaleStrategy(); break; default: break; } if (_options.extentOptions.extentType != MapExtentType.Custom) { ITileProviderOptions tileProviderOptions = _options.extentOptions.GetTileProviderOptions(); // Setup tileprovider based on type. switch (_options.extentOptions.extentType) { case MapExtentType.CameraBounds: TileProvider = gameObject.AddComponent <QuadTreeTileProvider>(); break; case MapExtentType.RangeAroundCenter: TileProvider = gameObject.AddComponent <RangeTileProvider>(); break; case MapExtentType.RangeAroundTransform: TileProvider = gameObject.AddComponent <RangeAroundTransformTileProvider>(); break; default: break; } TileProvider.SetOptions(tileProviderOptions); } else { TileProvider = _tileProvider; } if (_imagery == null) { _imagery = new ImageryLayer(); } _imagery.Initialize(); if (_terrain == null) { _terrain = new TerrainLayer(); } _terrain.Initialize(); if (_vectorData == null) { _vectorData = new VectorLayer(); } _vectorData.Initialize(); if (Options.loadingTexture != null) { _mapVisualizer.SetLoadingTexture(Options.loadingTexture); } if (Options.tileMaterial != null) { _mapVisualizer.SetTileMaterial(Options.tileMaterial); } _mapVisualizer.Factories = new List <AbstractTileFactory>(); _mapVisualizer.Factories.Add(_terrain.Factory); _mapVisualizer.Factories.Add(_imagery.Factory); _mapVisualizer.Factories.Add(_vectorData.Factory); InitializeMap(_options); }
public PathfindingResult Run(int startX, int startY, int endX, int endY, TileProvider provider, out List <PNode> path) { if (provider == null) { path = null; return(PathfindingResult.ERROR_INTERNAL); } // Validate start and end points. if (!provider.TileInBounds(startX, startY)) { path = null; return(PathfindingResult.ERROR_START_OUT_OF_BOUNDS); } if (!provider.TileInBounds(endX, endY)) { path = null; return(PathfindingResult.ERROR_END_OUT_OF_BOUNDS); } if (!provider.IsTileWalkable(startX, startY)) { path = null; return(PathfindingResult.ERROR_START_NOT_WALKABLE); } if (!provider.IsTileWalkable(endX, endY)) { path = null; return(PathfindingResult.ERROR_END_NOT_WALKABLE); } // Clear everything up. Clear(); var start = PNode.Create(startX, startY); var end = PNode.Create(endX, endY); // Check the start/end relationship. if (start.Equals(end)) { path = null; return(PathfindingResult.ERROR_START_IS_END); } // Add the starting point to all relevant structures. open.Enqueue(start, 0f); cameFrom[start] = start; costSoFar[start] = 0f; int count; while ((count = open.Count) > 0) { // Detect if the current open amount exceeds the capacity. // This only happens in very large open areas. Corridors and hallways will never cause this, not matter how large the actual path length. if (count >= MAX - 8) { path = null; return(PathfindingResult.ERROR_PATH_TOO_LONG); } var current = open.Dequeue(); if (current.Equals(end)) { // We found the end of the path! path = TracePath(end); return(PathfindingResult.SUCCESSFUL); } // Get all neighbours (tiles that can be walked on to) var neighbours = GetNear(current, provider); foreach (PNode n in neighbours) { float newCost = costSoFar[current] + GetCost(current, n); // Note that this could change depending on speed changes per-tile. if (!costSoFar.ContainsKey(n) || newCost < costSoFar[n]) { costSoFar[n] = newCost; float priority = newCost + Heuristic(current, n); open.Enqueue(n, priority); cameFrom[n] = current; } } } path = null; return(PathfindingResult.ERROR_INTERNAL); }
public TileOverlayOptions TileProvider(TileProvider tileProvider) { _tileProvider = tileProvider; return(this); }
private List <PNode> GetNear(PNode node, TileProvider provider) { // Want to add nodes connected to the center node, if they are walkable. // This code stops the pathfinder from cutting corners, and going through walls that are diagonal from each other. near.Clear(); // Left left = false; if (provider.IsTileWalkable(node.X - 1, node.Y)) { near.Add(PNode.Create(node.X - 1, node.Y)); left = true; } // Right right = false; if (provider.IsTileWalkable(node.X + 1, node.Y)) { near.Add(PNode.Create(node.X + 1, node.Y)); right = true; } // Above above = false; if (provider.IsTileWalkable(node.X, node.Y + 1)) { near.Add(PNode.Create(node.X, node.Y + 1)); above = true; } // Below below = false; if (provider.IsTileWalkable(node.X, node.Y - 1)) { near.Add(PNode.Create(node.X, node.Y - 1)); below = true; } // Above-Left if (left && above) { if (provider.IsTileWalkable(node.X - 1, node.Y + 1)) { near.Add(PNode.Create(node.X - 1, node.Y + 1)); } } // Above-Right if (right && above) { if (provider.IsTileWalkable(node.X + 1, node.Y + 1)) { near.Add(PNode.Create(node.X + 1, node.Y + 1)); } } // Below-Left if (left && below) { if (provider.IsTileWalkable(node.X - 1, node.Y - 1)) { near.Add(PNode.Create(node.X - 1, node.Y - 1)); } } // Below-Right if (right && below) { if (provider.IsTileWalkable(node.X + 1, node.Y - 1)) { near.Add(PNode.Create(node.X + 1, node.Y - 1)); } } return(near); }