public void GenerateLevel(Transform StaticParent, level_specification LevelSpecification) { float centerX = LevelSpecification.sizeX / 2f; float centerZ = LevelSpecification.sizeZ / 2f; //fill in the prefab arrays for the level spec info //this allows us to set the prefab arrays IN ONE PLACE, ONCE, and create new level specs quickly int pfIndex = 0; LevelSpecification.Prefab_Spaces = new GameObject[levelSpecSpacePrefabs.Length]; foreach (GameObject spacePF in levelSpecSpacePrefabs) { LevelSpecification.Prefab_Spaces[pfIndex] = levelSpecSpacePrefabs[pfIndex]; pfIndex += 1; } pfIndex = 0; LevelSpecification.Prefab_Pickups = new GameObject[levelSpecPickupPrefabs.Length]; foreach (GameObject spacePF in levelSpecPickupPrefabs) { LevelSpecification.Prefab_Pickups[pfIndex] = levelSpecPickupPrefabs[pfIndex]; pfIndex += 1; } int pStartX = 0, pStartY = 0; PlayerController pcon = GameObject.FindObjectOfType <GameLoopManager>().m_playerController; pcon.levelObject = StaticParent; pcon.levelSize = LevelSpecification.sizeX; GameObject.FindObjectOfType <LevelViewController>().levelTransform = StaticParent; CardControl cardControl = GameObject.FindObjectOfType <CardControl>(); cardControl.levelObject = StaticParent; cardControl.player = pcon; cardControl.levelSize = LevelSpecification.sizeX; //populate available ability buttons for the level foreach (Button b in cardControl.m_button) { b.gameObject.SetActive(false); } cardControl.m_button = new Button[LevelSpecification.available_abilities.Length]; string buttonName = ""; for (int i = 0; i < cardControl.m_button.Length; i++) { buttonName = LevelSpecification.available_abilities[i]; GameObject butt = allAbilityButtons.Find(x => x.name == buttonName); Debug.Log(butt); cardControl.m_button[i] = butt.GetComponent <Button>(); cardControl.m_button[i].gameObject.SetActive(true); } cardControl.SyncButtons(); pcon.grapeHealAmount = LevelSpecification.grapeHealAmount; pcon.wineHealAmount = LevelSpecification.wineHealAmount; pcon.backtrackDamage = LevelSpecification.backtrackDamage; pcon.hazardDamage = LevelSpecification.hazardDamage; pcon.walkDamage = LevelSpecification.walkDamage; pcon.playerStartWine = LevelSpecification.playerStartWine; pcon.playerMaxWine = LevelSpecification.playerMaxWine; pcon.wine = pcon.playerStartWine; CardControl abilityController = GameObject.FindObjectOfType <CardControl>(); abilityController.dashLoss = LevelSpecification.dashDamage; abilityController.diagLoss = LevelSpecification.diagDamage; GameObject layoutObj = LevelSpecification.LevelLayoutPrefab; GameObject[,] spacesArray = CreateSpacesArray(layoutObj.transform.Find("LevelSpaces"), LevelSpecification.sizeX, LevelSpecification.sizeZ); GameObject[,] pickupsArray = CreatePickupsArray(layoutObj.transform.Find("LevelPickups"), LevelSpecification.sizeX, LevelSpecification.sizeZ); for (int i = 0; i < LevelSpecification.sizeX; i++) { for (int j = 0; j < LevelSpecification.sizeZ; j++) { //Instantiate Spaces //int to enum type conversion? //SpaceType typeOfSpace = LevelSpecification.data[i, j]; RowData rowData = LevelSpecification.data.rows[i]; int spacetype = (int)(rowData.row[j]); //GameObject spaceprefab = LevelSpecification.Prefab_Spaces[spacetype]; GameObject space = null; if (spacesArray[i, j] != null) { GameObject spaceprefab = spacesArray[i, j]; //if(spacetype == 3) if (spaceprefab.name.Contains("ares")) { pcon.posX = i; pcon.posY = j; pStartX = i; pStartY = j; } space = (GameObject)Instantiate(spaceprefab, StaticParent); space.transform.localPosition = new Vector3((1f * i) - centerX, space.transform.localPosition.y, (1f * j) - centerZ); //if its a moveable space, give it xy coords if (space.GetComponent <MoveSpace>() != null) { space.GetComponent <MoveSpace>().posX = i; space.GetComponent <MoveSpace>().posY = j; space.GetComponent <MoveSpace>().moveSpaceType = (SpaceType)spacetype; } } //Instantiate Pickups RowData pickupsData = LevelSpecification.pickups.rows[i]; int pickuptype = pickupsData.row[j]; //0 type is "no pickup" if (pickupsArray[i, j] != null) { //GameObject pickupPrefab = LevelSpecification.Prefab_Pickups[pickuptype-1]; GameObject pickupPrefab = pickupsArray[i, j]; GameObject pickup = (GameObject)Instantiate(pickupPrefab, space.transform); pickup.transform.localPosition = new Vector3(0f, 1.1f, 0f); if (!pickup.name.Contains("dionysus")) { pickup.transform.localScale = new Vector3(.5f, .5f / pickup.transform.parent.localScale.y, .5f); } else { pickup.transform.localScale = new Vector3(20f, 20f / pickup.transform.parent.localScale.y, 20f); } space.GetComponent <MoveSpace>().hasPickup = true; } if (pickuptype == 5) { pStartX = space.GetComponent <MoveSpace>().posX; pStartY = space.GetComponent <MoveSpace>().posY; } } } //pcon.levelObject = GameObject.Find("LevelObject").transform; pcon.MoveToSpace(pStartX, pStartY); pcon.ResetExitStatus(); pcon.spacesArray = spacesArray; pcon.pickupsArray = pickupsArray; }