void GenerateTerrain(int x, int y) { RandomTile piece = GetRandomTile(); if (piece == null) { return; } Sprite spriteToUse = piece.sprite; GameObject newTile = new GameObject(spriteToUse.name); SpriteRenderer newTileRenderer = newTile.AddComponent <SpriteRenderer>(); newTileRenderer.sprite = spriteToUse; newTile.transform.SetParent(Chunk_TerrainParent, false); Vector3 tilePosition = new Vector3(SizeOfTile * x, SizeOfTile * y, TerrainZ); tilePosition.x += ChunkOffsetX; tilePosition.y += ChunkOffsetY; newTile.transform.position = tilePosition; }
RandomTile GetRandomTile() { if (Tiles.Count < 1) { return(null); } int r = Random.Range(0, TerrainTotalWeight); RandomTile p = null; for (int ind = 0; ind < Tiles.Count && p == null; ind++) { if (r <= Tiles[ind].ids) { p = Tiles[ind]; } } if (p == null) { Debug.Log("Not found tile."); } //Debug.Log("RandomTile. Random Number=" + r + " Piece:" + p.sprite.name); return(p); }
private void bAdd_Click(object sender, EventArgs e) { var tile = new RandomTile(); tile.Name = txName.Text; foreach (var s in txItems.Lines) { try { var id = int.Parse(s); tile.Items.Add(id); } catch { } } if (tile.Items.Count == 0) { MessageBox.Show(Pandora.Localization.GetTextProvider()["Random.InvalidIDs"]); return; } txName.Text = ""; txItems.Text = ""; m_TileSet.Tiles.Add(tile); lst.Items.Add(tile); }
public static IEnumerable <HighlitedM> GetHighlitedMs(float x, float y, int UTerrain, ProceduralTiles[] terrains, float RockFound) { var HighlitedMs = new HighlitedM[9]; x = (int)x >> 4; y = (int)y >> 4; int HighlitedMIndex = 0; for (int iX = -1; iX < 2; iX++) { for (int iY = -1; iY < 2; iY++) { var terrain = terrains[RandomTile.Range(x + iX, y + iY, UTerrain, terrains.Length)]; float mass = RandomTile.Percent(x + iX, y + iY, UTerrain) * 8 + 2; HighlitedMs[HighlitedMIndex++] = new HighlitedM() { Terrain = terrain, Location = new Vector2((int)(x + iX) << 4, (int)(y + iY) << 4) }; } } return(HighlitedMs); }
private void bDelItem_Click(object sender, System.EventArgs e) { RandomTile tile = lst.SelectedItem as RandomTile; if (tile != null) { m_TileSet.Tiles.Remove(tile); UpdateTileset(); } }
void OnEnable() { _randomTile = target as RandomTile; _noiseScaleProperty = serializedObject.FindProperty(nameof(RandomTile.NoiseScale)); _tiles.Setup(serializedObject.FindProperty(nameof(_randomTile.Tiles))) .MakeAddable(_addTileButton) .MakeRemovable(_removeTileButton) .MakeHeaderButton(_createTilesButton, CreateTiles, Color.white) .MakeCustomHeight(GetHeight) .MakeReorderable(); }
private void labQuick_DragDrop(object sender, DragEventArgs e) { var deco = e.Data.GetData(typeof(BoxDeco)) as BoxDeco; if (deco != null) { var tile = new RandomTile(); tile.Items.Add(deco.ID); tile.Name = deco.Name; m_TileSet.Tiles.Add(tile); lst.Items.Add(tile); } }
void changeTileOwner(Vector3 pos, int newOwner, bool forceChange) // Change owner of tile at position "pos" { if (!randomTiles.Exists(x => x.position == pos)) // Skip if no tile in that position { return; } RandomTile t = randomTiles.Find(x => x.position == pos); // Fetch struct value (NOT passed by reference) randomTiles.Remove(t); // Remove old struct if (t.owner == -2 || forceChange) // If no owner has been defined yet, give it a new owner { t.owner = newOwner; } randomTiles.Add(t); }
public static HighlitedM near(IEnumerable <HighlitedM> HighlitedMs, Vector2 location, int UTerrain) { HighlitedM HighTileSel = null; float near = float.MaxValue; foreach (var HighlitedM in HighlitedMs) { float rand = RandomTile.Percent( (int)(HighlitedM.Location.x + location.x), (int)(HighlitedM.Location.y + location.y), UTerrain) * 8; float Away = Vector2.Distance(location, HighlitedM.Location); Away -= rand; if (Away < near) { near = Away; HighTileSel = HighlitedM; } } return(HighTileSel); }
public void CreateObstacle() { //Setear layer?? o viene con obstáculo?? //Este for solo suma en i si no instancia ningún obstáculo for (int i = 0; i < obstacleSpawns.Count;) { obstacleRandomNumber = Random.Range(1, 100); //Limpio la lista de spawns cercanos nearbySpawns.Clear(); if (obstacleRandomNumber <= eachTileObstacleProbability) { currentObstacleChecking = obstacleSpawns[Random.Range(0, obstacleSpawns.Count)]; if (currentObstacleChecking.isObstacle) { obstacleLayer = LayerMask.NameToLayer("Obstacle"); } else { obstacleLayer = LayerMask.NameToLayer("NoTileHere"); } //Buscar tiles obstáculos cercanos //1.25 porque es la mitad entre 1 tile y 1 tile y medio for (int j = 0; j < obstacleSpawns.Count; j++) { if (obstacleSpawns[j] != currentObstacleChecking) { if (Vector3.Distance(obstacleSpawns[j].transform.position, currentObstacleChecking.transform.position) <= 1.25f) { //Obstáculos de 2 solo funcionan en horizontal if (obstacleSpawns[j].transform.position.z == currentObstacleChecking.transform.position.z) { nearbySpawns.Add(obstacleSpawns[j]); } } } } //Si hay un spawn cerca miro la posibilidad de instanciar un obstáculo que ocupe 2 if (nearbySpawns.Count > 0) { //Si supera el random la probabilidad instancio un obstáculo de 2. if (Random.Range(1, 100) <= probabilityOf2tilesObstacle) { currentsecondObstacleChecking = nearbySpawns[Random.Range(0, nearbySpawns.Count)]; //Instancio el obstáculo randomPos = Random.Range(0, twoTileObstacleConfig.Count); obstacleInstantiated = Instantiate(twoTileObstacleConfig[randomPos].obstacleAsset, (currentObstacleChecking.transform.position + currentsecondObstacleChecking.transform.position) / 2, twoTileObstacleConfig[randomPos].obstacleAsset.transform.rotation); ////Recoloco la rotación del obstáculo //if (currentObstacleChecking.transform.position.z != currentsecondObstacleChecking.transform.position.z || // currentObstacleChecking.transform.position.x != currentsecondObstacleChecking.transform.position.x) //{ // obstacleInstantiated.transform.Rotate(new Vector3(0,90,0)); //} obstacleSpawns.Remove(currentObstacleChecking); obstacleSpawns.Remove(currentsecondObstacleChecking); } //Si no sale mismo codigo que en else de abajo. Instancio obstáculo de 1 else { //Si no hay obstáculos cercanos instancio un obstáculo de 1 tile randomPos = Random.Range(0, oneTileObstacleConfig.Count); obstacleInstantiated = Instantiate(oneTileObstacleConfig[randomPos].obstacleAsset, currentObstacleChecking.transform.position, oneTileObstacleConfig[randomPos].obstacleAsset.transform.rotation); //Elimino el spawn de obstáculos ocupado de la lista obstacleSpawns.Remove(currentObstacleChecking); } } //Si no hay spawns cercano instancio obstáculo de 1. else { //Si no hay obstáculos cercanos instancio un obstáculo de 1 tile randomPos = Random.Range(0, oneTileObstacleConfig.Count); obstacleInstantiated = Instantiate(oneTileObstacleConfig[randomPos].obstacleAsset, currentObstacleChecking.transform.position, oneTileObstacleConfig[randomPos].obstacleAsset.transform.rotation); //Elimino el spawn de obstáculos ocupado de la lista obstacleSpawns.Remove(currentObstacleChecking); } //obstacleInstantiated.AddComponent<BoxCollider>(); //obstacleInstantiated.GetComponent<BoxCollider>().size = new Vector3(0.9f,0.9f,0.9f); //obstacleInstantiated.layer = obstacleLayer; } else { i++; continue; } } }
public Sprite TileFetch(float x, float y, int UTerrain) { return(Tiles[RandomTile.Range(x, y, UTerrain, Tiles.Length)]); }