public void generateLevels() { IEnumerable <PChapter> chapters = dConnector.GetAllChapters(); int i = 1; foreach (PChapter chapter in chapters) { //Generate Chapters GameObject newButton = Instantiate(chapterButton) as GameObject; ChapterButton cButton = newButton.GetComponent <ChapterButton>(); cButton.nameLabel.text = chapter.Name; cButton.lockedLabel.text = chapter.Locked?"Locked":"Unlocked"; newButton.transform.SetParent(contentPanel); ToConsole(chapter); //Generate Levels int j = 1; IEnumerable <PLevel> levels = dConnector.GetAllLevelsInChapterById(chapter.Id); foreach (PLevel level in levels) { GameObject newLevelButton = Instantiate(levelButton) as GameObject; LevelButton lButton = newLevelButton.GetComponent <LevelButton>(); lButton.nameLabel.text = level.Name; lButton.lockedLabel.text = level.Locked?"Locked":"Unlocked"; lButton.levelNumber.text = "#" + j; j++; newLevelButton.transform.SetParent(contentPanel); ToConsole(level); } i++; } }
public void CreateChapterButtons(GameObject container, bool updateButtons) { Debug.Log(TAG + "Clearing the old chapter buttons"); if (chapterButtons != null) { foreach (ChapterButton c in chapterButtons) { Destroy(c.gameObject); } chapterButtons = null; } Debug.Log(TAG + "Creating Chapterr buttons."); string[] folders = Directory.GetDirectories(Application.persistentDataPath + "/CustomChapters/"); Debug.Log(TAG + "___________________there are " + folders.Length + " custom chapters________________"); //TODO clear out old chapter buttons chapterButtons = new ChapterButton[folders.Length]; float x1, y1, x2, y2, buttonWidth, buttonHeight, padT; buttonWidth = 150.0f; buttonHeight = 35.0f; padT = 5.0f; x1 = 0; x2 = x1 + buttonWidth; y1 = -buttonHeight - padT; y2 = y1 + buttonHeight; for (int i = 0; i < folders.Length; i++) { string s = folders[i]; Debug.Log("folder = " + s); GameObject g = Instantiate(chapterButtonPrefab); g.transform.SetParent(container.transform); ChapterButton chapterButton = g.GetComponent <ChapterButton>(); chapterButton.SetUp(s, updateButtons, i, this); RectTransform r = g.GetComponent <RectTransform>(); r.offsetMin = new Vector2(x1, y1); r.offsetMax = new Vector2(x2, y2); y1 -= buttonHeight + padT; y2 = y1 + buttonHeight; chapterButtons[i] = chapterButton; } chapterButtons[0].Press(); //Select a chapter button by default curChapterButton = chapterButtons[0]; }
void Start() { dataController = FindObjectOfType <DataController>(); for (int i = 0; i < dataController.chapters.Length; i++) { GameObject chapterButtonGameObject = chapterButtonObjectPool.GetObject(); chapterButtonGameObjects.Add(chapterButtonGameObject); chapterButtonGameObject.transform.SetParent(chapterButtonParent); chapterButtonGameObject.transform.localScale = Vector3.one; ChapterButton chapterButton = chapterButtonGameObject.GetComponent <ChapterButton>(); chapterButton.Setup(dataController.chapters[i].nameText, dataController, i); // dataController.PlayClickSound(); // chapterButton.GetComponent<Button>().onClick.AddListener(()=>{chapterButton.StartChapter(this.GetComponent<ChapterButton>().cid);}); } }
public void SelectChapter(string s, bool updateButtons, int i, ChapterButton c) { //used for selecting the chapter the user wishes to save to //TODO could just refernce the curChapterButton and get rid of all the other variables Debug.Log(TAG + "Selecting Chapter: " + s); curChapter = s; chapterRefNum = i; if (curChapterButton != null) { curChapterButton.Select(false); } if (deleteMode) { toDeleteFile = false; OpenPopUpDelete(true); Text msgText = popUpDelete.GetComponentInChildren <Text>(); toDelete = curChapter; string[] fileName = toDelete.Split('/'); msgText.text = "Are you sure you want to delete " + fileName[fileName.Length - 1] + "?"; return; } curChapterButton = c; if (updateButtons) { ClearLevelButs(); Level[] levels = levelManager.GetCustomLevels(chapterRefNum); if (levels == null) { Debug.Log(TAG + "no level button to create."); return; } levelButtons = menuManager.CreateLevelButs(levelCon, levels, true); } }
public void BuildChapterButton(string boardName, int buttonID) { Debug.Log("Building chapter button " + buttonID + " for board " + boardName); GameObject newButton = Instantiate(chapterButtonWide); newButton.name = "ChapterButton" + buttonID.ToString(); ChapterButton button = newButton.GetComponentInChildren <ChapterButton>(); RectTransform trans = newButton.GetComponentInChildren <RectTransform>(); // set position, scale trans.SetParent(viewportContent, false); trans.anchoredPosition = new Vector2(chapterButtonLeftPadding, -chapterButtonTopPadding + (buttonID - 1) * -chapterButtonSpace); trans.localScale = Vector3.one; // update the button's chapter value button.SetChapterID("chapter" + buttonID.ToString()); button.SetLocked(boardName == "Epilogue" ? BoardLocked("071nurture") : BoardLocked(boardName)); button.SetDisplayName(boardName == "Epilogue" ? "Epilogue" : "Chapter " + buttonID.ToString()); }