public void OpenMiniMap() { Vector3 currentPos = _player.position; Vector2 mapPos = _terrainManager.WorldToMapPosition(currentPos); Debug.Log("OpenMiniMap " + "currentPos =" + currentPos + "mapPos =" + mapPos); //Preparing to switch the scene GameObject go = new GameObject(); //Make go unDestroyable GameObject.DontDestroyOnLoad(go); var starter = go.AddComponent<SceneStarter>(); starter.Key = Key; starter.MapPosition = mapPos; starter.PreviousPosition = currentPos; go.name = "Scene Starter"; //switch the scene SceneManager.LoadScene(SceneSettings.SceneIdForMiniMap); } private void LoadCaches() { foreach (var item in _cache.Find("Digging", transform.position, _horizontalTiles, false)) CreateDigging(item.Location,false); foreach (var item in _cache.Find("Item", transform.position, _horizontalTiles, false)) CreateItem(item.Location, Int32.Parse(item.Content)); } //Terrains public TerrainIns SelectTerrain(float x, float y) { return SelectTerrain(new Vector2(x, y)); } public TerrainIns SelectTerrain(Vector2 pos) { return Marker.Closest(_markers, pos, Key).Terrain; } //Elements private void SetAvailableMarketElements(TerrainIns terrain) { _elementTypes.Clear(); if (terrain.HasElement) for (int i = 0; i < _allElements.Count; i++) if (_allElements[i].FavoriteTerrainTypes == terrain.Type) _elementTypes.Add(_allElements[i]); } void SetElements(char[,] charMap, Vector2 location) { int elementMass = RandomHelper.Range(location.x, location.y, Key, 14 * 14) / 4; for (int i = 0; i < elementMass; i++) {
public TerrainType SelectTerrain(float x, float y) { return(Marker.Closest(_markers, new Vector2(x, y), Key).terrain); }
//Player private void SetPlayerLocation() { Marker marker = Marker.Closest(_markers, new Vector2(_player.position.x, _player.position.y), Key); if (!marker.Terrain.Walkable) foreach (var newMarker in _markers) { if (newMarker.Terrain.Walkable) { marker = newMarker; break; } } for (int r = 0; r < 8; r++) //Radiate from the center to find closest empty open space in the middle for (int x = 8 - r; x < 8 + r; x++) for (int y = 8 - r; y < 8 + r; y++) if (marker.CharMap[x, y] == 'E') { Vector2 rightCornerLocation = new Vector2(marker.Location.x - 8, marker.Location.y - 8); _player.position = new Vector3( rightCornerLocation.x + x, rightCornerLocation.y + y, 0); //print("###Inside Set Player location After: " + Player.position + marker.Terrain.Name); return; } } public static TerrainManager Instance() { if (!_terrainManager) { _terrainManager = FindObjectOfType(typeof(TerrainManager)) as TerrainManager; if (!_terrainManager) Debug.LogError("There needs to be one active TerrainManager script on a GameObject in your scene."); } return _terrainManager; } }