Advertisement
KaiClavier

STMPagination.cs

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