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.

ActionParallel.cs 1.8KB

10 jaren geleden
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. class ActionParallel : ActionInterval
  5. {
  6. protected Action[] actions;
  7. public ActionParallel(Action action1, Action action2)
  8. : base(0)
  9. {
  10. actions = new Action[] {action1, action2};
  11. }
  12. public ActionParallel(Action[] actionsList)
  13. : base(0)
  14. {
  15. actions = actionsList;
  16. }
  17. public override Action clone()
  18. {
  19. Action[] aList = new Action[actions.Length];
  20. for (int i = 0; i < actions.Length; i++)
  21. {
  22. aList[i] = actions[i].clone();
  23. }
  24. return new ActionSequence(aList);
  25. }
  26. public override Action reverse()
  27. {
  28. Action[] aList = new Action[actions.Length];
  29. for (int i = 0; i < actions.Length; i++)
  30. {
  31. aList[i] = actions[i].reverse();
  32. }
  33. return new ActionSequence(aList);
  34. }
  35. public override void start()
  36. {
  37. base.start();
  38. for (int i = 0; i < actions.Length; i++)
  39. {
  40. actions[i].setActor(target);
  41. actions[i].start();
  42. }
  43. }
  44. public override void step(float dt)
  45. {
  46. dt *= timeScale;
  47. for (int i = 0; i < actions.Length; i++)
  48. {
  49. if (actions[i].isRunning())
  50. actions[i].step(dt);
  51. }
  52. bool canStopNow = true;
  53. float dtrdata = 0;
  54. for (int i = 0; i < actions.Length; i++)
  55. {
  56. if (actions[i].isRunning())
  57. {
  58. canStopNow = false;
  59. dtrdata = Math.Max(actions[i].dtr, dtrdata);
  60. }
  61. }
  62. if (canStopNow)
  63. {
  64. stop();
  65. dtr = dtrdata;
  66. }
  67. }
  68. public override void stop()
  69. {
  70. base.stop();
  71. for (int i = 0; i < actions.Length; i++)
  72. {
  73. actions[i].stop();
  74. }
  75. }
  76. }