void CreateSlot() { myScript = level.GetComponent <LevelButtonScript>(); myScript.myLevel = levelCount; //creating the level image slot if (levelCount <= starsNeeded.Length) //here we are detecting whether or not the array length is larger than the variable, levelCount, so we can determine whether or not this is a custom map. { level.name = "Level " + levelCount.ToString(); //turning level's name and the level number to a string myScript.starsNeeded = starsNeeded[levelCount - 1]; } else { level.name = "Custom " + ((levelCount + 1) - maxLevels).ToString(); //Turning all levels that are instantiated after maxLevels into a custom string (i.e Custom 1) level.transform.Find("Locked").gameObject.SetActive(false); } level.GetComponentInChildren <Text>().text = level.name; //finding the child text of that level and printing the level name and level number level.transform.SetParent(content.transform); //assigning the instantiate level to child of the GameObject, "content" //getting the button component and assigning the game object, instantiated level, and the load level function to the //on click functions level.GetComponent <RectTransform>().localPosition = new Vector3(xPos, 0, 0); //here we are assigning the proper scale, rotation, position, width, and height of the gameobject "level" level.GetComponent <RectTransform>().localRotation = Quaternion.identity; level.GetComponent <RectTransform>().localScale = new Vector3(1, 1, 1); xPos += (int)level.GetComponent <RectTransform>().rect.height; }
void FillList() { foreach (var level in LevelList) { GameObject newbutton = Instantiate(LevelButton) as GameObject; LevelButtonScript button = newbutton.GetComponent <LevelButtonScript>(); button.LevelText.text = level.LevelText; //replace buttons text component with the text entered through LevelManagerScript if (PlayerPrefs.GetInt("Level" + button.LevelText.text) == 1) { level.Unlocked = 1; level.IsInteractable = true; } button.unlocked = level.Unlocked; button.GetComponent <Button>().interactable = level.IsInteractable; button.GetComponent <Button>().onClick.AddListener(() => LoadLevels("Level" + button.LevelText.text)); if (PlayerPrefs.GetInt("Level" + button.LevelText.text + "_score") > 0) { button.Star1.SetActive(true); } if (PlayerPrefs.GetInt("Level" + button.LevelText.text + "_score") >= 50) { button.Star2.SetActive(true); } if (PlayerPrefs.GetInt("Level" + button.LevelText.text + "_score") >= 99) { button.Star3.SetActive(true); } newbutton.transform.SetParent(Spacer, false); } SaveAll(); }
void FillList() { foreach (var level in levelList) { GameObject newButton = Instantiate(levelButton) as GameObject; LevelButtonScript button = newButton.GetComponent <LevelButtonScript>(); button.LevelText.text = level.LevelText; button.ScoreText.text = level.ScoreText; //Level1, Level2, if (PlayerPrefs.GetInt("Level" + button.LevelText.text) == 1) { level.Unlocked = 1; level.IsInteractable = true; } button.unlocked = level.Unlocked; button.GetComponent <Button>().interactable = level.IsInteractable; button.GetComponent <Button>().onClick.AddListener(() => loadLevels("level" + button.LevelText.text)); if (PlayerPrefs.GetInt("Level" + button.LevelText.text + "_score") > 0) { button.ScoreText.text = PlayerPrefs.GetInt("Level" + button.LevelText.text + "_score").ToString(); } newButton.transform.SetParent(Spacer, false); } }
public void CreateNewButton(string lvlName, int n) { LevelButtonScript newButton = Instantiate(buttonPrefab, this.transform); newButton.FilePath = lvlName; buttonGroup.Add(newButton); newButton.transform.localPosition = new Vector3(0, (n * -newButton.GetComponent <RectTransform>().rect.height) - 30f, 0);//(buttonGroup.Count - 1) - 20f,0); }
void SaveAll() { GameObject[] allButtons = GameObject.FindGameObjectsWithTag("LevelButton"); foreach (GameObject buttons in allButtons) { LevelButtonScript button = buttons.GetComponent <LevelButtonScript>(); PlayerPrefs.SetInt("Level" + button.LevelText.text, button.unlocked); } }
void FillGrid() { //PlayerPrefs.DeleteAll (); GameObject panel = GameObject.Find("Buttons-Panel"); for (int i = 0; i < GameManager.instance.maxLevels; i++) { Button button = Instantiate(buttonPrefab); button.transform.SetParent(panel.transform, false); LevelButtonScript buttonScript = button.GetComponent <LevelButtonScript>(); GameObject buttonUnlocked = button.transform.Find("LevelUnlocked").gameObject; GameObject lockImage = button.transform.Find("LockImage").gameObject; buttonUnlocked.SetActive(false); int t = i + 1; string levelStr = "LP" + GameManager.currentPack + "_" + "level-" + t; string levelStars = levelStr + "stars"; int stars = 0; int levelUnlocked = 0; if (!PlayerPrefs.HasKey(levelStr)) { if (i == 0) { levelUnlocked = 1; } PlayerPrefs.SetInt(levelStr, levelUnlocked); PlayerPrefs.SetInt(levelStars, stars); } else { levelUnlocked = PlayerPrefs.GetInt(levelStr); if (levelUnlocked == 1) { stars = PlayerPrefs.GetInt(levelStars); } } button.GetComponentInChildren <Text>().text = t.ToString(); if (GameConfig.instance.unlockAllLevelForTesting) { levelUnlocked = 1; } if (levelUnlocked == 1) { lockImage.SetActive(false); button.GetComponent <Image>().sprite = buttonScript.levelUnlocked; buttonUnlocked.SetActive(true); buttonScript.SetStars(stars); button.onClick.AddListener(() => LoadLevel(t)); } } }
void SaveAll() //remember the status of all buttons stored in LevelManagerScript; only do it once { // if (PlayerPrefs.HasKey ("Level1")) // { // return; //if level 1 fails; there is no progress to save // } // else { GameObject[] allButtons = GameObject.FindGameObjectsWithTag("LevelButton"); foreach (GameObject buttons in allButtons) { LevelButtonScript button = buttons.GetComponent <LevelButtonScript>(); //get access to all publics of the LevelButtonScript PlayerPrefs.SetInt("Level" + button.LevelText.text, button.unlocked); } } }
void FillList() { List <Level> ResortedList = new List <Level>(); foreach (var level in ListOfLevels) { if (GameManager.gameManager.GetCurrentLevelIndex() >= Int32.Parse(level.LevelText)) { ResortedList.Insert(0, level); } else { ResortedList.Add(level); } } foreach (var level in ResortedList) { GameObject newButton = Instantiate(LevelButton) as GameObject; LevelButtonScript button = newButton.GetComponent <LevelButtonScript>(); // All button numbers greater than CurrentLevelIndex remain uninteractable if (GameManager.gameManager.GetCurrentLevelIndex() >= Int32.Parse(level.LevelText)) { level.IsInteractable = true; button.GetComponent <Button>().interactable = level.IsInteractable; button.GetComponent <Button>().onClick.AddListener(() => SceneManager.LoadScene(level.LevelText)); button.leveltext.text = level.LevelText; button.scoretext.text = GameManager.gameManager.GetPointsEarned(level.LevelText).ToString() + "/" + GameManager.gameManager.GetMaxPoints(level.LevelText).ToString(); } else { button.lockimage.SetActive(true); } // Insert created Button into ButtonPanel newButton.GetComponent <Image>().color = Color; newButton.transform.SetParent(ButtonPanel, false); } }
// Start is called before the first frame update void Start() { for (int i = 0; i < numOfLevelsPerPage; i++) { // only spawn level buttons for days that have data if (levelData.dataArray[i].Daynum > 0) { LevelButtonScript levelButtonScript = Instantiate(levelButton, transform).GetComponent <LevelButtonScript>(); levelButtonScript.SetLevelNum(i); levelButtonScript.SetLevelName($"Day {levelData.dataArray[i].Daynum}"); levelButtonScript.SetStarCount(LoadData.FromBinaryFile <int>("npnp", $"day_{levelData.dataArray[i].Daynum}_stars")); ButtonTransistioner buttonTransistioner = levelButtonScript.GetComponent <ButtonTransistioner>(); buttonTransistioner.panelHandler = FindObjectOfType <MainMenuHandle>().gameObject; // set all levels that are beyond the furthest level to locked state if (i > LoadData.FromBinaryFile <int>("npnp", "FurthestLevel")) { buttonTransistioner.SetInteractable(false); } } } }
public void OnPointerClick(PointerEventData eventData) { if (!interactable) { return; } if (gameObject.name == "Start") //main menu { mainMenuHandle.logo.SetActive(true); mainMenuHandle.howToPlay.SetActive(false); mainMenuHandle.credits.SetActive(false); mainMenuHandle.levelSelectPanel.SetActive(true); mainMenuHandle.mainMenuPanel.SetActive(false); } if (gameObject.name == "HowToPlay") //main menu { mainMenuHandle.howToPlay.SetActive(true); mainMenuHandle.credits.SetActive(false); mainMenuHandle.logo.SetActive(false); } if (gameObject.name == "Credits") //main menu { mainMenuHandle.howToPlay.SetActive(false); mainMenuHandle.credits.SetActive(true); mainMenuHandle.logo.SetActive(false); } if (gameObject.name == "Quit") //main menu { mainMenuHandle.howToPlay.SetActive(false); mainMenuHandle.credits.SetActive(false); mainMenuHandle.logo.SetActive(false); Application.Quit(); } if (gameObject.name == "Restart") //ingame { Time.timeScale = 1; SceneManager.LoadScene("Game"); } if (gameObject.name == "BackToMain") //ingame { Time.timeScale = 1; SceneManager.LoadScene("MainMenu"); } if (gameObject.name == "Resume") //ingame { Time.timeScale = 1; FindObjectOfType <PauseMenu>().PauseFunction(); } if (gameObject.name == "RestartPause") //ingame { Time.timeScale = 1; FindObjectOfType <PauseMenu>().PauseFunction(); SceneManager.LoadScene("Game"); } if (gameObject.name == "BackToMainPause") //ingame { Time.timeScale = 1; FindObjectOfType <PauseMenu>().pausePanel.SetActive(false); SceneManager.LoadScene("MainMenu"); } if (gameObject.CompareTag("level")) { LevelButtonScript selectedLevel = gameObject.GetComponent <LevelButtonScript>(); selectedLevel.ChangeSelectedLevel(); LevelSelect.selectedLevel = selectedLevel.GetLevelNum(); mainMenuHandle.startLevelButton.SetActive(true); } if (gameObject.name == "Back") //back from level select to main menu { mainMenuHandle.levelSelectPanel.SetActive(false); mainMenuHandle.mainMenuPanel.SetActive(true); } if (gameObject.name == "StartLevel") { SceneManager.LoadScene("Game"); } img.color = hover; }
public void levelButtonPressed( LevelButtonScript button ) { //Figure out which button was pressed int i = 0; while (button != levelButtons[i]) if (++i == levelButtons.Length) return; manager.selectLevel (groupIndex, i); }