private void CreatePuzzleUIElement(TextAsset puzzle) { var uiElementRef = (GameObject)GameObject.Instantiate(puzzleUIElement, new Vector3(0, 0), new Quaternion()); uiElementRef.transform.SetParent(puzzleContainer.transform); uiElementRef.transform.localPosition = new Vector3(currentXcoordinate, currentYcoordinate); uiElementRef.transform.localScale = Vector3.one; uiElementRef.transform.Find("Text").gameObject.GetComponent <Text>().text = currentPuzzleCounter.ToString(); var levelSelectScript = uiElementRef.GetComponent <PuzzleMenuLevelSelectScript>(); levelSelectScript.PuzzleCategory = currentCategory; var puzzleName = new TextPuzzleParser().ParsePuzzle(puzzle.ToString()).PuzzleName; levelSelectScript.PuzzleToLoad = puzzleName; puzzleRowCount++; currentPuzzleCounter++; currentXcoordinate += puzzleUIElementWidth + buffer; }
public void PopulatePuzzleMenu() { puzzleUIElement = (GameObject)Resources.Load("UI/PuzzleUIElement"); puzzleUIElementWidth = puzzleUIElement.GetComponent <RectTransform>().sizeDelta.x; puzzleUIElementHeight = puzzleUIElement.GetComponent <RectTransform>().sizeDelta.y; var rectTransform = puzzleContainer.GetComponent <RectTransform>(); // Load the puzzles under the current category currentCategory = PlayerPrefs.GetString("PuzzleCategory"); var puzzlesRaw = Resources.LoadAll("Puzzles/" + currentCategory); // Reset puzzle Coutner to 1 so the gameobjects know what text to value to display currentPuzzleCounter = 1; title.text = currentCategory; puzzleContainerScript.ClearPuzzles(); // Take all the puzzles loaded from resources and convert them into text assets var puzzles = new TextPuzzleParser().ParsePuzzles("Puzzles/" + currentCategory); // Create a UI element for each puzzle under the categories foreach (var puzzle in puzzles) { CreatePuzzleUIElement(puzzle); } // Resize container so that the scrolling behaves properly puzzleContainerScript.ResizeContainer(puzzles.Count); // Make sure scroll rect is scrolled to the top puzzleContainerScript.ScrollToTop(); var category = Constants.PuzzleCategories.First(x => x.CategoryName == currentCategory); completedTitle.text = category.LevelsCompleted + " / " + category.LevelsAvailable; }
public void PuzzleParser_ThrowAwayTest() { TextPuzzleParser puzzleParser = new TextPuzzleParser(); puzzleParser.ParsePuzzles("Puzzles"); }