ShaderPropAnimator.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace TMPro.Examples
  4. {
  5. public class ShaderPropAnimator : MonoBehaviour
  6. {
  7. private Renderer m_Renderer;
  8. private Material m_Material;
  9. public AnimationCurve GlowCurve;
  10. public float m_frame;
  11. void Awake()
  12. {
  13. // Cache a reference to object's renderer
  14. m_Renderer = GetComponent<Renderer>();
  15. // Cache a reference to object's material and create an instance by doing so.
  16. m_Material = m_Renderer.material;
  17. }
  18. void Start()
  19. {
  20. StartCoroutine(AnimateProperties());
  21. }
  22. IEnumerator AnimateProperties()
  23. {
  24. //float lightAngle;
  25. float glowPower;
  26. m_frame = Random.Range(0f, 1f);
  27. while (true)
  28. {
  29. //lightAngle = (m_Material.GetFloat(ShaderPropertyIDs.ID_LightAngle) + Time.deltaTime) % 6.2831853f;
  30. //m_Material.SetFloat(ShaderPropertyIDs.ID_LightAngle, lightAngle);
  31. glowPower = GlowCurve.Evaluate(m_frame);
  32. m_Material.SetFloat(ShaderUtilities.ID_GlowPower, glowPower);
  33. m_frame += Time.deltaTime * Random.Range(0.2f, 0.3f);
  34. yield return new WaitForEndOfFrame();
  35. }
  36. }
  37. }
  38. }