internal void LoadTexture() { if (File.Exists("worlds/" + ImagePath)) { ImagePath = "worlds/" + ImagePath; } TileTexture = Texture.NewTexture(ImagePath); try { TileTexture.LoadTextureFromFile(); } catch { try { TileTexture.LoadTextureFromResource(); } catch { throw new System.IO.FileNotFoundException("Could not find texture for tileset", ImagePath); } } if (Properties == null) { Properties = new Dictionary <string, string>(); } if (_tileProperties == null) { _tileProperties = new Dictionary <string, Dictionary <string, string> >(); } TileProperties = new TileProperties(_tileProperties, FirstGID); }
public Texture2D GetTexture(TileTexture tileTexture, int region) { if (textureSet.ContainsKey(tileTexture)) { if (region == 0) { return(textureSet[tileTexture][0]); } else { int index = 0; for (int c = 0; c < region; c++) { index++; if (index >= textureSet[tileTexture].Count) { index = 0; } } return(textureSet[tileTexture][index]); } } return(nullTex); }
private void HandleInput() { if (Event.current.type == EventType.KeyDown) { if (Event.current.keyCode == KeyCode.A) { _currentIndex = Math.Max(_currentIndex - 1, 0); _currentIndex = Math.Min(_currentIndex, Tileset.Assets.Count - 1); SetTile(_currentIndex); } if (Event.current.keyCode == KeyCode.D) { _currentIndex = Math.Min(_currentIndex + 1, Tileset.Assets.Count - 1); SetTile(_currentIndex); } if (Event.current.keyCode == KeyCode.Delete) { if (Delete()) { CurrentSelection = null; _currentIndex = -1; return; } } if (Event.current.keyCode == KeyCode.Alpha1) { CurrentSelection.Connections ^= (ConnectionMask)(1 << 0); } if (Event.current.keyCode == KeyCode.Alpha2) { CurrentSelection.Connections ^= (ConnectionMask)(1 << 1); } if (Event.current.keyCode == KeyCode.Alpha3) { CurrentSelection.Connections ^= (ConnectionMask)(1 << 2); } if (Event.current.keyCode == KeyCode.Alpha4) { CurrentSelection.Connections ^= (ConnectionMask)(1 << 3); } if (Event.current.keyCode == KeyCode.Alpha5) { //all CurrentSelection.Connections = (ConnectionMask)15; } if (Event.current.keyCode == KeyCode.Alpha6) { CurrentSelection.Connections = 0; } Repaint(); } }
private void SetTile(int index) { if (index == -1) { return; } CurrentSelection = Tileset.Assets[index]; _currentIndex = index; Repaint(); }
// Use this for initialization void Awake() { if (instance == null) { instance = this; } if (instance != this) { Destroy(gameObject); } }
/// <summary> /// Gets the material by name if the tile has a custom material /// </summary> /// <param name="name">The name of the texture</param> /// <returns>Requested material or null</returns> public Material GetTileCustomMaterial(string name) { TileTexture tt = tileTextures.Where(x => x.name == name).FirstOrDefault(); if (tt == null) { return(null); } return(tt.customMaterial); }
public static void DrawTile(TileTexture tiles, TileIndex index, Vector2 position, Color?color = null, TextureMirror mirror = TextureMirror.None) { Engine.DrawTexture( tiles.Texture, position: position, color: color, scaleMode: TextureScaleMode.Nearest, source: new Bounds2(index * tiles.SourceSize, tiles.SourceSize), size: tiles.DestinationSize, mirror: mirror); }
public bool SetBrush(TileTexture texture) { if (TilerMap == null) { return(false); } DrawTool.SetBrush(new NormalBrush(TilerMap.TileResolution, texture)); Repaint(); return(true); }
private NormalBrush GetBrush(IEnumerable <Tileset> tilesets, Tile tile, int textureSize) { var c = tile.Collision; var collision = new bool[c.Length]; Array.Copy(c, collision, c.Length); var id = tile.Properties.ID; var setID = (int)(id >> 32); Tileset ts = null; // Find matching tileset // ReSharper disable LoopCanBeConvertedToQuery foreach (var t in tilesets) // ReSharper restore LoopCanBeConvertedToQuery { if (t.TilesetID == setID) { ts = t; break; } } TileTexture tt = null; if (ts) { // Find matching tile tt = ts.Assets.Find(a => a.ID == id); } if (tt == null) { tt = TileTexture.None; } var brush = new NormalBrush(textureSize, tt); for (var i = 0; i < 4; i++) { if (brush.GetBrush().Properties.Rot == tile.Properties.Rot) { break; } brush.Rotate(); } return(brush); }
public void SetTileset(Tileset ts) { Tileset = ts; CurrentSelection = null; _currentIndex = -1; Repaint(); var nullAssets = Tileset.Assets.FindAll(t => t.Texture == null); foreach (var asset in nullAssets) { Tileset.Assets.Remove(asset); } }
public void Render(Tile tile, Camera camera) { var game = _master.State.Manager.Game; _shader.Start(); Matrix4x4 transformation = Maths.CreateTransformationMatrix(tile.DrawX, tile.DrawY, camera.Scale); _shader.LoadMatrix("transformation", transformation); Matrix4x4 viewMatrix = Maths.CreateViewMatrix(camera); _shader.LoadMatrix("viewMatrix", viewMatrix); float aspectRatio = (float)game.Witdh / game.Height; Matrix4x4 projection = Maths.CreateProjectionMatrix(game.Height * aspectRatio, game.Height);; _shader.LoadMatrix("projection", projection); _vao.Bind(); _gl.EnableVertexAttribArray(0); _gl.EnableVertexAttribArray(1); Texture texture = TileTexture.Get(tile.TileType); texture.Bind(); _gl.DrawArrays(PrimitiveType.Triangles, 0, 6); texture.Unbind(); if (tile.WindPower > 0) { _numbers[tile.WindPower - 1].Bind(); _gl.DrawArrays(PrimitiveType.Triangles, 0, 6); _numbers[tile.WindPower - 1].Unbind(); } if (tile.Turbined) { TileTexture.Turbine.Bind(); _gl.DrawArrays(PrimitiveType.Triangles, 0, 6); TileTexture.Turbine.Unbind(); } _gl.DisableVertexAttribArray(0); _gl.DisableVertexAttribArray(1); _vao.Unbind(); _shader.Stop(); }
const float TILE_TEXTURE_SIZE = 0.25f;//assumes 4X4 texture should change later public static Vector2[] GetFaceUVs(Direction _direction, Voxel _voxel) { Vector2[] uvs = new Vector2[4]; TileTexture tile_texture_pos = _voxel.GetTextureCoordsByDirection(_direction); //Calculate uvs based on tile coordinates uvs[0] = new Vector2(TILE_TEXTURE_SIZE * tile_texture_pos.x, TILE_TEXTURE_SIZE * tile_texture_pos.y); uvs[1] = new Vector2(TILE_TEXTURE_SIZE * tile_texture_pos.x, TILE_TEXTURE_SIZE * tile_texture_pos.y + TILE_TEXTURE_SIZE); uvs[2] = new Vector2(TILE_TEXTURE_SIZE * tile_texture_pos.x + TILE_TEXTURE_SIZE, TILE_TEXTURE_SIZE * tile_texture_pos.y + TILE_TEXTURE_SIZE); uvs[3] = new Vector2(TILE_TEXTURE_SIZE * tile_texture_pos.x + TILE_TEXTURE_SIZE, TILE_TEXTURE_SIZE * tile_texture_pos.y); return(uvs); }
/// <summary> /// Get the texture by name /// </summary> /// <param name="name">The name of the texture</param> /// <returns>Requested texture or null</returns> public Texture2D GetTileTexture(string name, bool dither) { TileTexture tt = tileTextures.Where(x => x.name == name).FirstOrDefault(); if (tt == null) { return(null); } Texture2D texture = tt.texture; if (dither && tt.ditherTex != null && tt.ditherTex.Length > 0 && Random.value <= tt.ditherChance) { texture = tt.ditherTex[Random.Range(0, tt.ditherTex.Length)]; } return(texture); }
public void CreateFace(Vector3 corner, Vector3 up, Vector3 right, TileTexture tileTexture) { int tIndex = _verts.Count; _verts.Add(corner); _verts.Add(corner + up); _verts.Add(corner + up + right); _verts.Add(corner + right); _tris.Add(tIndex + 0); _tris.Add(tIndex + 1); _tris.Add(tIndex + 2); _tris.Add(tIndex + 2); _tris.Add(tIndex + 3); _tris.Add(tIndex + 0); _uvs.AddRange(tileTexture.GetUVs()); }
public TileTexture AddAsset(Texture2D texture) { TileTexture exists = Assets.FirstOrDefault(t => t.Texture == texture); if (exists == null) { int id = NextTileID; long uid = ((long)TilesetID << 32) | (uint)id; texture.name = id.ToString(CultureInfo.InvariantCulture); var tt = new TileTexture(uid, texture, Collision); Assets.Add(tt); return(tt); } return(exists); }
public TileTexture AddAsset(Texture2D texture) { TileTexture exists = Assets.FirstOrDefault(t => t.Texture == texture); if (exists == null) { int id = NextTileID; long uid = ((long)TilesetID << 32) | (uint)id; texture.name = id.ToString(CultureInfo.InvariantCulture); var tt = new TileTexture(uid, texture, Collision); Assets.Add(tt); return tt; } return exists; }
public static void DrawTileString(TileTexture tileFont, string text, Vector2 position, Color?color = null) { float step = tileFont.DestinationSize.X; float left = position.X; foreach (char c in text) { if (c == '\n') { position.X = left; position.Y += step; } else { DrawTile(tileFont, new TileIndex(c % 16, c / 16), position, color); position.X += step; } } }
void UpdatePreviewTile(bool timer) { if (inAnimMode) { if (timer) { Image endTileImage = new Bitmap(picTileset.Width, picTileset.Height); using (var graphics = System.Drawing.Graphics.FromImage(endTileImage)) { TileTexture tex = chosenAnim.Frames[animFrame]; graphics.DrawImage(tiles[tex.Sheet], 0, 0, new Rectangle(tex.Texture.X * Graphics.TextureManager.TILE_SIZE, tex.Texture.Y * Graphics.TextureManager.TILE_SIZE, Graphics.TextureManager.TILE_SIZE, Graphics.TextureManager.TILE_SIZE), GraphicsUnit.Pixel); } picTile.Image = endTileImage; } else { lblTileInfo.Text = "[Animation]"; } } else { Image endTileImage = new Bitmap(picTileset.Width, picTileset.Height); lock (drawLock) { using (var graphics = System.Drawing.Graphics.FromImage(endTileImage)) { graphics.DrawImage(tiles[chosenTileset], 0, 0, new Rectangle(chosenTile.X * Graphics.TextureManager.TILE_SIZE, chosenTile.Y * Graphics.TextureManager.TILE_SIZE, Graphics.TextureManager.TILE_SIZE, Graphics.TextureManager.TILE_SIZE), GraphicsUnit.Pixel); } picTile.Image = endTileImage; } lblTileInfo.Text = "Tile" + chosenTileset + " X" + chosenTile.X + " Y" + chosenTile.Y; } }
public void Start() { TileTexture.Init(); _level = new Level(this); _manager.Game.Camera.MaxXDistance = _level.PixelWidth / 2.0f; _manager.Game.Camera.MaxYDistance = _level.PixelHeight / 2.0f; _manager.Game.Camera.CanZoom = true; _renderer = new GameStateRenderer(this); _finishButton = new Button(1150.0f, 50.0f, 100.0f, 100.0f, Finish); _resetButton = new Button(1150.0f, 175.0f, 100.0f, 100.0f, Reset); _reset = ResourceManager.LoadTexture("Reset_Button"); _finish = ResourceManager.LoadTexture("Finish_Button"); _star = ResourceManager.LoadTexture("Sun"); _stopwatch = Stopwatch.StartNew(); AudioManager.Stop(); MusicMaster.State = MusicState.Game; switch (LevelMeta.name) { case "level1": AudioManager.Play("./Assets/Sound/Introduction.wav"); break; case "level4": AudioManager.Play("./Assets/Sound/Coversation_1.wav"); break; case "level7": AudioManager.Play("./Assets/Sound/Coversation_2.wav"); break; } }
private void SetTile(int index) { if (index == -1) return; CurrentSelection = Tileset.Assets[index]; _currentIndex = index; Repaint(); }
private void DrawTextures() { const int space = 2; const int previewSize = 64; // 15 for scrollbar var size = Parent.position.width - PropertyWidth - ListWidth - WindowPadding * 2; var width = (int)Mathf.Max((size - 16) / (previewSize + space), 1); for (int index = 0; index < Tileset.Assets.Count; index += width) { EditorGUILayout.BeginHorizontal(); var hor = Mathf.Min(Tileset.Assets.Count - index, width); for (var i = 0; i < hor; i++) { var assetIndex = index + i; var t = Tileset.Assets[assetIndex]; var rect = GUILayoutUtility.GetRect(64, 64, GUIStyle.none); GUI.color = CurrentSelection == t ? new Color(153 / 255f, 204 / 255f, 1f, 1) : Color.white; GUI.DrawTexture(rect, t.Texture); if (Event.current.type == EventType.MouseDown) { if (rect.Contains(Event.current.mousePosition)) { if (Event.current.button == 0) { SetTile(assetIndex); } } } rect.x += rect.width - 20; rect.width = 20; rect.height = 20; GUI.color = Color.red; if (GUI.Button(rect, "X")) { if (Delete()) { i--; hor = Mathf.Min(Tileset.Assets.Count - index, width); if (t == CurrentSelection) { CurrentSelection = null; _currentIndex = -1; } } } GUILayout.Space(space); GUI.color = Color.white; } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); GUILayout.Space(space); } }
private void HandleInput() { if (Event.current.type == EventType.keyDown) { if (Event.current.keyCode == KeyCode.A) { _currentIndex = Math.Max(_currentIndex - 1, 0); _currentIndex = Math.Min(_currentIndex, Tileset.Assets.Count - 1); SetTile(_currentIndex); } if (Event.current.keyCode == KeyCode.D) { _currentIndex = Math.Min(_currentIndex + 1, Tileset.Assets.Count - 1); SetTile(_currentIndex); } if (Event.current.keyCode == KeyCode.Delete) { if (Delete()) { CurrentSelection = null; _currentIndex = -1; return; } } if (Event.current.keyCode == KeyCode.Alpha1) { CurrentSelection.Connections ^= (ConnectionMask)(1 << 0); } if (Event.current.keyCode == KeyCode.Alpha2) { CurrentSelection.Connections ^= (ConnectionMask)(1 << 1); } if (Event.current.keyCode == KeyCode.Alpha3) { CurrentSelection.Connections ^= (ConnectionMask)(1 << 2); } if (Event.current.keyCode == KeyCode.Alpha4) { CurrentSelection.Connections ^= (ConnectionMask)(1 << 3); } if (Event.current.keyCode == KeyCode.Alpha5) { //all CurrentSelection.Connections = (ConnectionMask)15; } if (Event.current.keyCode == KeyCode.Alpha6) { CurrentSelection.Connections = 0; } Repaint(); } }
public bool SetBrush(TileTexture texture) { if (TilerMap == null) return false; DrawTool.SetBrush(new NormalBrush(TilerMap.TileResolution, texture)); Repaint(); return true; }
static TileIndex GetCellAt(Vector2 point, TileTexture tiles) { return new TileIndex( (int)Math.Floor(point.X / tiles.DestinationSize.X), (int)Math.Floor(point.Y / tiles.DestinationSize.Y)); }
// 设计时 含初始化 public TileItem(TileTexture texture, int tileId) { this.Texture = texture; this.TileId = tileId; Initialize(); }