/// <summary> /// Detects and seals the opening with a wall depending on the side. /// </summary> /// <param name="side"></param> public void CloseOpening(string side) { Tile newtile; int openingindex = CalculateOpening(side); if (side == "Left") { newtile = new Tile("Left_Wall", PrefabManager.GetInstance().GetAllRoomTiles().Where(obj => obj.name == "Left_Wall").First(), RoomTiles[openingindex].Position); } else if (side == "Top") { newtile = new Tile("Top_Wall", PrefabManager.GetInstance().GetAllRoomTiles().Where(obj => obj.name == "Top_Wall").First(), RoomTiles[openingindex].Position); } else if (side == "Right") { newtile = new Tile("Right_Wall", PrefabManager.GetInstance().GetAllRoomTiles().Where(obj => obj.name == "Right_Wall").First(), RoomTiles[openingindex].Position); } else { newtile = new Tile("Bottom_Wall", PrefabManager.GetInstance().GetAllRoomTiles().Where(obj => obj.name == "Bottom_Wall").First(), RoomTiles[openingindex].Position); } RoomTiles[openingindex] = newtile; Vector3 oldtileloc = new Vector3(0, 0, 0); if (Instantiated_Tiles != null)//If room is already instatiated. { oldtileloc = Instantiated_Tiles[openingindex].transform.position; //Destroy old opening. Object.Destroy(Instantiated_Tiles[openingindex]); //Instantiate new opening. Instantiated_Tiles[openingindex] = Object.Instantiate(newtile.Objtile, oldtileloc, new Quaternion(), RoomObject.transform); } }
public Player PlayerConstructor(Vector3 pos, Vector2 scale, PlayerState iniState) { if (_prefabManager == null) { var pIns = PrefabManager.GetInstance(); if (pIns == null) { throw new Exception("get null prefab manager"); } _prefabManager = pIns; } var playerPrefab = _prefabManager.GetGameObject("Player"); if (playerPrefab == null) { throw new Exception("get null player prefab"); } var playerObject = Object.Instantiate(playerPrefab); playerObject.transform.position = pos; playerObject.transform.localScale = scale; var controller = playerObject.AddComponent <OperationEventListener>(); var player = playerObject.GetComponent <Player>(); player.InitPlayer(controller, iniState); player.ModifySelfId(Guid.NewGuid()); _sendInit(playerObject, "Player"); return(player); }
private void Start() { Skill skill = SkillOperationFactory.GetSkillOperation("Q"); QQQ q = skill as QQQ; q.targetHero = new MyHero("阿卡丽"); q.SkillRelease(); skill = SkillOperationFactory.GetSkillOperation("W"); WWWW w = skill as WWWW; w.pos = new Vector3(1, 1, 1); skill.SkillRelease(); Skill rSkill = SkillOperationFactory.GetSkillOperation("R"); GameObject heroPrefab = Resources.Load <GameObject>("heroPrefab"); //Other Script GameObject otherHeroPrefab = Resources.Load <GameObject>("heroPrefab"); //Test:资源动态加载 // PrefabManager.GetInstance().CreateGameObjectByPrefab("Body"); // PrefabManager.GetInstance().CreateGameObjectByPrefab( // "Body", new Vector3(1, 1, 1), Quaternion.identity); PrefabManager.GetInstance().CreateGameObjectByPrefab( "Body", Camera.main.transform, Vector3.zero, Quaternion.identity); }
private void _instantiateObject(JSONObject jsonObject) { var guid = Guid.Parse(jsonObject["uuid"].str); var position = Jsonify.JsontoVector(jsonObject["transform"]["position"]); var rotation = Jsonify.JsontoVector(jsonObject["transform"]["rotation"]); var prefab = jsonObject["prefab"].str; switch (prefab) { case "Player": UnityMainThread.Worker.AddJob(() => { _playerCount++; var pref = PrefabManager.GetInstance().GetGameObject($"P{_playerCount}Sprite"); var obj = Object.Instantiate(pref, position, Quaternion.Euler(rotation)); obj.transform.localScale = Vector3.one * 0.4f; obj.GetComponent <UuidObject>().ModifySelfId(guid); }); break; default: UnityMainThread.Worker.AddJob(() => { var pref = PrefabManager.GetInstance().GetGameObject(prefab); var obj = Object.Instantiate(pref, position, Quaternion.Euler(rotation)); obj.GetComponent <UuidObject>().ModifySelfId(guid); }); break; } }
private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { GameObject go = PrefabManager.GetInstance().CreateGameObjectByPrefab("Prefab"); Destroy(go, 2f); } }
public Stone(Vector3 pos, World world) : base(pos) { this.world = world; cube = GameObject.Instantiate(PrefabManager.GetInstance().GetPrefab(PrefabType.Stone).GetGameObject()); cube.transform.position = pos; rigidbody = cube.GetComponent <Rigidbody>(); cube.AddComponent <CubeActor>(); actor = cube.GetComponent <CubeActor>(); }
private void CreateIndicatorSetIfNeeded() { //create if needed if (resourceIndicatorSet == null) { resourceIndicatorSet = GameObject.Instantiate(PrefabManager.GetInstance().indicatorSet, UIManager.WorldToUISpace(this.transform.position), Quaternion.identity, UIManager.GetCanvas().transform); resourceIndicatorSet.GetComponent <IndicatorSet>().owner = this.gameObject; } }
public Cloud(Vector3 pos, World world) : base(pos) { this.world = world; cube = GameObject.Instantiate(PrefabManager.GetInstance().GetPrefab(PrefabType.Cloud).GetGameObject()); cube.transform.position = pos; cube.AddComponent <CubeActor>(); actor = cube.GetComponent <CubeActor>(); standTime = 2; chainAble = true; }
private void _buildOnlineClient() { MapFactory.GlobalSpeed = 0; EventManager.GetInstance().HookNetworking(); var uiPrefab = PrefabManager.GetInstance().GetGameObject("UIController"); var ui = Instantiate(uiPrefab, canvas.transform); UuidManager.GetInstance().HookNetworking(); creator.PlayerConstructor(Vector3.zero, Vector2.zero, PlayerState.Jump); }
void Start() { camTrans = transform.Find("Main Camera"); screen = DebugScreen.GetInstance(); world = GameObject.Find("World").GetComponent <World>(); promptText = GameObject.Find("Selection prompt").GetComponent <Text>(); //设置Enermy默认模型 enermyModelPrefab = PrefabManager.GetInstance().GetPrefab(PrefabType.Breaker); InitMonsterModel(); }
void Start() { currentHealth = startHealth; currentMoveSpeed = startMoveSpeed; currentDamage = startDamage; currentEXP = startEXP; currentFund = startFund; prefabManager = PrefabManager.GetInstance(); enemies.Add(prefabManager.GetPrefab("Zombie")); }
private NetworkManager() { if (_instance != null) { return; } var pref = PrefabManager.GetInstance().GetGameObject("Network"); var gameObject = Object.Instantiate(pref); Object.DontDestroyOnLoad(gameObject); _instance = gameObject.GetComponent <SocketIOComponent>(); _self = this; }
void Start() { currentHealth = startHealth; currentMoveSpeed = startMoveSpeed; currentDamage = startDamage; currentEXP = startEXP; currentFund = startFund; prefabManager = PrefabManager.GetInstance(); enemies.Add(prefabManager.GetPrefab("Zombie")); gameManager = GameObject.Find("GameManager").GetComponent <GameManager>(); }
public IPlatform PlatformConstructor(Vector3 pos, Vector2 scale, PlatformTypes type) { if (_prefabManager == null) { var pIns = PrefabManager.GetInstance(); if (pIns == null) { throw new Exception("get null prefab manager"); } _prefabManager = pIns; } string platform; switch (type) { case PlatformTypes.Direction: platform = "DirectionPlatform"; break; case PlatformTypes.Fragile: platform = "FragilePlatform"; break; case PlatformTypes.Freeze: platform = "FreezePlatform"; break; case PlatformTypes.Normal: platform = "NormalPlatform"; break; case PlatformTypes.Spike: platform = "SpikePlatform"; break; case PlatformTypes.Time: platform = "TimePlatform"; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } GameObject gameObject = _prefabManager.GetGameObject(platform); var instance = Object.Instantiate(gameObject); instance.transform.position = pos; instance.transform.localScale = scale; _sendInit(instance, platform); return(instance.GetComponent <IPlatform>()); }
public void Clean() { if (_instance == null) { return; } Object.Destroy(_instance.gameObject); var pref = PrefabManager.GetInstance().GetGameObject("Network"); var gameObject = Object.Instantiate(pref); Object.DontDestroyOnLoad(gameObject); _instance = gameObject.GetComponent <SocketIOComponent>(); }
private void Start() { if (PrefabManager.GetInstance() == null) { throw new ApplicationException("can not init prefab manager"); } Instance = this; #if BUILD_SERVER GameChoice.Gamemode = GameMode.Server; #endif switch (Application.platform) { case RuntimePlatform.Android: if (GameChoice.GameMode == GameMode.Offline) { creator = new AppOfflineConstructor(); _buildAppOffline(); } break; case RuntimePlatform.LinuxPlayer: break; case RuntimePlatform.OSXEditor: case RuntimePlatform.OSXPlayer: case RuntimePlatform.WindowsPlayer: case RuntimePlatform.WindowsEditor: if (GameChoice.GameMode == GameMode.Offline) { creator = new PcOfflineConstructor(); _buildPcOffline(); } else if (GameChoice.GameMode == GameMode.Online) { creator = new OnlineClientConstructor(); _buildOnlineClient(); } else if (GameChoice.GameMode == GameMode.Server) { creator = new ServerConstructor(); _buildOnlineServer(); } break; default: throw new ArgumentException($"does not support at platform {Application.platform}"); } }
private void _buildPcOffline() { #region map_creation var locations = new[] { new Vector2(1.75f, 3.45f), new Vector2(4.78f, 2.02f), new Vector2(-2.04f, 1.34f), new Vector2(0.42f, -0.4f), new Vector2(-2.07f, -2.43f), new Vector2(4.49f, -2.43f) }; MapFactory.GetInstance(); MapFactory.PlatformScale = 2; foreach (var location in locations) { creator.PlatformConstructor(location, Vector2.one * 2, PlatformTypes.Normal); } #endregion #region player_creation const int pScale = 4; var p1 = creator.PlayerConstructor(new Vector2(-2.78f, 2.48f), Vector2.one * pScale, PlayerState.Jump); p1.name = "p1"; var p2 = creator.PlayerConstructor(new Vector2(3.904f, -3.963f), Vector2.one * pScale, PlayerState.Attack); p2.GetComponent <PcKeyboardModel>().walk = new[] { KeyCode.UpArrow, KeyCode.DownArrow, KeyCode.LeftArrow, KeyCode.RightArrow }; p2.GetComponent <PcKeyboardModel>().clicked = KeyCode.KeypadEnter; p2.name = "p2"; var prefabManager = PrefabManager.GetInstance(); if (prefabManager == null) { print("null prefab manager"); } _setPlayerSprite(prefabManager.GetGameObject("P1Sprite"), p1); _setPlayerSprite(prefabManager.GetGameObject("P2Sprite"), p2); #endregion var round = new GameObject("GameRound"); round.AddComponent <GameRound>(); var ui = PrefabManager.GetInstance().GetGameObject("UIController"); Instantiate(ui, canvas); }
// 死亡行为 // 死后使地下的方块塌陷 public Breaker(Vector3 pos, World world) : base(pos) { Debug.Log("world: " + world); //随机方向种子 thisWorld = world; Random.InitState(0); //初始化各个参数 cubeIdx = thisWorld.GetCubes(); moveSpeed = 0.2f; traceDepth = 5; health = 1; monster = GameObject.Instantiate(PrefabManager.GetInstance().GetPrefab(PrefabType.Breaker).GetGameObject()); monsterAni = monster.GetComponent <Animator>(); monster.transform.position = pos; this.OnCreate(); }
/// <summary> /// 初始化 /// </summary> private void Init() { //计算格子网格的长度(纵向的格子数量) grid_Length = (int)(-cubeOriginPos * transform.localScale.x * 2 / cubeOriginScale); //计算格子网格的宽度(横向的格子数量) grid_Width = (int)(-cubeOriginPos * transform.localScale.z * 2 / cubeOriginScale); //实例化二维数组 allCubes = new CubeGrid[grid_Length, grid_Width]; for (int i = 0; i < grid_Length; i++) { for (int j = 0; j < grid_Width; j++) { //计算每个格子的x坐标 float x = cubeOriginPos * transform.localScale.x + cubeOriginScale * i + cubeOriginScale / 2; //计算每个格子的z坐标 float z = cubeOriginPos * transform.localScale.z + cubeOriginScale * j + cubeOriginScale / 2; //生成格子 GameObject currentGrid = PrefabManager.GetInstance(). CreateGameObjectByPrefab("CubeGrid", new Vector3(x, 0, z), Quaternion.identity); //获取格子组件 CubeGrid cubeGrid = currentGrid.GetComponent <CubeGrid>(); //设置格子所对应的坐标【3,4】 cubeGrid.x = i; cubeGrid.z = j; //随机一个数 int randomNum = Random.Range(1, 101); //如果当前随机数进入障碍物概率范围 if (randomNum <= obsticleScale) { //设置格子类型为障碍物 cubeGrid.SetGridType(GridType.Obsticle); } //放置到二维数组 allCubes[i, j] = cubeGrid; } } //通过数组找到起点,并设置为起点类型 allCubes[(int)startPos.x, (int)startPos.y].SetGridType(GridType.Start); //通过数组找到终点,并设置为终点类型 allCubes[(int)endPos.x, (int)endPos.y].SetGridType(GridType.End); }
private void _buildAppOffline() { Screen.orientation = ScreenOrientation.Portrait; #region map_creation var locations = new[] { new Vector2(1.75f, 6.45f), new Vector2(4.78f, 4.02f), new Vector2(-2.04f, 2.34f), new Vector2(0.42f, -0.4f), new Vector2(-2.07f, -4.43f), new Vector2(4.49f, -4.43f) }; var mapFactory = MapFactory.GetInstance(); MapFactory.PlatformScale = 2; mapFactory.YLocation = 9; mapFactory.SpawnSpeed = 2.5f; foreach (var location in locations) { creator.PlatformConstructor(location, Vector2.one * 2, PlatformTypes.Normal); } #endregion #region player_creation const int pScale = 4; var p1 = creator.PlayerConstructor(new Vector2(-2.78f, 2.48f), Vector2.one * pScale, PlayerState.Jump); p1.name = "p1"; var p2 = creator.PlayerConstructor(new Vector2(3.904f, -3.963f), Vector2.one * pScale, PlayerState.Attack); p2.name = "p2"; var prefabManager = PrefabManager.GetInstance(); if (prefabManager == null) { print("null prefab manager"); } _setPlayerSprite(prefabManager.GetGameObject("P1Sprite"), p1); _setPlayerSprite(prefabManager.GetGameObject("P2Sprite"), p2); #endregion var round = new GameObject("GameRound"); round.AddComponent <GameRound>(); var ui = PrefabManager.GetInstance().GetGameObject("AppUIController"); Instantiate(ui, canvas); }
/// <summary> /// 加载模块 /// </summary> /// <param name="moduleName"></param> private void LoadModule(string moduleName, Vector2 anchoredPosition) { //如果字典中根本没有该模块,或字典里该模块的值为空 if (!_uiModules.ContainsKey(moduleName) || _uiModules[moduleName] == null) { //通过模块名称获取对应的资源路径 string panelPath = UIConfigurationManager.GetInstance().GetPanelPrefabPathByName(moduleName); //加载预设体,并生成对应的对象 GameObject module = PrefabManager.GetInstance().CreateGameObjectByPrefab(panelPath, _canvas, anchoredPosition); //修改模块的名称,去掉(Clone) module.name = moduleName; //获取模块组件 UIModuleBase moduleBase = module.GetComponent <UIModuleBase>(); //添加到字典里 _uiModules[moduleName] = moduleBase; } }
private void UpdateSelectIndex(int length, float scrool) { if (scrool != 0) { if (scrool > 0) { selectIndex = (selectIndex + 1) % length; } else if (scrool < 0) { int complete = length - 1; selectIndex = (selectIndex + complete) % length; } if (editMode == EditMode.MonsterMode) { enermyModelPrefab = PrefabManager.GetInstance().GetPrefabByMonsterType((MonsterType)selectIndex); InitMonsterModel(); } } }
void Start() { animator = GetComponent <Animator>(); weaponBob = GetComponent <WeaponBob>(); InitAmmo(); originalPos = transform.localPosition; crosshair = GameObject.Find("Crosshair").GetComponent <Image>(); prefabManager = PrefabManager.GetInstance(); spriteManager = SpriteManager.GetInstance(); crosshairCross = spriteManager.GetSprite("Crosshair_Default"); crosshairCrossAim = spriteManager.GetSprite("Crosshair_Default_Aim"); crosshairCircle = spriteManager.GetSprite("Crosshair_Circle"); crosshairCircleAim = spriteManager.GetSprite("Crosshair_Circle_Aim"); weaponNameText = GameObject.Find("UI/InGameUI/WeaponStatus/WeaponNameText").GetComponent <Text>(); weaponAmmoText = GameObject.Find("UI/InGameUI/WeaponStatus/AmmoText").GetComponent <Text>(); }
public Player PlayerConstructor(Vector3 pos, Vector2 scale, PlayerState iniState) { if (_prefabManager == null) { var pIns = PrefabManager.GetInstance(); if (pIns == null) { throw new Exception("get null prefab manager"); } _prefabManager = pIns; } var playerPrefab = _prefabManager.GetGameObject("Player"); if (playerPrefab == null) { throw new Exception("get null player prefab"); } var playerObject = Object.Instantiate(playerPrefab); playerObject.transform.position = pos; playerObject.transform.localScale = scale; var player = playerObject.GetComponent <Player>(); player.jumpScale = 8; var controllerPrefab = PrefabManager.GetInstance().GetGameObject("AppController"); Vector3 controllerPosition = _isUpperPlayer ? new Vector3(0, 10.5f) : new Vector3(0, -10.5f); var controllerGameObject = Object.Instantiate(controllerPrefab, controllerPosition, quaternion.identity); var controller = controllerGameObject.GetComponent <IPlayerController>(); if (controller == null) { Debug.Log("player controller is null"); } player.InitPlayer(controller, iniState); _isUpperPlayer = !_isUpperPlayer; return(player); }
/// <summary> /// Create new opening to connect rooms on selected side. /// </summary> /// <param name="side"></param> /// <returns></returns> public Vector3 CreateOpening(int indexopening, string side) { Tile t; //Tile to be placed. if (side == "Top") { t = new Tile("Top_Door", PrefabManager.GetInstance().GetAllRoomTiles().Where(obj => obj.name == "Top_Door").First(), RoomTiles[indexopening].Position); } else if (side == "Right") { t = new Tile("Right_Door", PrefabManager.GetInstance().GetAllRoomTiles().Where(obj => obj.name == "Right_Door").First(), RoomTiles[indexopening].Position); } else if (side == "Bottom") { t = new Tile("Bottom_Door", PrefabManager.GetInstance().GetAllRoomTiles().Where(obj => obj.name == "Bottom_Door").First(), RoomTiles[indexopening].Position); } else { t = new Tile("Left_Door", PrefabManager.GetInstance().GetAllRoomTiles().Where(obj => obj.name == "Left_Door").First(), RoomTiles[indexopening].Position); } //Replace opening. RoomTiles[indexopening] = t; Vector3 oldtileloc = new Vector3(0, 0, 0); if (Instantiated_Tiles != null)//If room is already instatiated. { oldtileloc = Instantiated_Tiles[indexopening].transform.position; //Destroy old opening. Object.Destroy(Instantiated_Tiles[indexopening]); //Instantiate new opening. Instantiated_Tiles[indexopening] = Object.Instantiate(t.Objtile, oldtileloc, new Quaternion(), RoomObject.transform); } Available_Sides.Remove(side); return(oldtileloc); }
public void CreateDungeon(int room_number) { //Construct Spawn Room. InstantiateIRoom(RoomFactory.Build("SpawningRoom", PrefabManager.GetInstance().GetAllRoomTiles(), 5, 5), new Vector3(0, 0, 0), PrefabManager.GetInstance().GetAllRoomTiles()); //TO BE REMOVED! TESTING CODE. allrooms[0].RoomObject.AddComponent <SpawnRoomScript>(); allrooms[0].RoomObject.AddComponent <BoxCollider>(); //Create new collider for the room. allrooms[0].RoomObject.GetComponent <BoxCollider>().size = new Vector3(allrooms[0].Tiles_number_x * Tile.X_length - 2, 5, allrooms[0].Tiles_number_z * Tile.Z_length - 2); //Set the size of the collider to cover all the room. allrooms[0].RoomObject.GetComponent <BoxCollider>().isTrigger = true; //Set collider to trigger. //TO BE REMOVED! bool foundcorridor, foundroom; while (true) { int openroomindex = -1; foundcorridor = false; foundroom = false; //Used to find corridor with available sides. for (int i = 0; i < allrooms.Count; i++) { if (allrooms[i].Available_Sides.Count > 0) { if (allrooms[i].Category == "Corridor") { foundcorridor = true; openroomindex = i; break; } } } //Gives priority to available corridors. //Used to find available room. if (!foundcorridor) { for (int i = 0; i < allrooms.Count; i++) { if (allrooms[i].Available_Sides.Count > 0) { if (allrooms[i].Category == "Room") { foundroom = true; openroomindex = i; break; } } } } //Something went wrong and there is no available side to none of the rooms. if (!foundcorridor && !foundroom) { Debug.LogError("Finished dungeon generator without reaching the room goal."); break; } (IRoom newroom, Vector3 newroomloc) = allrooms[openroomindex].CreateAdjacentRoom(); if (newroom != null) { if (allrooms[openroomindex].Category == "Room") { InstantiateIRoom(newroom, newroomloc, PrefabManager.GetInstance().GetAllRoomTiles()); if (newroom.Category == "Room") { roomsPlaced++; } } else if (allrooms[openroomindex].Category == "Corridor") { InstantiateIRoom(newroom, newroomloc, PrefabManager.GetInstance().GetAllRoomTiles()); if (newroom.Category == "Room") { roomsPlaced++; } } if (roomsPlaced >= RoomNumber) { break; } } } }
private void Start() { PrefabManager.GetInstance().CreateGameObjectByPrefab("RedPanel", transform, Vector3.zero, Quaternion.identity); }
/// <summary> /// Create an adjacent room on selected side. /// </summary> /// <param name="side"></param> /// <param name="opening_location"></param> /// <returns></returns> public (IRoom, Vector3) CreateAdjacentRoom() { //Chose if next room is gonna be corridor or room. string room_corridor = RandomnessMaestro.GetInstance().Choose_Room_Or_Corridor(); List <string> available_rooms = new List <string>(); //Get all the available rooms based on the available sides of the current room. foreach (string availableSide in Available_Sides) { available_rooms.AddRange(ValidationMaestro.GetAppropriateRooms(room_corridor, GetAdjacentSide(availableSide))); } available_rooms = available_rooms.Distinct().ToList();//Remove duplicates. if (room_corridor == "Room") { string roomsize = RandomnessMaestro.GetInstance().Choose_Room_Size(); //Select the room size. (int sizex, int sizez) = DataManager.GetInstance().Search_Sizes_Dictionary(roomsize); //Get the room size data. IRoom new_room = RoomFactory.Build(RandomnessMaestro.GetInstance().Choose_Room_Type(available_rooms), PrefabManager.GetInstance().GetAllRoomTiles(), sizex, sizez); //Construct the new room. string connectionSide = ""; foreach (string avside in Available_Sides) { if (new_room.Available_Sides.Contains(GetAdjacentSide(avside))) { connectionSide = avside; break; } }//Find the connection side between the current room and the new one. string adjside = GetAdjacentSide(connectionSide);//Get the side that the new room needs to have available. int openindex = CalculateOpening(connectionSide); Vector3 opening_location = Instantiated_Tiles[openindex].transform.position; //Location of the tile that the opening is gonna be. int new_opening_index = new_room.CalculateOpening(adjside); //Calculate the opening of the new room. //Place new adjacent room appropriately. Vector3 new_placed_location = LocationManager.GetApropriateLocationForRoom(connectionSide, opening_location, new_opening_index, new_room.Tiles_number_x, new_room.Tiles_number_z); bool end = false; //While location is taken by another object. while (!ValidationMaestro.IsNotClaimed(new_placed_location, new_room.Tiles_number_x, new_room.Tiles_number_z) && !end) { //If the smallest room doesn't fit, stop. if (roomsize == "Small") { end = true; } //Return a smaller size. (roomsize, sizex, sizez) = DataManager.GetInstance().ReturnSmallerSize(roomsize, 1); //Re-Construct the room. new_room = RoomFactory.Build(RandomnessMaestro.GetInstance().Choose_Room_Type(available_rooms), PrefabManager.GetInstance().GetAllRoomTiles(), sizex, sizez); //Re-Calculate opening. new_opening_index = new_room.CalculateOpening(adjside); //Re-Place the room appropriately. new_placed_location = LocationManager.GetApropriateLocationForRoom(connectionSide, opening_location, new_opening_index, new_room.Tiles_number_x, new_room.Tiles_number_z); } if (end)//if smaller doesn't fit. { this.Available_Sides.Remove(connectionSide); return(null, new Vector3(0, 0, 0)); } if (new_room.Type.Equals("EndRoom"))//Check if the floor end room is placed. { new_room.Available_Sides.Clear(); RandomnessMaestro.GetInstance().endRoomPlaced = true; Debug.LogError("Placed end room at: " + DungeonGenerator.GetInstance().roomsPlaced); } //If everything is okay, place the room normally. this.Available_Sides.Remove(connectionSide); new_room.Available_Sides.Remove(adjside); if (this.Category.Equals("Room")) { CreateOpening(openindex, connectionSide); //Create opening if this is a room. } Vector3 newopenloc = new_room.CreateOpening(new_opening_index, adjside); //Create opening to the adjacent room. //Make this room parent of the new one. if (this.Category == "Room") { switch (connectionSide) { case "Left": this.AdjRoomLeft = new_room; break; case "Top": this.AdjRoomTop = new_room; break; case "Right": this.AdjRoomRight = new_room; break; case "Bottom": this.AdjRoomBottom = new_room; break; } } else { ((Basic_Corridor)this).Child = new_room; } switch (adjside) { case "Left": ((Basic_Room)new_room).AdjRoomLeft = this; break; case "Top": ((Basic_Room)new_room).AdjRoomTop = this; break; case "Right": ((Basic_Room)new_room).AdjRoomRight = this; break; case "Bottom": ((Basic_Room)new_room).AdjRoomBottom = this; break; } return(new_room, new_placed_location); } else { //Choose randomly the type of corridor. string corridor_chosen_type = RandomnessMaestro.GetInstance().Choose_Corridor_Type(); //Choose only corridors that match the type List <string> proper_rooms = available_rooms.Where(x => x.Contains(corridor_chosen_type)).ToList(); IRoom new_room = RoomFactory.Build(proper_rooms[Random.Range(0, proper_rooms.Count - 1)], PrefabManager.GetInstance().GetAllCorridorTiles(), 1, 1); string connectionSide = ""; foreach (string avside in Available_Sides) { if (new_room.Available_Sides.Contains(GetAdjacentSide(avside))) { connectionSide = avside; break; } } string adjside = GetAdjacentSide(connectionSide); int openindex = CalculateOpening(connectionSide); Vector3 opening_location = Instantiated_Tiles[openindex].transform.position; //Calculate the opening of the new room. int new_opening_index = new_room.CalculateOpening(adjside); //Place new adjacent room appropriately. Vector3 new_placed_location = LocationManager.GetApropriateLocationForRoom(connectionSide, opening_location, new_opening_index, new_room.Tiles_number_x, new_room.Tiles_number_z); //If location is taken by another object. if (!ValidationMaestro.IsNotClaimed(new_placed_location, new_room.Tiles_number_x, new_room.Tiles_number_z)) { this.Available_Sides.Remove(connectionSide); return(null, new Vector3(0, 0, 0)); } else { if (this.Category.Equals("Room")) { CreateOpening(openindex, connectionSide); } this.Available_Sides.Remove(connectionSide); new_room.Available_Sides.Remove(adjside); if (this.Category == "Room") { switch (connectionSide) { case "Left": this.AdjRoomLeft = new_room; break; case "Top": this.AdjRoomTop = new_room; break; case "Right": this.AdjRoomRight = new_room; break; case "Bottom": this.AdjRoomBottom = new_room; break; } } else { ((Basic_Corridor)this).Child = new_room; } ((Basic_Corridor)new_room).Parent = this; return(new_room, new_placed_location); } } }