static StackObject *AssignFromStack_m_textInfo_0(ref object o, ILIntepreter __intp, StackObject *ptr_of_this_method, IList <object> __mStack) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; TMPro.TMP_TextInfo @m_textInfo = (TMPro.TMP_TextInfo) typeof(TMPro.TMP_TextInfo).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0); ((TMPro.TMP_Text)o).m_textInfo = @m_textInfo; return(ptr_of_this_method); }
/// <summary> /// Plays the typewriter effect. /// </summary> public IEnumerator Play() { if ((textComponent != null) && (charactersPerSecond > 0)) { if (waitOneFrameBeforeStarting) { yield return(null); } if (audioSource != null) { audioSource.clip = audioClip; } onBegin.Invoke(); IsPlaying = true; paused = false; float delay = 1 / charactersPerSecond; float lastTime = DialogueTime.time; float elapsed = 0; textComponent.maxVisibleCharacters = 0; textComponent.ForceMeshUpdate(); yield return(null); textComponent.maxVisibleCharacters = 0; textComponent.ForceMeshUpdate(); TMPro.TMP_TextInfo textInfo = textComponent.textInfo; int totalVisibleCharacters = textInfo.characterCount; // Get # of Visible Character in text object charactersTyped = 0; while (charactersTyped < totalVisibleCharacters) { if (!paused) { var deltaTime = DialogueTime.time - lastTime; elapsed += deltaTime; var goal = elapsed * charactersPerSecond; while (charactersTyped < goal) { PlayCharacterAudio(); onCharacter.Invoke(); charactersTyped++; } } textComponent.maxVisibleCharacters = charactersTyped; HandleAutoScroll(); //---Uncomment the line below to debug: //Debug.Log(textComponent.text.Substring(0, charactersTyped).Replace("<", "[").Replace(">", "]") + " (typed=" + charactersTyped + ")"); lastTime = DialogueTime.time; var delayTime = DialogueTime.time + delay; int delaySafeguard = 0; while (DialogueTime.time < delayTime && delaySafeguard < 999) { delaySafeguard++; yield return(null); } } } Stop(); }
public IEnumerator LoadPageAsync(string pageText) { textMesh.maxVisibleCharacters = 0; textMesh.text = pageText; textMesh.pageToDisplay = 1; // Wait for TMP to process the page text. yield return(new WaitUntil( () => (textInfo = textMesh.GetTextInfo(pageText)).characterCount > 0)); parsedPageText = textMesh.GetParsedText(); }
static int _m_GetTextInfo(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); TMPro.TextMeshProUGUI gen_to_be_invoked = (TMPro.TextMeshProUGUI)translator.FastGetCSObj(L, 1); { string _text = LuaAPI.lua_tostring(L, 2); TMPro.TMP_TextInfo gen_ret = gen_to_be_invoked.GetTextInfo(_text); translator.Push(L, gen_ret); return(1); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
/// <summary> /// Plays the typewriter effect. /// </summary> public virtual IEnumerator Play(int fromIndex) { if ((textComponent != null) && (charactersPerSecond > 0)) { if (waitOneFrameBeforeStarting) { yield return(null); } fromIndex = StripRPGMakerCodes(Tools.StripTags(textComponent.text.Substring(0, fromIndex))).Length; ProcessRPGMakerCodes(); ProcessTags(); if (runtimeAudioSource != null) { runtimeAudioSource.clip = audioClip; } onBegin.Invoke(); paused = false; float delay = 1 / charactersPerSecond; float lastTime = DialogueTime.time; float elapsed = fromIndex / charactersPerSecond; textComponent.maxVisibleCharacters = fromIndex; textComponent.ForceMeshUpdate(); yield return(null); textComponent.maxVisibleCharacters = fromIndex; textComponent.ForceMeshUpdate(); TMPro.TMP_TextInfo textInfo = textComponent.textInfo; var parsedText = textComponent.GetParsedText(); int totalVisibleCharacters = textInfo.characterCount; // Get # of Visible Character in text object charactersTyped = fromIndex; int skippedCharacters = 0; while (charactersTyped < totalVisibleCharacters) { if (!paused) { var deltaTime = DialogueTime.time - lastTime; elapsed += deltaTime; var goal = (elapsed * charactersPerSecond) + skippedCharacters; while (charactersTyped < goal) { if (rpgMakerTokens.ContainsKey(charactersTyped)) { var tokens = rpgMakerTokens[charactersTyped]; for (int i = 0; i < tokens.Count; i++) { var token = tokens[i]; switch (token) { case RPGMakerTokenType.QuarterPause: yield return(DialogueTime.WaitForSeconds(quarterPauseDuration)); break; case RPGMakerTokenType.FullPause: yield return(DialogueTime.WaitForSeconds(fullPauseDuration)); break; case RPGMakerTokenType.SkipToEnd: charactersTyped = totalVisibleCharacters - 1; break; case RPGMakerTokenType.InstantOpen: var close = false; while (!close && charactersTyped < totalVisibleCharacters) { charactersTyped++; skippedCharacters++; if (rpgMakerTokens.ContainsKey(charactersTyped) && rpgMakerTokens[charactersTyped].Contains(RPGMakerTokenType.InstantClose)) { close = true; } } break; } } } var typedCharacter = (0 <= charactersTyped && charactersTyped < parsedText.Length) ? parsedText[charactersTyped] : ' '; if (charactersTyped < totalVisibleCharacters && !IsSilentCharacter(typedCharacter)) { PlayCharacterAudio(typedCharacter); } onCharacter.Invoke(); charactersTyped++; textComponent.maxVisibleCharacters = charactersTyped; if (IsFullPauseCharacter(typedCharacter)) { yield return(DialogueTime.WaitForSeconds(fullPauseDuration)); } else if (IsQuarterPauseCharacter(typedCharacter)) { yield return(DialogueTime.WaitForSeconds(quarterPauseDuration)); } } } textComponent.maxVisibleCharacters = charactersTyped; HandleAutoScroll(); //---Uncomment the line below to debug: //Debug.Log(textComponent.text.Substring(0, charactersTyped).Replace("<", "[").Replace(">", "]") + " (typed=" + charactersTyped + ")"); lastTime = DialogueTime.time; var delayTime = DialogueTime.time + delay; int delaySafeguard = 0; while (DialogueTime.time < delayTime && delaySafeguard < 999) { delaySafeguard++; yield return(null); } } } Stop(); }
// from textmeshpro examples void WarpText() { VertexCurve.preWrapMode = WrapMode.Clamp; VertexCurve.postWrapMode = WrapMode.Clamp; //Mesh mesh = m_TextComponent.textInfo.meshInfo[0].mesh; Vector3[] vertices; Matrix4x4 matrix; var m_TextComponent = title; m_TextComponent.havePropertiesChanged = true; // Need to force the TextMeshPro Object to be updated. CurveScale *= 10; float old_CurveScale = CurveScale; AnimationCurve old_curve = CopyAnimationCurve(VertexCurve); old_CurveScale = CurveScale; old_curve = CopyAnimationCurve(VertexCurve); m_TextComponent.ForceMeshUpdate(); // Generate the mesh and populate the textInfo with data we can use and manipulate. TMPro.TMP_TextInfo textInfo = m_TextComponent.textInfo; int characterCount = textInfo.characterCount; if (characterCount == 0) { return; } //vertices = textInfo.meshInfo[0].vertices; //int lastVertexIndex = textInfo.characterInfo[characterCount - 1].vertexIndex; float boundsMinX = m_TextComponent.bounds.min.x; //textInfo.meshInfo[0].mesh.bounds.min.x; float boundsMaxX = m_TextComponent.bounds.max.x; //textInfo.meshInfo[0].mesh.bounds.max.x; for (int i = 0; i < characterCount; i++) { if (!textInfo.characterInfo[i].isVisible) { continue; } int vertexIndex = textInfo.characterInfo[i].vertexIndex; // Get the index of the mesh used by this character. int materialIndex = textInfo.characterInfo[i].materialReferenceIndex; vertices = textInfo.meshInfo[materialIndex].vertices; // Compute the baseline mid point for each character Vector3 offsetToMidBaseline = new Vector2((vertices[vertexIndex + 0].x + vertices[vertexIndex + 2].x) / 2, textInfo.characterInfo[i].baseLine); //float offsetY = VertexCurve.Evaluate((float)i / characterCount + loopCount / 50f); // Random.Range(-0.25f, 0.25f); // Apply offset to adjust our pivot point. vertices[vertexIndex + 0] += -offsetToMidBaseline; vertices[vertexIndex + 1] += -offsetToMidBaseline; vertices[vertexIndex + 2] += -offsetToMidBaseline; vertices[vertexIndex + 3] += -offsetToMidBaseline; // Compute the angle of rotation for each character based on the animation curve float x0 = (offsetToMidBaseline.x - boundsMinX) / (boundsMaxX - boundsMinX); // Character's position relative to the bounds of the mesh. float x1 = x0 + 0.0001f; float y0 = VertexCurve.Evaluate(x0) * CurveScale; float y1 = VertexCurve.Evaluate(x1) * CurveScale; Vector3 horizontal = new Vector3(1, 0, 0); //Vector3 normal = new Vector3(-(y1 - y0), (x1 * (boundsMaxX - boundsMinX) + boundsMinX) - offsetToMidBaseline.x, 0); Vector3 tangent = new Vector3(x1 * (boundsMaxX - boundsMinX) + boundsMinX, y1) - new Vector3(offsetToMidBaseline.x, y0); float dot = Mathf.Acos(Vector3.Dot(horizontal, tangent.normalized)) * 57.2957795f; Vector3 cross = Vector3.Cross(horizontal, tangent); float angle = cross.z > 0 ? dot : 360 - dot; matrix = Matrix4x4.TRS(new Vector3(0, y0, 0), Quaternion.Euler(0, 0, angle), Vector3.one); vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]); vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]); vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]); vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]); vertices[vertexIndex + 0] += offsetToMidBaseline; vertices[vertexIndex + 1] += offsetToMidBaseline; vertices[vertexIndex + 2] += offsetToMidBaseline; vertices[vertexIndex + 3] += offsetToMidBaseline; } // Upload the mesh with the revised information m_TextComponent.UpdateVertexData(); }
// TODO: remove from here public virtual bool FixTMProDiacriticPositions(TMPro.TMP_TextInfo textInfo) { return(true); }