//another override. this one is overriding the method used to display an icon in the assets folder //i want the tile's texture to be visible from the assets folder for ease of use. //this code replaces the normal default icon with the tile's sprite texture. //the normal method in the "Editor" class just returns a boring generic icon. public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height) { StoneTile tile = target as StoneTile; if (tile == null || tile.sprite == null) { return(null); //use the default icon if no custom one is available } Texture2D cache = new Texture2D(width, height); //create a new texture variable EditorUtility.CopySerialized(AssetPreview.GetAssetPreview(tile.sprite.texture), cache); //write the tile's texture into it return(cache); //and display! }
private void Update() { if (Input.GetKeyDown(KeyCode.A)) { seed = Random.Range(-10000000, 1000000); Generation(); } if (Input.GetKeyDown(KeyCode.D)) { StoneTile.ClearAllTiles(); DirtTile.ClearAllTiles(); GrassTile.ClearAllTiles(); } }
public TerrainTile CreateTerrainFromType(TerrainType type, BaseTileData baseTileData) { TerrainTile newTile = null; TerrainBinding terrainBinding = GetTerrainBindingFromType(type); if (terrainBinding != null) { switch (type) { case TerrainType.Plains: newTile = new PlainsTile(); break; case TerrainType.Water: newTile = new WaterTile(); break; case TerrainType.Wood: newTile = new WoodsTile(); break; case TerrainType.Stone: newTile = new StoneTile(); break; case TerrainType.Sand: newTile = new SandTile(); break; default: throw new MissingTerrainTypeDefinitionException(); } } baseTileData.terrainTile = newTile; TerrainInfo terrainInfo = Instantiate(terrainBinding.terrainVisualInfo, baseTileData.worldPosition, Quaternion.identity, _terrainTilemap.transform); terrainInfo.dataTile = newTile; newTile.terrainInfo = terrainInfo; newTile.GridPosition = baseTileData.GridPosition; return(newTile); }
void Generation() { for (int x = 0; x < width; x++) { //Height Generation height = Mathf.RoundToInt(heightValue * Mathf.PerlinNoise(x / smoothness, seed)); //Max Stone Spawn Distance int minStoneSpawnDistance = height - minStoneheight; int maxStoneSpawnDistance = height - maxStoneheight; int totalStoneSpawnDistance = Random.Range(minStoneSpawnDistance, maxStoneSpawnDistance); int maxGrassHeightDistance = height; int maxWaterSpawnDistance = maxGrassHeightDistance; int mimWaterSpawnDistance = height - 0; for (int y = 0; y < height; y++) { if (y < totalStoneSpawnDistance) { StoneTile.SetTile(new Vector3Int(x, y, 0), Stone); } else { DirtTile.SetTile(new Vector3Int(x, y, 0), Dirt); } if (totalStoneSpawnDistance == height) { StoneTile.SetTile(new Vector3Int(x, height, 0), Stone); } else { GrassTile.SetTile(new Vector3Int(x, height, 0), Grass); } } } }
public virtual ITile GetTile(string tileType) { switch (tileType) { case "Ceramic": if (!tiles.ContainsKey("Ceramic")) { tiles["Ceramic"] = new CeramicTile(); } return(tiles["Ceramic"]); case "Stone": if (!tiles.ContainsKey("Stone")) { tiles["Stone"] = new StoneTile(); } return(tiles["Stone"]); } return(new NullTile()); }
public void CreateGrid() { StreamReader sr = new StreamReader(@"Level1.txt"); List <string> stringList = new List <string>(); while (!sr.EndOfStream) { stringList.Add(sr.ReadLine()); } grid = new Tile[GlobalValues.HOLE_LENGTH / GlobalValues.TILE_SIZE, GlobalValues.HOLE_HEIGHT / GlobalValues.TILE_SIZE]; for (int i = 0; i < GlobalValues.HOLE_HEIGHT / GlobalValues.TILE_SIZE; i++) { var line = stringList[i]; for (int k = 0; k < GlobalValues.HOLE_LENGTH / GlobalValues.TILE_SIZE && k < line.Length; k++) { switch (line[k]) { case 'G': grid[k, i] = new GreenTile(TextureLibrary.green, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'F': grid[k, i] = new FairwayTile(TextureLibrary.fairway, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'R': grid[k, i] = new RoughTile(TextureLibrary.rough, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'C': grid[k, i] = new CupTile(TextureLibrary.cup, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'B': grid[k, i] = new BunkerTile(TextureLibrary.bunker, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'S': grid[k, i] = new StoneTile(TextureLibrary.stone, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'W': grid[k, i] = new WaterTile(TextureLibrary.water, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'M': grid[k, i] = new MudTile(TextureLibrary.mud, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'P': grid[k, i] = new FlagStickTile(TextureLibrary.flagpost, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'Q': grid[k, i] = new FlagTile(TextureLibrary.flag, new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE)); tiles.Add(grid[k, i]); break; case 'X': ballStartPos = new Vector2(k * GlobalValues.TILE_SIZE, i * GlobalValues.TILE_SIZE); break; } } } }
private void FixedUpdate() { digDir = new Vector2(x, y).normalized; //Debug.Log("new: " + digDir + " old: " +oldDir); changed = false; if (digDir != oldDir) { changed = true; } if (!(digProgress > 0) && !rocket) { sound.Stop(0); body.position += new Vector2(x, 0); if (x < 0) { animator.Play("Walk_Left"); } if (x > 0) { animator.Play("Walk_Right"); } if (x == 0) { animator.Play("Idle"); } } if (rocket && !(digProgress > 0)) { sound.Stop(0); body.position += new Vector2(x, 0); body.AddForce(new Vector2(0, 20), ForceMode2D.Force); animator.Play("Fly_Up"); jetpack.emissionRate = 100; } else { jetpack.emissionRate = 0; } if (digDir.magnitude > 0 && !rocket && !changed) { try { if (digDir.y > 0 || Mathf.Abs(digDir.x) > 0) { digDir.y = 0; } RaycastHit2D hit = Physics2D.CircleCast(this.transform.position, 0.3f, digDir, 0.35f); if (hit.collider.CompareTag("Blocks")) { sound.Play(0); if (x > 0) { animator.Play("Drill_Right"); } if (x < 0) { animator.Play("Drill_Left"); } if (y < 0) { animator.Play("Drill_Down"); } Vector3Int gridPos = grid.WorldToCell(hit.point + (digDir * 0.1f)); Vector2 particlePos = new Vector2(gridPos.x + 0.5f, gridPos.y + 0.5f); digParticles.transform.position = particlePos; shaker.ShakeCameraContinuous(0.2f, 0.02f); StoneTile stone = (StoneTile)stoneMap.GetTile(gridPos); OreTile ore = (OreTile)oreMap.GetTile(gridPos); bool inBounds = !(gridPos.x >= 7 || gridPos.x < -7); if (inBounds) { if (stone.hardness <= (GlobalVars.level + 1)) { digProgress += Time.deltaTime; try { digParticleRenderer.material = particleMats[stone.hardness - 1]; } catch { } } else { digParticleRenderer.material = sparkMat; } digParticles.emissionRate = 25; if (digProgress >= 0.75f) { stoneMap.SetTile(gridPos, null); oreMap.SetTile(gridPos, null); digProgress = 0; digParticles.emissionRate = 0; if (ore.dropItem != null) { Instantiate(ore.dropItem, particlePos, Quaternion.identity); } } } } } catch//(System.NullReferenceException n) { //Debug.Log("drill hit air"); } } else { digProgress = 0; digParticles.emissionRate = 0; } oldDir = digDir; }