public IntegerRect GetRelativeBounds(MapQuad other) { IntegerRect offsetRect = this.CenteredBounds; offsetRect.Center.X = this.Bounds.Center.X - other.Bounds.Center.X; offsetRect.Center.Y = this.Bounds.Center.Y - other.Bounds.Center.Y; return offsetRect; }
private void changeCurrentQuad() { // Change current quad for (int i = 0; i < _targetLoadedQuads.Count; ++i) { IntegerRect otherRect = _targetLoadedQuads[i].GetRelativeBounds(_currentQuad); if (otherRect.Contains(_trackerPosition)) { _currentQuad = _targetLoadedQuads[i]; _recenterOffset = otherRect.Center; break; } } }
private void gatherWorldMapInfo() { TextAsset asset = Resources.Load<TextAsset>(PATH + this.WorldMapName); MapInfo mapInfo = JsonConvert.DeserializeObject<MapInfo>(asset.text); _allMapQuads = new List<MapQuad>(); MapInfo.MapLayer layer = mapInfo.GetLayerWithName(LAYER); for (int i = 0; i < layer.objects.Length; ++i) { MapInfo.MapObject mapObject = layer.objects[i]; MapQuad quad = new MapQuad(); quad.Name = mapObject.name; int y = this.FlipVertical ? mapInfo.height - mapObject.y - mapObject.height / 2 : mapObject.y + mapObject.height / 2; quad.Bounds = new IntegerRect(mapObject.x + mapObject.width / 2, y, mapObject.width, mapObject.height); quad.CenteredBounds = new IntegerRect(0, 0, mapObject.width, mapObject.height); quad.BoundsToLoad = new IntegerRect(quad.Bounds.Center.X, quad.Bounds.Center.Y, mapObject.width + BOUNDS_TO_LOAD, mapObject.height + BOUNDS_TO_LOAD); _allMapQuads.Add(quad); } }