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.

49 lines
1.3KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. /// <summary>
  7. /// Fades the target to the given alpha value. The tartet shaders should support transparency in order to use this action.
  8. /// </summary>
  9. class ActionFadeTo : ActionInterval
  10. {
  11. protected float value;
  12. protected float delta;
  13. public ActionFadeTo(float tgtValue, float tgtDuration)
  14. : base(tgtDuration)
  15. {
  16. value = tgtValue;
  17. }
  18. /// <summary>
  19. /// Returns a copy of the action.
  20. /// </summary>
  21. public override ActionInstant clone()
  22. {
  23. return new ActionFadeTo(value, duration);
  24. }
  25. /// <summary>
  26. /// This method is called at the action start.
  27. /// </summary>
  28. public override void start()
  29. {
  30. base.start();
  31. delta = value - renderer.material.color.a;
  32. }
  33. /// <summary>
  34. /// This method is called every frame update.
  35. /// </summary>
  36. public override void stepInterval(float dt)
  37. {
  38. float d = dt / duration;
  39. Color tgtColor = renderer.material.color;
  40. tgtColor[3] += delta * d;
  41. renderer.material.color = tgtColor;
  42. }
  43. }
  44. }