public void ChangeArea(ChunkTile startTile, ChunkTile endTile, ChunkTileSerialized newTile) { int width = endTile.worldX - startTile.worldX; int height = endTile.worldY - startTile.worldY; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { ChunkTile tile = m_completeMap[startTile.worldX + x, startTile.worldY + y]; tile.chunk.ChangeBlockAt(tile.x, tile.y, newTile); } } }
private void RefreshUI() { if (ManagerInstance.Get <DatabaseManager>().dataBase != null) { for (int i = 0; i < ManagerInstance.Get <DatabaseManager>().dataBase.loadedData.Count; i++) { ChunkTileSerialized tile = ManagerInstance.Get <DatabaseManager>().dataBase.loadedData[i]; GameObject ui = GameObject.Instantiate(Resources.Load("UI/Tile Button") as GameObject); ui.transform.parent = transform; ui.name = "Tile: " + tile.identity; ui.GetComponent <RectTransform>().anchoredPosition = new Vector2(10 + i * 85, 0); ui.GetComponent <RectTransform>().localScale = new Vector2(1, 1); ui.GetComponent <Image>().sprite = Sprite.Create(ManagerInstance.Get <DatabaseManager>().dataBase.loadedGraphics[i].ToTexture(ManagerInstance.Get <DatabaseManager>().dataBase.loadedGraphics[i].texture), new Rect(0, 0, WorldGraphicsManager.TILE_RESOLUTION, WorldGraphicsManager.TILE_RESOLUTION), new Vector2(0, 0)); ui.GetComponent <TileSelectionButton>().tileIndex = i; m_tileButtons.Add(ui); } } }
public void ChangeTo(ChunkTileSerialized tile) { chunk.ChangeBlockAt(x, y, tile); }
//--------------Set Methods-------------- public void ChangeBlockAt(int x, int y, ChunkTileSerialized newTile, bool checkNeighbors = true) { if (m_tiles[x, y].identity != newTile.identity) { m_tiles[x, y].AddToDrawQueue(); if (checkNeighbors) { List <ChunkTile> neighbors = m_tiles[x, y].GetAllNeighbors(); for (int i = 0; i < m_tiles[x, y].GetAllNeighbors().Count; i++) { if (neighbors[i] == null) { break; } int nY = 1; int nX = 1; if (m_tiles[x, y].worldX > neighbors[i].worldX) { nX++; } else if (m_tiles[x, y].worldX < neighbors[i].worldX) { nX--; } if (m_tiles[x, y].worldY > neighbors[i].worldY) { nY++; } else if (m_tiles[x, y].worldY < neighbors[i].worldY) { nY--; } if (neighbors[i].identity != newTile.identity) { if (neighbors[i].GetProperty <int>("height") < newTile.GetProperty <int>("height")) { neighbors[i].drawMap.SetBorderAt(nX, nY, BorderType.Shadow); } else if (neighbors[i].GetProperty <int>("height") == newTile.GetProperty <int>("height")) { neighbors[i].drawMap.SetBorderAt(nX, nY, BorderType.Merge); } if (nX == 0) { nX = 2; } else if (nX == 2) { nX = 0; } if (nY == 0) { nY = 2; } else if (nY == 2) { nY = 0; } if (neighbors[i].GetProperty <int>("height") > newTile.GetProperty <int>("height")) { m_tiles[x, y].drawMap.SetBorderAt(nX, nY, BorderType.Shadow); } else { m_tiles[x, y].drawMap.SetBorderAt(nX, nY, BorderType.None); } neighbors[i].AddToDrawQueue(); } else { neighbors[i].drawMap.RemoveBorderAt(nX, nY); if (nX == 0) { nX = 2; } else if (nX == 2) { nX = 0; } if (nY == 0) { nY = 2; } else if (nY == 2) { nY = 0; } m_tiles[x, y].drawMap.RemoveBorderAt(nX, nY); neighbors[i].AddToDrawQueue(); } } } //mod if (ManagerInstance.Get <ModManager>() != null) { for (int i = 0; i < ManagerInstance.Get <ModManager>().loadedMods.Count; i++) { if (ManagerInstance.Get <ModManager>().loadedMods[i].GetType().GetInterface("ITileScript") == typeof(ITileScript)) { ITileScript tileScript = ((ITileScript)ManagerInstance.Get <ModManager>().loadedMods[i]); for (int t = 0; t < tileScript.tiles.Length; t++) { if (tileScript.tiles[t] == newTile.identity) { tileScript.OnTileBuild(m_tiles[x, y].worldX, m_tiles[x, y].worldY); } else if (tileScript.tiles[t] == m_tiles[x, y].identity) { tileScript.OnTileDestroy(m_tiles[x, y].worldX, m_tiles[x, y].worldY); } } } } } m_tiles[x, y].CopyProperties(newTile.GetAllProperties()); if (ManagerInstance.Get <PathingManager>() != null) { ManagerInstance.Get <PathingManager>().SetTraversableAt(m_tiles[x, y].worldX, m_tiles[x, y].worldY, newTile.traversable); } } }
private void OnGUI() { if (m_dataBase == null) { m_dataBase = new Database <ChunkTileSerialized, TileGraphics>("tiles", "tile"); } if (GUILayout.Button("Load Tiles")) { m_dataBase.LoadItems(); } if (m_dataBase.loadedData != null) { List <ChunkTileSerialized> tiles = m_dataBase.loadedData; for (int i = 0; i < tiles.Count; i++) { for (int p = 0; p < tiles[i].GetAllProperties().Count; p++) { GUILayout.BeginHorizontal(); GUILayout.Label(tiles[i].GetAllProperties()[p].Key); if (tiles[i].GetAllProperties()[p].Value.GetType() == typeof(string)) { tiles[i].SetProperty(tiles[i].GetAllProperties()[p].Key, EditorGUILayout.TextField(tiles[i].GetProperty <string>(tiles[i].GetAllProperties()[p].Key))); } if (tiles[i].GetAllProperties()[p].Value.GetType() == typeof(int)) { tiles[i].SetProperty(tiles[i].GetAllProperties()[p].Key, EditorGUILayout.IntField(tiles[i].GetProperty <int>(tiles[i].GetAllProperties()[p].Key))); } if (tiles[i].GetAllProperties()[p].Value.GetType() == typeof(float)) { tiles[i].SetProperty(tiles[i].GetAllProperties()[p].Key, EditorGUILayout.FloatField(tiles[i].GetProperty <float>(tiles[i].GetAllProperties()[p].Key))); } if (tiles[i].GetAllProperties()[p].Value.GetType() == typeof(bool)) { tiles[i].SetProperty(tiles[i].GetAllProperties()[p].Key, EditorGUILayout.Toggle(tiles[i].GetProperty <bool>(tiles[i].GetAllProperties()[p].Key))); } if (GUILayout.Button("X", GUILayout.Width(20))) { tiles[i].GetAllProperties().Remove(tiles[i].GetAllProperties()[p]); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal(); if (m_dataBase.loadedGraphics.Count > i) { if (m_dataBase.loadedGraphics[i].texture == null) { GUILayout.Box("No graphics.png detected."); } else { GUILayout.Box(m_dataBase.loadedGraphics[i].ToTexture(m_dataBase.loadedGraphics[i].texture)); } } GUILayout.BeginVertical(); if (GUILayout.Button("Open Folder")) { System.Diagnostics.Process.Start(tiles[i].dataPath); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (GUILayout.Button("New Property")) { showNewPropertyField = true; tileToAddTo = tiles[i]; } Line(); } if (GUILayout.Button("New Tile")) { m_dataBase.CreateItem(); } if (GUILayout.Button("Save Tiles")) { m_dataBase.SaveItems(); } Line(); if (showNewPropertyField) { ShowNewProperyWindow(); } } }