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.

66 lines
1.5KB

  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace coa4u
  5. {
  6. class ActionIf : ActionInterval
  7. {
  8. protected ActionInstant action;
  9. protected Predicate predicate;
  10. protected bool started;
  11. public ActionIf(Predicate targetPredicate, ActionInstant targetAction)
  12. : base(0)
  13. {
  14. action = targetAction;
  15. predicate = targetPredicate;
  16. }
  17. public override ActionInstant Clone()
  18. {
  19. return new ActionIf(predicate, action);
  20. }
  21. public override ActionInstant Reverse()
  22. {
  23. return new ActionIf(predicate, action.Reverse());
  24. }
  25. public override void Start()
  26. {
  27. base.Start();
  28. if (predicate.check())
  29. {
  30. started = true;
  31. action.SetActor(target);
  32. action.Start();
  33. duration = action.duration;
  34. }
  35. else
  36. {
  37. running = false;
  38. }
  39. }
  40. public override void StepTimer(float dt)
  41. {
  42. if (!started)
  43. return;
  44. dt *= timeScale;
  45. if (action.running)
  46. action.StepTimer(dt);
  47. if (!action.running)
  48. {
  49. Stop();
  50. dtr = action.dtr;
  51. }
  52. }
  53. public override void Stop()
  54. {
  55. base.Stop();
  56. action.Stop();
  57. }
  58. }
  59. }