KaiClavier

STMColorAnimationReceiver.cs

Aug 1st, 2020 (edited)
1,676
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2.  
  3. [ExecuteInEditMode]
  4. [RequireComponent(typeof(SuperTextMesh))]
  5.  
  6. /*
  7. at the moment I don't have a boolean to force STM to update so...
  8. create a new jitter that does nothing (set strength to 0)
  9. and include it at the start of strings to make STM force-update every frame.
  10.  
  11. this script isn't needed anymore for STM v1.11+! The default color value is animateable and there's a boolean to force text to update every frame.
  12.  
  13. */
  14. public class STMColorAnimationReceiver : MonoBehaviour
  15. {
  16.  
  17.     [SerializeField] private Color _color = Color.white;
  18.     public Color color
  19.     {
  20.         get
  21.         {
  22.             return _color;
  23.         }
  24.         set
  25.         {
  26.             SetColor(value);
  27.         }
  28.     }
  29.     public void SetColor(Color col)
  30.     {
  31.         _color = col;
  32.         superTextMesh.color = _color;
  33.         //superTextMesh.SetMesh(0f);// this isn't public... (hey, make this public!)
  34.         //superTextMesh.Rebuild(); //this is too heavy...
  35.         //mesh could also just have a wave that does nothing to force a SetMesh() call
  36.        
  37.         //maybe I'll add a "force animation" boolean? whatever
  38.         //any of these options work but for now... use the note at the top of this script!
  39.     }
  40.     public SuperTextMesh superTextMesh;
  41.  
  42.     public void OnValidate()
  43.     {
  44.         validate = true;
  45.     }
  46.     private bool validate = false;
  47.     public void Update()
  48.     {
  49.         if(validate)
  50.         {
  51.             SetColor(_color);
  52.         }
  53.        
  54.     }
  55.     public void Reset()
  56.     {
  57.         superTextMesh = GetComponent<SuperTextMesh>();
  58.     }
  59. }
RAW Paste Data