private void Start() { // if the help text is not proper, fix in editor pls, there are buttons for that hpv = GetComponent <HelpPageViewer>(); _mainCamera = Camera.main; StartCoroutine(FetchTMPInfoAfterDelay()); soundUnderline = GameObject.FindGameObjectWithTag("SFX").GetComponent <SFX>(); }
public void CreateHelpTextPages() { HelpPageViewer hpv = GetComponent <HelpPageViewer>(); #if UNITY_EDITOR Undo.RecordObject(hpv, "Changed Help Pages"); #endif hpv.EmptyFolder(); linkPageByID = new List <int>(); // create temp text int counter = 0; string newText = ""; Queue <string> textParts = new Queue <string>(); foreach (var obje in objectListByID) { string addedText = "<link=" + counter + ">" + obje.helpText + "</link> " + "\n \n "; newText += addedText; counter++; textParts.Enqueue(addedText); } _helpTextUI.text = newText; _helpTextUI.ForceMeshUpdate(); int pageCount = 0; // split onto pages while (_helpTextUI.text != "") { TMP_LinkInfo[] links = _helpTextUI.textInfo.linkInfo; List <TMP_LinkInfo> linkL = links.ToList(); linkL.RemoveRange(counter, links.Length - counter); links = linkL.ToArray(); TMP_PageInfo[] pages = _helpTextUI.textInfo.pageInfo; for (var index = 0; index < links.Length; index++) { var link = links[index]; if (link.linkIdLength > 0) { if (link.linkTextfirstCharacterIndex < pages[0].lastCharacterIndex && link.linkTextfirstCharacterIndex + link.linkTextLength > pages[0].lastCharacterIndex) { // text is stretched over two pages, create a new text for all before this and shorten/update layout GameObject newPage = Instantiate(helpPagePrefab, Vector3.zero, Quaternion.identity); string pageText = ""; string compareText = "<link=" + link.GetLinkID() + ">" + link.GetLinkText() + "</link> " + "\n \n "; while (textParts.Peek() != compareText) { pageText += textParts.Dequeue(); linkPageByID.Add(pageCount); counter--; } newPage.GetComponentInChildren <TextMeshProUGUI>().text = pageText; hpv.FilePage(newPage); _helpTextUI.text = _helpTextUI.text.Replace(pageText, ""); _helpTextUI.ForceMeshUpdate(); pageCount++; #if UNITY_EDITOR PrefabUtility.RecordPrefabInstancePropertyModifications(newPage); #endif break; } if ((int.Parse(link.GetLinkID()) == objectListByID.Count - 1) || (links[index + 1].linkTextfirstCharacterIndex > pages[0].lastCharacterIndex) ) // page just ends peacefully { // create a new text for all including this and shorten/update layout GameObject newPage = Instantiate(helpPagePrefab, Vector3.zero, Quaternion.identity); string pageText = ""; string compareText = "<link=" + link.GetLinkID() + ">" + link.GetLinkText() + "</link> " + "\n \n "; while (textParts.Peek() != compareText) { pageText += textParts.Dequeue(); linkPageByID.Add(pageCount); counter--; } pageText += textParts.Dequeue(); counter--; newPage.GetComponentInChildren <TextMeshProUGUI>().text = pageText; hpv.FilePage(newPage); _helpTextUI.text = _helpTextUI.text.Replace(pageText, ""); _helpTextUI.ForceMeshUpdate(); pageCount++; #if UNITY_EDITOR PrefabUtility.RecordPrefabInstancePropertyModifications(newPage); #endif break; } } } } hpv.SortFrontToBack(); #if UNITY_EDITOR PrefabUtility.RecordPrefabInstancePropertyModifications(hpv); #endif }