You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

48 lines
1.4KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Tints the target by the given color value. If you're going to change alpha, target shaders should support transparency.
  8. /// </summary>
  9. class ActionTintBy : ActionInterval
  10. {
  11. protected Vector4 color;
  12. protected const float coeff = 1F / 255F;
  13. public ActionTintBy(Vector4 targetColor, float targetDuration)
  14. : base(targetDuration)
  15. {
  16. color = targetColor * coeff;
  17. }
  18. public ActionTintBy(Vector3 targetColor, float targetDuration)
  19. : this(new Vector4(targetColor.x, targetColor.y, targetColor.z), targetDuration)
  20. {
  21. }
  22. public override ActionInstant Clone()
  23. {
  24. return new ActionTintBy(color / coeff, duration);
  25. }
  26. public override ActionInstant Reverse()
  27. {
  28. return new ActionTintBy(-color / coeff, duration);
  29. }
  30. public override void Step(float dt)
  31. {
  32. float d = dt / duration;
  33. Vector4 target = color * d;
  34. Color targetColor = renderer.material.color;
  35. targetColor[0] += target[0];
  36. targetColor[1] += target[1];
  37. targetColor[2] += target[2];
  38. targetColor[3] += target[3];
  39. renderer.material.color = targetColor;
  40. }
  41. }
  42. }