public void DrawLayerEditor(TileSetLayer layer) { var tmpName = EditorGUILayout.TextField("Layer name", layer.Name); var tmpLayerType = (TileSetLayerType)EditorGUILayout.EnumPopup("Type", layer.LayerType); var tmpWidth = EditorGUILayout.IntField(new GUIContent("Width", TILESET_WIDTH_TOOLTIP), layer.TileSetWidth); var tmpHeight = EditorGUILayout.IntField(new GUIContent("Height", TILESET_HEIGHT_TOOLTIP), layer.TileSetHeight); var tmpTexture = (Texture2D)EditorGUILayout.ObjectField("Texture", layer.Texture, typeof(Texture2D), false); // Detect changes if (tmpName != layer.Name || tmpLayerType != layer.LayerType || tmpWidth != layer.TileSetWidth || tmpHeight != layer.TileSetHeight || tmpTexture != layer.Texture) { layer.Applied = false; } layer.Name = tmpName; layer.LayerType = tmpLayerType; layer.TileSetWidth = tmpWidth; layer.TileSetHeight = tmpHeight; layer.Texture = tmpTexture; if (layer.Applied && layer.Texture != null) { DrawLayerTileEditor(layer); } }
public void Apply() { if (!ValidateTileSet()) { return; } foreach (var entry in LocalLayers) { if (!entry.Applied) { if (!entry.Apply()) { return; } } } foreach (var layer in LocalLayers) { var tileSetEntry = GetLayerFromGuid(layer.Guid); if (tileSetEntry == null) { tileSetEntry = new TileSetLayer(layer); TileSet.Layers.Add(tileSetEntry); } else { tileSetEntry.CopyFrom(layer); } } // Make sure the new tileset is saved EditorUtility.SetDirty(target); }
protected void AddUvs(TileSetLayer tileSetLayer, int tile, List <Vector2> uvs) { foreach (var uvCords in tileSetLayer.Tiles[tile].UvCords) { uvs.Add(uvCords); } }
protected void AddUvs(int tile, List <Vector2> uvs, TileSetLayer layer) { foreach (var uvCord in layer.Tiles[tile].UvCords) { uvs.Add(uvCord); } }
public void AddLayer() { var localLayer = new TileSetLayer(); localLayer.IsOpenInEditor = true; LocalLayers.Add(localLayer); this.Repaint(); }
private static TileSetLayer ParserTileSetLayer(XmlNode tilesetLayerNode) { int width = -1; int height = -1; for (int i = 0; i < tilesetLayerNode.Attributes.Count; i++) { XmlNode attribute = tilesetLayerNode.Attributes.Item(i); string attributeName = tilesetLayerNode.Attributes.Item(i).Name; switch (attributeName) { case "width": width = int.Parse(attribute.Value); break; case "height": height = int.Parse(attribute.Value); break; default: break; } } string name; float offsetX; float offsetY; bool visible; float opacity; ParserLayerBaseAttributes(tilesetLayerNode, out name, out offsetX, out offsetY, out visible, out opacity); TileSetLayer tileSetLayer = new TileSetLayer(width, height, name, offsetX, offsetY, opacity, visible); XmlNode dataNode = tilesetLayerNode.ChildNodes.Item(0); string[] data = dataNode.InnerText.Split(','); int y = 0; int x = 0; for (int i = 0; i < data.Length; i++) { tileSetLayer.Tiles[x, y] = int.Parse(data[i]); if ((i + 1) % width == 0) { x = 0; y++; } else { x++; } } return(tileSetLayer); }
public TilePoolPresenter(TilePool tilePool) { _tilePool = tilePool; _tilePool.TileRemoved += TilePoolTileRemoved; _tileSet = new TileSetLayer(tilePool.Name, tilePool); _annotations = new ObservableCollection <Annotation>(); InitializeLayerHierarchy(); }
public void DrawLayerTileEditor(TileSetLayer layer) { if (layer.TileSetWidth <= 0 || layer.TileSetHeight <= 0) { return; } int bufferSize = 32; int windowSize = Screen.width - bufferSize; int tileWidth = (int)Mathf.Floor(windowSize / layer.TileSetWidth); GUI.BeginGroup(GUILayoutUtility.GetRect(windowSize, layer.TileSetHeight * tileWidth)); int height = layer.TileSetHeight * tileWidth; for (int y = 0; y < layer.TileSetHeight; y++) { for (int x = 0; x < layer.TileSetWidth; x++) { int num = (y * layer.TileSetWidth) + x; Rect rect = new Rect(x * tileWidth, height - ((y + 1) * tileWidth), tileWidth, tileWidth); GUI.DrawTextureWithTexCoords(rect, layer.Texture, layer.Tiles[num].Rect); string buttonText = ""; if (layer.Tiles[num].Pathing == TilePathing.BaseUnwalkable) { buttonText = "X"; } else if (layer.Tiles[num].Pathing == TilePathing.BaseWalkable) { buttonText = "O"; } else if (layer.Tiles[num].Pathing == TilePathing.OverlayInherit) { buttonText = "-"; } else if (layer.Tiles[num].Pathing == TilePathing.OverlayUnwalkable) { buttonText = "U"; } else if (layer.Tiles[num].Pathing == TilePathing.OverlayWalkable) { buttonText = "W"; } if (GUI.Button(rect, buttonText, GuiStyle)) { CycleType(layer, layer.Tiles[num]); } } } GUI.EndGroup(); }
public void AlterLayer(TileSetLayer tileSetLayer, int layerIndex) { var segmentGameObject = GetObjectFromLayer(tileSetLayer); if (segmentGameObject != null) { var layer = segmentGameObject.GetComponent <MapSegmentLayer>(); layer.TileSetLayer = tileSetLayer; ApplyChanges(layer, segmentGameObject, layerIndex); } }
public bool HasLayer(TileSetLayer segmentLayer) { foreach (var layer in Layers) { if (layer.Guid == segmentLayer.Guid) { return(true); } } return(false); }
public void CreateNewLayer(TileSetLayer tileSetLayer, int layerIndex) { GameObject segmentGameObject = new GameObject("MapSegmentLayer"); var layer = segmentGameObject.AddComponent <MapSegmentLayer>(); layer.MapSegment = MapSegment; layer.TileSetLayer = tileSetLayer; segmentGameObject.gameObject.transform.parent = MapSegment.transform; ApplyChanges(layer, segmentGameObject, layerIndex); EditorUtility.SetDirty(segmentGameObject); }
public GameObject GetObjectFromLayer(TileSetLayer tileSetLayer) { foreach (var tmpLayer in MapSegment.GetComponentsInChildren <MapSegmentLayer>()) { if (tmpLayer.TileSetLayer.Guid == tileSetLayer.Guid) { return(tmpLayer.gameObject); } } // This should really never happen Debug.LogError("Could not find the correct GameObject to alter"); return(null); }
public bool HasLayerOfType(TileSetLayer tileSetLayer) { // The layers list might be out of date, so fetch the latest list from the actuall children var tmpLayers = GetComponentsInChildren <MapSegmentLayer>(); foreach (var layer in tmpLayers) { if (layer.TileSetLayer.Guid == tileSetLayer.Guid) { return(true); } } return(false); }
private void BuildTexture(TileSetLayer tileSetLayer) { int textureWidth = numberTilesX * tileResolution; int textureHeight = numberTilesY * tileResolution; Texture2D texture = new Texture2D(textureWidth, textureHeight); texture.alphaIsTransparency = true; Color[][] tiles = SplitTileset(); Debug.Log(">> Build Texture"); Debug.Log(" # Texture Resolution: " + texture.width + " x " + texture.width); int tileRowIndex = 0; for (int y = numberTilesY - 1; y > -1; y--) { int lineInPixels = y * tileResolution; for (int x = 0; x < numberTilesX; x++) { Color[] tile = transparentColor; int tileID = tileSetLayer.Tiles[x, tileRowIndex]; if (tileID != TileSetLayer.EMPTY_TILE) { tile = tiles[tileID - 1]; if (tileSetLayer.Opacity < ALPHA_OPAQUE) { SetOpacity(tile, tileSetLayer.Opacity); } } texture.SetPixels(x * tileResolution, lineInPixels, tileResolution, tileResolution, tile); } tileRowIndex++; } texture.filterMode = FilterMode; texture.wrapMode = WrapMode; texture.Apply(); MeshRenderer meshRenderer = GetComponent <MeshRenderer>(); meshRenderer.material.mainTexture = texture; }
public void Reset() { TileSet = (TileSet)target; LocalLayers = new List <TileSetLayer>(); if (TileSet == null) { return; } foreach (var entry in TileSet.Layers) { var tmpEntry = new TileSetLayer(entry); tmpEntry.Applied = true; LocalLayers.Add(tmpEntry); } }
public void CopyFrom(TileSetLayer other) { Guid = other.Guid; Name = other.Name; TileSetWidth = other.TileSetWidth; TileSetHeight = other.TileSetHeight; LayerType = other.LayerType; Texture = other.Texture; uvOffsetSize = other.uvOffsetSize; Tiles = CopyTiles(Tiles, other.Tiles.Length); for (int i = 0; i < Tiles.Length; i++) { Tiles[i].CopyFrom(other.Tiles[i]); } Applied = false; }
public void CycleType(TileSetLayer layer, Tile tile) { if (layer.LayerType == TileSetLayerType.BaseLayer) { if (tile.Pathing == TilePathing.BaseUnwalkable) { tile.Pathing = TilePathing.BaseWalkable; } else if (tile.Pathing == TilePathing.BaseWalkable) { tile.Pathing = TilePathing.BaseUnwalkable; } else { tile.Pathing = TilePathing.BaseUnwalkable; } } else if (layer.LayerType == TileSetLayerType.OnTopOverlay || layer.LayerType == TileSetLayerType.Overlay) { if (tile.Pathing == TilePathing.OverlayInherit) { tile.Pathing = TilePathing.OverlayUnwalkable; } else if (tile.Pathing == TilePathing.OverlayUnwalkable) { tile.Pathing = TilePathing.OverlayWalkable; } else if (tile.Pathing == TilePathing.OverlayWalkable) { tile.Pathing = TilePathing.OverlayInherit; } else { tile.Pathing = TilePathing.OverlayInherit; } } else { tile.Pathing = TilePathing.BaseUnwalkable; } }
public TileSetLayerPresenter(TileSetLayer layer) { _layer = layer; }
public TileSetLayer(TileSetLayer other) { Tiles = new Tile[0]; CopyFrom(other); }
public bool ContainsLayer(TileSetLayer layer) { return(GetGuids().Contains(layer.Guid)); }