KaiClavier

STMPagination.cs

Jul 14th, 2025 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. //Copyright (c) 2016-2025 Kai Clavier [kaiclavier.com] Do Not Distribute
  2. using UnityEngine;
  3. using System.Collections;
  4.  
  5. [ExecuteInEditMode]
  6. [RequireComponent(typeof(SuperTextMesh))]
  7. public class STMPagination : MonoBehaviour {
  8.     public SuperTextMesh originalText;
  9.     public SuperTextMesh overflowText;
  10.    
  11.     public void Awake(){
  12.  
  13.         if(originalText == null)
  14.         {
  15.             originalText = GetComponent<SuperTextMesh>();
  16.         }
  17.         //clear on runtime
  18.         if(overflowText != null)
  19.             overflowText.text = "";
  20.     }
  21.     public void OverflowLeftovers()
  22.     {
  23.         if(overflowText == null) return;
  24.        
  25.         overflowText.text = originalText.leftoverText.TrimStart();
  26.         //if there's no text, Rebuild() doesn't get called anyway
  27.         //use TrimStart() to remove any spaces that might have carried over.
  28.     }
  29.     //is this implementation better? causes errors when the object isn't defined...
  30.     //sort of a non-issue tho, an error *should* be returned if the next text field isn't defined!
  31.     public void OverflowLeftovers(SuperTextMesh stm)
  32.     {
  33.         if(overflowText == null) return;
  34.         overflowText.text = stm.leftoverText.TrimStart();
  35.     }
  36.  
  37.     public void Reset()
  38.     {
  39.         originalText = GetComponent<SuperTextMesh>();
  40.     }
  41.     //update, just use delegate events to subscribe automatically!
  42.     public void OnEnable()
  43.     {
  44.         originalText.OnCompleteEvent += OverflowLeftovers;
  45.     }
  46.     public void OnDisable()
  47.     {
  48.         originalText.OnCompleteEvent -= OverflowLeftovers;
  49.     }
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment