/// <summary> /// Adds the locked door to dungeon. /// </summary> public static void AddLockedDoorToDungeon(Dungeon dungeon, GameObject doorPrefab, Doorway doorway) { dungeon.LockedDoorList.Add(doorPrefab.GetComponent <LockedDoor>()); }
private void SpawnDoorPrefab(Doorway a, Doorway b, System.Random randomStream) { // This door already has a prefab instance placed, exit early if (a.HasDoorPrefabInstance || b.HasDoorPrefabInstance) { return; } // Add door prefab Doorway chosenDoor; bool doorwayAHasEntries = a.ConnectorPrefabWeights.HasAnyViableEntries(); bool doorwayBHasEntries = b.ConnectorPrefabWeights.HasAnyViableEntries(); // No doorway has a prefab to place, exit early if (!doorwayAHasEntries && !doorwayBHasEntries) { return; } // If both doorways have door prefabs.. if (doorwayAHasEntries && doorwayBHasEntries) { // ..A is selected if its priority is greater than or equal to B.. if (a.DoorPrefabPriority >= b.DoorPrefabPriority) { chosenDoor = a; } // .. otherwise, B is chosen.. else { chosenDoor = b; } } // ..if only one doorway has a prefab, use that one else { chosenDoor = (doorwayAHasEntries) ? a : b; } GameObject doorPrefab = chosenDoor.ConnectorPrefabWeights.GetRandom(randomStream); if (doorPrefab != null) { GameObject door = Instantiate(doorPrefab, chosenDoor.transform); door.transform.localPosition = Vector3.zero; if (!chosenDoor.AvoidRotatingDoorPrefab) { door.transform.localRotation = Quaternion.identity; } doors.Add(door); DungeonUtil.AddAndSetupDoorComponent(this, door, chosenDoor); a.SetUsedPrefab(door); b.SetUsedPrefab(door); } }
/// <summary> /// Adds a Door component to the selected doorPrefab if one doesn't already exist /// </summary> /// <param name="dungeon">The dungeon that this door belongs to</param> /// <param name="doorPrefab">The door prefab on which to apply the component</param> /// <param name="doorway">The doorway that this door belongs to</param> public static void AddAndSetupDoorComponent(Dungeon dungeon, GameObject doorPrefab, Doorway doorway) { var door = doorPrefab.GetComponent <Door>(); if (door == null) { door = doorPrefab.AddComponent <Door>(); } door.Dungeon = dungeon; door.DoorwayA = doorway; door.DoorwayB = doorway.ConnectedDoorway; door.TileA = doorway.Tile; door.TileB = doorway.ConnectedDoorway.Tile; }
public DoorwayPair(Tile previousTile, Doorway previousDoorway, PreProcessTileData nextTemplate, Doorway nextDoorway, TileSet nextTileSet, float tileWeight, float doorwayWeight) { PreviousTile = previousTile; PreviousDoorway = previousDoorway; NextTemplate = nextTemplate; NextDoorway = nextDoorway; NextTileSet = nextTileSet; TileWeight = tileWeight; DoorwayWeight = doorwayWeight; }
public DoorwayConnection(Doorway a, Doorway b) { A = a; B = b; }
internal void MakeConnection(Doorway a, Doorway b, System.Random randomStream) { bool areDoorwaysFromDifferentDungeons = (a.Dungeon != b.Dungeon); a.Tile.Placement.UnusedDoorways.Remove(a); a.Tile.Placement.UsedDoorways.Add(a); b.Tile.Placement.UnusedDoorways.Remove(b); b.Tile.Placement.UsedDoorways.Add(b); a.ConnectedDoorway = b; b.ConnectedDoorway = a; if (!areDoorwaysFromDifferentDungeons) { var conn = new DoorwayConnection(a, b); connections.Add(conn); } // Add door prefab Doorway chosenDoor; // If both doorways have door prefabs.. if (a.DoorPrefabs.Count > 0 && b.DoorPrefabs.Count > 0) { // ..A is selected if its priority is greater than or equal to B.. if (a.DoorPrefabPriority >= b.DoorPrefabPriority) { chosenDoor = a; } // .. otherwise, B is chosen.. else { chosenDoor = b; } } // ..if only one doorway has a prefab, use that one else { chosenDoor = (a.DoorPrefabs.Count > 0) ? a : b; } List <GameObject> doorPrefabs = chosenDoor.DoorPrefabs; if (doorPrefabs.Count > 0 && !(a.HasDoorPrefab || b.HasDoorPrefab)) { GameObject doorPrefab = doorPrefabs[randomStream.Next(0, doorPrefabs.Count)]; if (doorPrefab != null) { GameObject door = (GameObject)GameObject.Instantiate(doorPrefab); door.transform.parent = gameObject.transform; door.transform.position = a.transform.position; door.transform.localScale = a.transform.localScale; if (!chosenDoor.AvoidRotatingDoorPrefab) { door.transform.rotation = a.transform.rotation; } doors.Add(door); a.SetUsedPrefab(door); b.SetUsedPrefab(door); DungeonUtil.AddAndSetupDoorComponent(this, door, a); } } }
public bool ChooseRandomDoorway(System.Random random, DoorwaySocketType?socketGroupFilter, Vector3?allowedDirection, out int doorwayIndex, out Doorway doorway) { doorwayIndex = -1; doorway = null; IEnumerable <Doorway> possibleDoorways = Doorways; if (socketGroupFilter.HasValue) { possibleDoorways = possibleDoorways.Where(x => { return(DoorwaySocket.IsMatchingSocket(x.SocketGroup, socketGroupFilter.Value)); }); } if (allowedDirection.HasValue) { possibleDoorways = possibleDoorways.Where(x => { return(x.transform.forward == allowedDirection); }); } if (possibleDoorways.Count() == 0) { return(false); } doorway = possibleDoorways.ElementAt(random.Next(0, possibleDoorways.Count())); doorwayIndex = Doorways.IndexOf(doorway); return(true); }