private void Invert() { TileSet inverseSelection = new TileSet(); foreach (Tile nextTile in FPGA.FPGA.Instance.GetAllTiles()) { if (!TileSelectionManager.Instance.IsSelected(nextTile.TileKey)) { inverseSelection.Add(nextTile); } } TileSelectionManager.Instance.ClearSelection(); foreach (Tile t in inverseSelection) { TileSelectionManager.Instance.AddToSelection(t.TileKey, false); } TileSelectionManager.Instance.SelectionChanged(); }
public void Genererate() { /// create tile set tileSet = new TileSet(); tileSet.width = TileSet.map.width; tileSet.height = TileSet.map.height; // create room types List <Tile.Type> roomTypes = new List <Tile.Type> (); Tile.Type type = Tile.Type.LivingRoom; /// debug interior : create fix list of rooms roomTypes.Add(Tile.Type.Bathroom); roomTypes.Add(Tile.Type.Bedroom); roomTypes.Add(Tile.Type.ChildBedroom); roomTypes.Add(Tile.Type.Kitchen); roomTypes.Add(Tile.Type.Toilet); // create hallway Coords hallway_Coords = tileSet.Center; Coords hallway_Dir = new Coords(0, 1); int a = 0; while (roomTypes.Count > 0) { // add new hallway tile Tile newHallwayTile = new Tile(hallway_Coords); newHallwayTile.SetType(Tile.Type.Hallway); if (tileSet.tiles.ContainsKey(hallway_Coords)) { hallway_Coords += hallway_Dir; ++a; continue; } tileSet.Add(hallway_Coords, newHallwayTile); // set entrance door if (a == 0) { Item doorItem = Item.CreateNewItem("porte"); doorItem.AddProperty("entrance", "true"); // il n'y a plus réellement de porte dehors en fait non ? //doorItem.word.SetAdjective(TileSet.map.GetTile(TileSet.map.playerCoords).items[0].word.GetAdjective); doorItem.AddProperty("direction", "to south"); newHallwayTile.AddItem(doorItem); } // check if room appears if (Random.value < chanceCreateRoom) { Coords side = new Coords(hallway_Dir.x, hallway_Dir.y); side.Turn(); Coords coords = newHallwayTile.coords + side ; if (tileSet.tiles.ContainsKey(coords)) { continue; } Tile newRoomTile = new Tile(coords); Tile.Type roomType = roomTypes [Random.Range(0, roomTypes.Count)]; newRoomTile.SetType(roomType); roomTypes.Remove(roomType); if (Random.value < chanceEnclosedRoom) { newRoomTile.enclosed = true; } tileSet.Add(coords, newRoomTile); } hallway_Coords += hallway_Dir; if (Random.value < chanceHallwayTurn) { hallway_Dir.Turn(); } ++a; } InitStoryTiles(); // ADDING DOORS AddDoors(); }
public IEnumerable<TileBase> GetTiles( Rectangle bounds, [NotNull] IEnumerable<TileBase> existingTiles) { TileSet tiles = new TileSet(); Queue<TileBase> openTiles = new Queue<TileBase>(); List<TileBase> removeTiles = new List<TileBase>(); Rectangle tileBounds; foreach (TileBase tile in existingTiles) { // if tile is in bounds // TODO The width and height must also be >= 1px tileBounds = tile.GetApproximateBounds(); if (bounds.IntersectsWith(tileBounds)) { tiles.Add(tile); if (tile.GetOpenEdgeParts().Any()) openTiles.Enqueue(tile); } else removeTiles.Add(tile); } foreach (TileBase tile in removeTiles) tile.RemoveAdjacent(); if (tiles.Count < 1) { TileBase tile = Tiles[0]; Debug.Assert(tile != null, "tile != null"); // TODO The width and height must also be >= 1px tileBounds = tile.GetApproximateBounds(); if (!bounds.IntersectsWith(tileBounds)) { tile = new TileInstance( (Tile) tile, tile.Label, tile.Transform * Matrix3x2.CreateTranslation(bounds.Center - tileBounds.Center)); } // add initial tile to tiles tiles.Add(tile); // add initial tile to end of openTiles openTiles.Enqueue(tile); } // while there are tiles with no neighbour while (openTiles.Count > 0) { TileBase tile = openTiles.Dequeue(); // for each edgePart with no neighbour foreach (EdgePart edgePart in tile.GetOpenEdgeParts()) { TileBase newTile = CreateNewTile(tile, edgePart); tiles.Add(newTile); // if newTile is in bounds // TODO The width and height must also be >= 1px tileBounds = newTile.GetApproximateBounds(); if (bounds.IntersectsWith(tileBounds)) { // add newTile to end of openTiles openTiles.Enqueue(newTile); } } } // Set the style for the new cells foreach (TileBase tile in tiles.Where(t => t.Style == null)) { // set cell style from styleManager tile.Style = StyleManager.GetStyle(tile); } return tiles.ToArray(); }
public override void OnInspectorGUI() { serializedObject.Update(); TileSet tileSet = (TileSet)target; EditorGUILayout.LabelField($"Serialization status: {tileSet.status}"); // Needed to plan out the whole UI string[] allVariants = tileSet.GetVariants(); // Ensure that the list of booleans matches the number of variants appropriately. if (variantCount != allVariants.Length) { // Create new if we haven't already. if (variantCount == -1 || variantVisibility == null) { variantVisibility = new List <bool>(); } // Too small, so add some new entries (closed by default) if (variantCount < allVariants.Length) { for (int i = variantCount; i < allVariants.Length; i++) { variantVisibility.Add(false); } } // Too big, so cut off the last elements without modifying previous else { for (int i = variantCount; i > allVariants.Length; i--) { variantVisibility.RemoveAt(i); } } // Update the size so we can resize next time variantCount = allVariants.Length; } showPosition = EditorGUILayout.Foldout(showPosition, "Tiles in dictionary"); if (showPosition) { EditorGUI.indentLevel++; Debug.Log($"Found {variantCount} variants."); // For each variant, create an entry for (int i = 0; i < allVariants.Length; i++) { // Grab all Tile objects List <Tile> tiles = null; bool found = tileSet.Get(new TileSet.VariantKey(TileType.ANY, allVariants[i]), ref tiles); if (!found) { Debug.LogError($"Failed to find any tiles for variant {allVariants[i]}"); } else { Debug.Log($"For variant {allVariants[i]}, found {tiles.Count} tiles."); } variantVisibility[i] = EditorGUILayout.Foldout(variantVisibility[i], $"Variant \"{allVariants[i]}\""); if (variantVisibility[i]) { EditorGUI.indentLevel++; for (int j = 0; j < TileType.TypeList.Length; j++) { Tile foundTile = null; foreach (Tile tile in tiles) { if (tile.type == TileType.TypeList[j]) { foundTile = tile; break; } } if (foundTile != null) { //SerializedObject serObj = new SerializedObject(foundTile); //EditorGUILayout.PropertyField(serObj.FindProperty("gameObject"), new GUIContent(TileType.TypeList[j].Name)); GameObject gameObject = EditorGUILayout.ObjectField(new GUIContent(TileType.TypeList[j].Name), foundTile, typeof(Tile), false) as GameObject; } else { //Debug.Log($"Couldn't find a Tile for variant {allVariants[i]} and type {TileType.TypeList[j].Name}. Filling with blank space."); //Tile blankTile = null; //EditorGUILayout.ObjectField(blankTile, typeof(Tile)); //EditorGUILayout.PropertyField(new SerializedProperty()); Tile blankTile = null; blankTile = EditorGUILayout.ObjectField(new GUIContent(TileType.TypeList[j].Name), blankTile, typeof(Tile), false) as Tile; if (blankTile != null) { tileSet.Add(blankTile); } } } EditorGUI.indentLevel--; } } // New variant field if (addingVariant) { string newName = EditorGUILayout.TextField("VariantName"); if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return) { addingVariant = false; Tile dummyTile = new Tile() { type = TileType.ANY, variant = newName }; tileSet.Add(dummyTile); } } // Button to toggle above field visibility if (GUILayout.Button("Add new variant")) { addingVariant = true; } EditorGUI.indentLevel--; } serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Compiles all Tiles found under "Assets/Tiles/" into a TileSet, accounting /// for variant folders. Creates a default TileSet asset for use in GameManager. /// </summary> public void GenerateTileSet() { // Clean up the input folders so we can reference files within them properly. string relativeTilePath = TrimAssetFolder(tilePath); string relativeTileSetPath = TrimAssetFolder(tileSetPath); // Ensure TileSet output path exists. DirectoryInfo outputFolder = new DirectoryInfo(Application.dataPath + sep + relativeTileSetPath); if (!outputFolder.Exists) { outputFolder.Create(); } // Try to load the Tile assets from the Tile directory //DirectoryInfo modelFolder = new DirectoryInfo(Application.dataPath + sep + "Tiles"); DirectoryInfo tileFolder = new DirectoryInfo(Application.dataPath + sep + relativeTilePath); // The directories here represent different variants. DirectoryInfo[] variantFolders = tileFolder.GetDirectories(); TileSet newTileSet = ScriptableObject.CreateInstance <TileSet>(); for (int i = 0; i < variantFolders.Length; i++) { string variantName = variantFolders[i].Name.ToLowerInvariant(); // Go through each variant folder and extract all the models we recognize the name of. FileInfo[] tileFiles = variantFolders[i].GetFiles(); for (int j = 0; j < tileFiles.Length; j++) { // Ignore .meta files if (tileFiles[j].Extension.Equals(".meta")) { continue; } //string tileFilePath = "Assets" + sep + "Tiles" + sep + variantName + sep + tileFiles[j].Name; string tileFilePath = "Assets" + sep + relativeTilePath + sep + variantName + sep + tileFiles[j].Name; Tile tile = AssetDatabase.LoadAssetAtPath <Tile>(tileFilePath); if (tile == null) { Debug.LogWarning($"Failed to load in file \"{tileFilePath}\"."); continue; } // Add the Tile file to the Tile pile. //if (GameManager.Instance != null) //{ // GameManager.Instance.TileSet.Add(tile); //} //else //{ // Debug.LogWarning("GameManager instance is null- can't yet add assets outside of play time"); //} newTileSet.Add(tile); } } // Create the TileSet into a new asset. //AssetDatabase.CreateAsset(newTileSet, "Assets/TileSets/default.asset"); //string outputPath = Path.Combine(Application.streamingAssetsPath, relativeTileSetPath, tileSetName + ".asset"); //BuildPipeline.BuildAssetBundle(newTileSet, null, outputPath, BuildAssetBundleOptions.None, EditorUserBuildSettings.activeBuildTarget); // TODO use asset bundles? AssetDatabase.CreateAsset(newTileSet, "Assets" + sep + relativeTileSetPath + sep + tileSetName + ".asset"); }