/*void Start() { * Debug.Log(position); * tileObject.transform.position = position; * }*/ public TileObject(TileGeneration parent, GameObject newTileObject, Vector3 newPosition, Hashtable newSubObjects) { tileObject = newTileObject; position = newPosition; if (newSubObjects != null) { subObjects = newSubObjects; } //subObjects.Add(GameObject.CreatePrimitive(PrimitiveType.Cube), new Vector3(0, 0, 0)); //test //Debug.Log(position); tileObject.transform.position = position; Vector3 rand = new Vector3(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f)); tileObject.transform.localScale = new Vector3(1.0f, 1 + rand.y, 1.0f); tileObject.GetComponent <Renderer>().material.SetColor( "_Color", new Color(rand.x, rand.y, rand.z, (parent.disolver < rand.y)?1f:0f) ); /*if (rand.y < 0.5) { * GameObject.Destroy(this.tileObject,0f); * }*/ }
private void GenerateLevel(TileGeneration currentTile) { float tileXSize = 10; float tileZSize = 10; List <Vector3> requiredCoordinates = new List <Vector3>(); for (int i = _horizontalRange * -1; i <= _horizontalRange; i++) { for (int j = (_verticalRange / 2) * -1; j <= _verticalRange; j++) { float xPosition = currentTile.GetPosition().x + i * tileXSize; float zPosition = currentTile.GetPosition().z + j * tileZSize; requiredCoordinates.Add(new Vector3(xPosition, 0, zPosition)); } } foreach (var coordinate in requiredCoordinates) { if (_currentTiles.Where(tile => tile.GetPosition() == coordinate).ToArray().Count() == 0) { _currentTiles.Add(GenerateTile(coordinate)); } } if (!_isFinishGenerateTiles) { _isFinishGenerateTiles = true; _fogConstructor.StartGenerate(this, _startTile); } _enemiesConstructor.GenerateEnemeSpawners(_currentTiles.ToArray(), currentTile); }
private void OnMouseClick(MouseUpEvent mouseEvent) { if (mouseEvent.button == 0) // Left click to select the tile { for (int i = 0; i < tileAreas.Count; i++) { if (tileAreas[i].Contains(mouseEvent.mousePosition)) { selectedTileNum = i; selectedTile = gridTilesList[i]; } } } else if (mouseEvent.button == 1) // Right click to create dropdown menu of tile options for that tile { for (int i = 0; i < tileAreas.Count; i++) { if (tileAreas[i].Contains(mouseEvent.mousePosition)) { selectedTileNum = i; selectedTile = gridTilesList[i]; } } CustomDropDown.Show(this, mouseEvent.mousePosition, selectedTile); } }
public SpawnerRange(TileGeneration tile, int stepX, int stepZ) { getTile = tile; _stepX = stepX; _stepZ = stepZ; FillingRange(); }
private void SubscribeOnTileAction(TileGeneration tile) { tile.ReturningToPool += delegate(TileGeneration currentTile) { _currentTiles.Remove(currentTile); }; tile.CheckPosition += GenerateLevel; }
private void SetSpawnerOnScene(TileGeneration tile) { SpawnDotData spawner = new SpawnDotData(tile); spawner.Spawner = Instantiate(_spawner, tile.GetPosition(), Quaternion.identity); spawner.SetConnectionWithTile(); _currentSpawners.Add(spawner); }
public void StartGenerate(LevelConstructor levelConstructor, TileGeneration startTile) { _levelConstructor = levelConstructor; _fogZPosition = startTile.GetPosition().z - startTile.GetSize().z *_startOfsetPosition; _fogStep = startTile.GetSize().z; _pool = FindObjectOfType <FogPool>(); GenerateFog(); StartCoroutine(NextGnerateFog()); }
private void CreateYTiles(Vector2 p1, Vector2 p2) { for (int y = 0; y < Mathf.Abs(p1.y - p2.y); y++) { for (int x = 0; x < width; x++) { Vector2 pos = new Vector2(x, y); TileGeneration.InstantiateFromArray(ProceduralDungeon.Instance.floorTiles, pos, this.transform); } } }
private void Start() { TileBuilderWrapper tbw = TileGeneration.buildTiles(); allTiles = tbw.allTiles; outgoingEdges = tbw.outgoingEdges; incomingTiles = tbw.incomingTiles; // We only need to draw the ground once this.tileDraw.drawGround(allTiles); }
public void check_tree_gen() { TileGeneration tile_gen = new TileGeneration(); string x = tile_gen.terrain_type_check; if (x == "water") { Debug.Log("moisture applied to water reigons"); Debug.Log("heat applied to water reigons"); } }
public void check_map() { TileGeneration tile_gen = new TileGeneration(); float Y = tile_gen.size_checker; Debug.Log(Y); if (Y > 11 || Y < 11) { Debug.Log("calculated map dimensions have errors"); } }
private bool AddTileByCoordinates(Vector3 position, ref List <TileGeneration> tiles) { TileGeneration tile = _currentTiles.Where(a => a.GetPosition() == position).FirstOrDefault(); if (tile != null) { tiles.Add(tile); } return(tile != null); }
private IEnumerator GenerateOgre(float time) { while (true) { yield return(new WaitForSeconds(time)); TileGeneration tile = _spawnGenerator.GetTileForEnemy(); Vector3 spawnPosition = tile.GetPosition(); spawnPosition.y += 2.2f; Instantiate(_ogre, spawnPosition, Quaternion.Euler(0, Random.Range(0, 360), 0)); } }
public void ReturnToPool(TileGeneration tile) { Vector3 position = transform.position; for (int i = 0; i < _tilePool.Length; i++) { if (_tilePool[i] == tile) { _tilePool[i].ReturnToPool(new Vector3(position.x, position.y - i, position.z)); } } }
private IEnumerator GenerateRocket(float time) { while (true) { yield return(new WaitForSeconds(time)); TileGeneration tile = _spawnGenerator.GetTileForEnemy(); Vector3 spawnPosition = tile.GetPosition(); spawnPosition.y += 0.5f; Instantiate(_rocket, spawnPosition, Quaternion.identity); } }
public static void Show(EditorWindow host, Vector2 displayPosition, TileGeneration selectedTile) { _selectedType = selectedTile.GetTileType(); _startingType = _selectedType; hostWindow = host; var window = CreateInstance <CustomDropDown>(); var position = GetPosition(host, displayPosition); window.position = new Rect(position + host.position.position, s_DefaultSize); window.ShowPopup(); window.Focus(); }
private void Start() { myTileGen = GameObject.Find("TileGen").GetComponent <TileGeneration>(); SetStandableMat(); if (!hasDoors) { foreach (GameObject door in doors) { Destroy(door); } } }
public void EnableTiles() { for (int row = 0; row < width; row++) { for (int col = 0; col < height; col++) { Vector2 pos = upperRight; pos.x -= row; pos.y -= col; TileGeneration.InstantiateFromArray(ProceduralDungeon.Instance.floorTiles, pos, this.transform); } } }
public void Initialization(TileGeneration tile, float lifeTime, float saveTime) { _tile = tile; Vector3 position = tile.GetPosition(); transform.position = new Vector3(position.x, position.y + 1, position.z); _particle = GetComponent <ParticleSystem>(); _selfColider = GetComponent <Collider>(); _lifeTime = lifeTime; _saveTime = saveTime; _particle.Play(); IsInThePool = false; StartCoroutine(DestroyTile()); StartCoroutine(DeadZoneActive()); }
public void GenerateEnemeSpawners(TileGeneration[] tiles, TileGeneration currentTile) { if (_spawnGenerator == null) { _spawnGenerator = new EnemySpawnGenerator(_spawnRect); } var tilesToGenerate = _spawnGenerator.GetTilesToSpawn(tiles, currentTile); if (tilesToGenerate.Length > 0) { foreach (var tileToGenerate in tilesToGenerate) { SetSpawnerOnScene(tileToGenerate); } } }
private void Awake() { if (Instance != null && Instance != this) { Destroy(Instance.gameObject); } Instance = this; //assign proper preset tile data for level AssetDataSetup(); //assign tileGen obj _myTileGen = FindObjectOfType <TileGeneration>(); //number of objectives - REMOVED NUMBER 2 WILL READD LATER _posObjectives = new List <int> { 1, 2, 3 }; StartCoroutine(FadeIn()); }
public static List <Tile> GenerateTileTypes(TileGeneration generation, List <Tile> tiles, int seed) { switch (generation) { case TileGeneration.Random: { System.Random r = new System.Random(seed); int index = 0; foreach (Tile t in tiles.OrderBy(t => r.Next(1000000))) { Array values = Enum.GetValues(typeof(TileType)); t.type = (TileType)values.GetValue(index++ % values.Length); } return(tiles); } default: { return(tiles); } } }
public SpawnDotData(TileGeneration tile) { Tile = tile; }
public TileGeneration[] GetTilesToSpawn(TileGeneration[] tiles, TileGeneration currentTile) { CheckTilesOnScene(tiles); _currentTile = currentTile; Vector3 size = _currentTile.GetSize(); List <TileGeneration> tilesToSpawn = new List <TileGeneration>(); _currentTiles = tiles; Vector3 startTile = _currentTile.GetPosition() + new Vector3(0, 0, _stepZ * size.z); tilesToSpawn.Add(_currentTiles.Where(a => a.GetPosition() == startTile).First()); int counter = 1; bool isTileNotEnded = true; while (isTileNotEnded) { Vector3 nextPosition = new Vector3(startTile.x, startTile.y, startTile.z + _stepZ * counter * size.z); isTileNotEnded = AddTileByCoordinates(nextPosition, ref tilesToSpawn); counter++; if (counter > 100) { Debug.Log("counter > 100"); isTileNotEnded = false; } } Vector3[] centralTiles = new Vector3[tilesToSpawn.Count]; int tilesCounter = 0; foreach (var centralTile in tilesToSpawn) { centralTiles[tilesCounter] = centralTile.GetPosition(); tilesCounter++; } tilesToSpawn = new List <TileGeneration>(); for (int i = 0; i < centralTiles.Length; i++) { AddTileByCoordinates(centralTiles[i], ref tilesToSpawn); for (int j = -2; j <= 2; j++) { if (j != 0) { Vector3 nextPosition = new Vector3(centralTiles[i].x + (j * _stepX * size.x), centralTiles[i].y, centralTiles[i].z); AddTileByCoordinates(nextPosition, ref tilesToSpawn); } } } CheckSpawnsOnSceene(ref tilesToSpawn); if (tilesToSpawn.Count > 0) { foreach (var tileToSpawn in tilesToSpawn) { _tilesWithSpawner.Add(new SpawnerRange(tileToSpawn, _stepX, _stepZ)); } } return(tilesToSpawn.ToArray()); }
public static Map GenerateMap(int size, float radius, MapShape shape, TileGeneration generation, int seed) { Dictionary <string, Location> locations = new Dictionary <string, Location>(); Dictionary <(int, int), Path> paths = new Dictionary <(int, int), Path>(); List <Tile> tiles = new List <Tile>(); int currentLocationId = 0; int currentPathId = 0; int currentTileId = 0; UnityEngine.Random.InitState(seed); // Generate tiles with given map shape Vector3[] tileLocations = GenerateTilesOfShape(shape, size, radius); // Generate all tiles, locations, and paths foreach (Vector3 l in tileLocations) { // Initialize tile Tile tile = new Tile() { id = currentTileId, position = l, value = UnityEngine.Random.Range(2, 11), // Random number in [2, 10] }; currentTileId++; Vector3[] surroundingPoints = MapUtil.HexagonFromPoint(new Vector2(l.x, l.z), radius); tile.locations = new Location[surroundingPoints.Length]; Location startLocation = null; Location prevLocation = null; for (int i = 0; i < surroundingPoints.Length; i++) { Vector3 point = surroundingPoints[i]; Location location = null; String pointKey = point.x.ToString("0.000") + "_" + point.z.ToString("0.000"); if (!locations.ContainsKey(pointKey)) { // Locatino does not already exist, add it to the dictionary location = new Location() { id = currentLocationId, position = point, type = LocationType.Available, }; locations.Add(pointKey, location); currentLocationId++; } else { // Location already exist, extract it from the dictionary location = locations[pointKey]; } // Check if the location is the first location of the tile if (startLocation == null) { startLocation = location; } // Add path between the previous location if (prevLocation != null) { // Check if there already is an existing path between the locations if (!paths.ContainsKey((location.id, prevLocation.id)) && !paths.ContainsKey((prevLocation.id, location.id))) { paths.Add((location.id, prevLocation.id), new Path() { id = currentPathId, between = new Tuple <Location, Location>(location, prevLocation) }); currentPathId++; } } prevLocation = location; tile.locations[i] = location; } // Add a path between the previous location and the start location // Check if there already is an existing path between the locations if (!paths.ContainsKey((startLocation.id, prevLocation.id)) && !paths.ContainsKey((prevLocation.id, startLocation.id))) { paths.Add((startLocation.id, prevLocation.id), new Path() { id = currentPathId, between = new Tuple <Location, Location>(startLocation, prevLocation) }); currentPathId++; } // Reset the locations prevLocation = null; startLocation = null; tiles.Add(tile); } // Generate map tile types tiles = GenerateTileTypes(generation, tiles, seed); // Convert map attributes to Map map = new Map(); map.AddLocations(locations.Values); map.AddTiles(tiles); map.AddPaths(paths.Values); return(map); }
private void OnEnable() { myTileGeneration = (TileGeneration)target; //myTileGeneration.debugPathOn = false; }