public void InstantiateChunk(PlayChunk c, Option chosenOption = null) { chunk.gameObject.SetActive(false); var chunkObj = Instantiate(chunk.gameObject) as GameObject; chunkObj.SetActive(true); chunkObj.transform.SetParent(chunk.transform.parent); var chunkComponent = chunkObj.GetComponent <Chunk> (); chunkComponent.Set(c, chosenOption, this); chunks.Add(chunkComponent); Canvas.ForceUpdateCanvases(); StartCoroutine(AnimateScroll(scroll.verticalNormalizedPosition, 0, 0.5f)); }
/// <summary> /// Takes a single stitch to display, and returns the stitch // /referenced by the player selected option if one is available. /// </summary> static Stitch DisplayChunk(PlayChunk chunk) { foreach (var paragraph in chunk.Paragraphs) { if (!string.IsNullOrEmpty(paragraph.Image)) { WriteImage(paragraph.Image); Console.WriteLine(); } WriteWrappedText(paragraph.Text); Console.WriteLine(); } // Find all available options var visibleOptions = chunk.Options.Where(o => o.IsVisible).Select(o => o.Content).ToList(); // Bail out if no options were visible and we have nowhere to go if (visibleOptions.Count == 0) { return(null); } // Display options for (int i = 0; i < visibleOptions.Count; i++) { Console.WriteLine(string.Format("{0}. {1}", (i + 1), visibleOptions[i].Text)); } // Wait for input, return selected option's linked stitch int choice = -1; while (choice < 1 || choice > visibleOptions.Count) { var key = Console.ReadKey(true); int.TryParse(key.KeyChar.ToString(), out choice); } return(visibleOptions [choice - 1].LinkStitch); }
public void Set(PlayChunk chunk, Option chosenOption, InklewriterPlayer player) { text.gameObject.SetActive(false); foreach (var p in chunk.Paragraphs) { var obj = Instantiate(text.gameObject) as GameObject; obj.SetActive(true); obj.transform.SetParent(text.transform.parent); obj.GetComponent <TextBlock> ().Set(p); } option.gameObject.SetActive(false); foreach (var o in chunk.Options) { if (!o.IsVisible) { continue; } var obj = Instantiate(option.gameObject) as GameObject; obj.SetActive(true); obj.transform.SetParent(option.transform.parent); var optionButton = obj.GetComponent <OptionButton> (); optionButton.Set(o.Content, player); options.Add(optionButton); } option.transform.parent.SetAsLastSibling(); if (chosenOption != null) { chosenOptionText.gameObject.SetActive(true); chosenOptionText.text = chosenOption.Text; } else { chosenOptionText.gameObject.SetActive(false); } }