private IEnumerator Generate() { while (!this.generated) { if (base.name == "Host") { GameConsole.Console console = UnityEngine.Object.FindObjectOfType <GameConsole.Console>(); console.AddLog("Initializing generator...", new Color32(0, byte.MaxValue, 0, byte.MaxValue), false); ImageGenerator lcz = null; ImageGenerator hcz = null; ImageGenerator enz = null; foreach (ImageGenerator imageGenerator in UnityEngine.Object.FindObjectsOfType <ImageGenerator>()) { if (imageGenerator.height == 0) { lcz = imageGenerator; } if (imageGenerator.height == -1000) { hcz = imageGenerator; } if (imageGenerator.height == -1001) { enz = imageGenerator; } } if (!TutorialManager.status) { lcz.GenerateMap(this.seed); hcz.GenerateMap(this.seed + 1); enz.GenerateMap(this.seed + 2); foreach (Door door in UnityEngine.Object.FindObjectsOfType <Door>()) { door.UpdatePos(); } } foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("DoorButton")) { try { gameObject.GetComponent <ButtonWallAdjuster>().Adjust(); foreach (ButtonWallAdjuster buttonWallAdjuster in gameObject.GetComponentsInChildren <ButtonWallAdjuster>()) { buttonWallAdjuster.Invoke("Adjust", 4f); } } catch { } } foreach (Lift lift in UnityEngine.Object.FindObjectsOfType <Lift>()) { foreach (Lift.Elevator elevator in lift.elevators) { elevator.SetPosition(); } } yield return(new WaitForSeconds(1f)); console.AddLog("Spawning items...", new Color32(0, byte.MaxValue, 0, byte.MaxValue), false); if (base.isLocalPlayer) { foreach (Door door2 in UnityEngine.Object.FindObjectsOfType <Door>()) { if (door2.destroyed) { door2.DestroyDoor(true); } } base.GetComponent <HostItemSpawner>().Spawn(this.seed); base.GetComponent <AntiFakeCommands>().FindAllowedTeleportPositions(); } console.AddLog("The scene is ready! Good luck!", new Color32(0, byte.MaxValue, 0, byte.MaxValue), false); this.generated = true; } yield return(new WaitForEndOfFrame()); } yield break; }
public void GenerateMap(int seed) { GameConsole.Console console = UnityEngine.Object.FindObjectOfType <GameConsole.Console>(); if (!TutorialManager.status) { base.GetComponent <PocketDimensionGenerator>().GenerateMap(seed); for (int i = 0; i < this.positions.Count; i++) { this.positions[i].point.name = "POINT" + i; if (this.positions[i].point.GetComponent <Point>() == null) { Debug.LogError("RoomManager: Missing 'Point' script at current position."); return; } } UnityEngine.Random.InitState(seed); console.AddLog("[MG REPLY]: Successfully recieved map seed!", new Color32(0, byte.MaxValue, 0, byte.MaxValue), true); List <RoomManager.RoomPosition> list = this.positions; console.AddLog("[MG TASK]: Setting rooms positions...", new Color32(0, byte.MaxValue, 0, byte.MaxValue), false); foreach (RoomManager.Room room in this.rooms) { console.AddLog("\t\t[MG INFO]: " + room.label + " is about to set!", new Color32(120, 120, 120, byte.MaxValue), true); List <int> list2 = new List <int>(); for (int j = 0; j < list.Count; j++) { if (this.positions[j].type.Equals(room.type)) { bool flag = true; foreach (Point point in room.roomPrefab.GetComponentsInChildren <Point>()) { if (this.positions[j].point.name == point.gameObject.name) { flag = false; } } if (flag) { list2.Add(j); } } } List <int> list3 = list2; for (int l = 0; l < list3.Count; l++) { foreach (Point point2 in room.roomPrefab.GetComponentsInChildren <Point>()) { if (this.positions[list3[l]].point.name == point2.gameObject.name) { list2.Remove(list3[l]); } } } int index = list2[UnityEngine.Random.Range(0, list2.Count)]; RoomManager.RoomPosition roomPosition = this.positions[index]; GameObject roomPrefab = room.roomPrefab; RawImage icon = room.icon; room.readonlyPoint = roomPosition.point; roomPrefab.transform.SetParent(roomPosition.point); roomPrefab.transform.localPosition = room.roomOffset.position; roomPrefab.transform.localRotation = Quaternion.Euler(room.roomOffset.rotation); roomPrefab.transform.localScale = room.roomOffset.scale; if (icon != null) { icon.rectTransform.SetParent(roomPosition.ui_point); icon.transform.localPosition = room.iconoffset.position; icon.rectTransform.localRotation = Quaternion.Euler(room.iconoffset.rotation); icon.transform.localScale = room.iconoffset.scale; } roomPrefab.SetActive(true); this.positions.RemoveAt(index); } } console.AddLog("--Map successfully generated--", new Color32(0, byte.MaxValue, 0, byte.MaxValue), false); this.isGenerated = true; }