// Start is called before the first frame update public List <ObstructedLocation> LoadElevators(float wealthLevel) { elevatorManager.Reset(); var obstructedLocation = new List <ObstructedLocation>(); var tempGeoForm = ChooseElevatorForm(wealthLevel); var tempOpenness = ChooseElevatorOpenness(wealthLevel); var tempBorderId = ChooseBorder(tempGeoForm, tempOpenness, wealthLevel); var profile = new ElevatorProfile() { Location = GetLocationElevator(wealthLevel), NbElevator = GetNbElevator(wealthLevel), Elevator = GetElevator(tempGeoForm, tempOpenness), Border = GetBorder(tempGeoForm, tempBorderId), Bottom = GetBottom(tempGeoForm), Gate = GetGate(tempGeoForm, tempOpenness) }; obstructedLocation.Add(profile.Location); LoadCeilingAndLevel(profile); LoadElevatorProfile(profile); return(obstructedLocation); }
private void LoadCeilingAndLevel(ElevatorProfile profile) { switch (profile.Location) { case ObstructedLocation.Middle: GameObject ceil = Instantiate(MiddleCeiling[(profile.NbElevator == 1)? 0 : 1], ProceduralManager.ParentMap); ceil.transform.position = Vector3.zero; GameObject level = Instantiate(Levels[0], ProceduralManager.ParentMap); level.transform.position = Vector3.zero; break; case ObstructedLocation.Long: GameObject ceil2 = Instantiate(ShortCeiling[(profile.NbElevator == 1)? 0 : 1], ProceduralManager.ParentMap); ceil2.transform.position = Vector3.zero; GameObject level2 = Instantiate(Levels[1], ProceduralManager.ParentMap); level2.transform.position = Vector3.zero; break; case ObstructedLocation.Short: GameObject ceil3 = Instantiate(LongCeiling[(profile.NbElevator == 1)? 0 : 1], ProceduralManager.ParentMap); ceil3.transform.position = Vector3.zero; GameObject level3 = Instantiate(Levels[2], ProceduralManager.ParentMap); level3.transform.position = Vector3.zero; break; } }
private void LoadElevator(ElevatorProfile profile, Vector3 position) { GameObject parentElevator = new GameObject(); parentElevator.transform.parent = ProceduralManager.ParentMap; parentElevator.transform.position = position; parentElevator.name = "ElevatorParent" + parentElevator.GetInstanceID(); GameObject elevator = Instantiate(profile.Elevator, parentElevator.transform); int rotation = GetRotationElevator(position, profile.Location); elevator.transform.position = position; elevator.transform.Rotate(0, rotation, 0); GameObject border = Instantiate(profile.Border, parentElevator.transform); border.transform.position = position; border.transform.Rotate(0, rotation, 0); GameObject bottom = Instantiate(profile.Bottom, parentElevator.transform); bottom.transform.position = position; bottom.transform.Rotate(0, rotation, 0); ElevatorEntity elevatorEntity = new ElevatorEntity(); elevatorEntity.ParentElevatorName = parentElevator.name; elevatorEntity.Elevator = elevator; elevatorEntity.ElevatorAnim = elevator.GetComponent <Animator>(); Animator borderAnimator = null; try { borderAnimator = border.GetComponent <Animator>(); } catch (Exception e) { // Nothing to handle } elevatorEntity.BorderAnim = borderAnimator; elevatorEntity.GateAnim = null; if (profile.Gate != null) { GameObject gate = Instantiate(profile.Gate, parentElevator.transform); gate.transform.position = position; gate.transform.Rotate(0, rotation, 0); elevatorEntity.GateAnim = gate.GetComponent <Animator>(); } elevatorManager.Add(elevatorEntity); }
private void LoadElevatorProfile(ElevatorProfile profile) { float delta = 1.9f; switch (profile.Location) { case ObstructedLocation.Middle: if (profile.NbElevator == 1) { LoadElevator(profile, Vector3.zero); } else { for (int i = 0; i < 4; i++) { float xdirection = (i % 2 == 0) ? 1f : -1f; float zdirection = (i < 2) ? 1f : -1f; Vector3 position = new Vector3(xdirection * delta, 0, zdirection * delta); LoadElevator(profile, position); } } break; case ObstructedLocation.Long: var zCoord = 68.7f; if (profile.NbElevator == 1) { for (int i = 0; i < 2; i++) { float zdirection = (i % 2 == 0) ? 1f : -1f; Vector3 position = new Vector3(0, 0, zdirection * zCoord); LoadElevator(profile, position); } } else { for (int i = 0; i < 4; i++) { float xdirection = (i % 2 == 0) ? 1f : -1f; float zdirection = (i < 2) ? 1f : -1f; Vector3 position = new Vector3(xdirection * delta, 0, zdirection * zCoord); LoadElevator(profile, position); } } break; case ObstructedLocation.Short: var xCoord = 98.7f; if (profile.NbElevator == 1) { for (int i = 0; i < 2; i++) { float xdirection = (i % 2 == 0) ? 1f : -1f; Vector3 position = new Vector3(xdirection * xCoord, 0, 0); LoadElevator(profile, position); } } else { for (int i = 0; i < 4; i++) { float xdirection = (i % 2 == 0) ? 1f : -1f; float zdirection = (i < 2) ? 1f : -1f; Vector3 position = new Vector3(xdirection * xCoord, 0, zdirection * delta); LoadElevator(profile, position); } } break; } }